当前位置: 首页>>代码示例>>Golang>>正文


Golang ScalewayServerPatchDefinition.EnableIPV6方法代码示例

本文整理汇总了Golang中github.com/scaleway/scaleway-cli/pkg/api.ScalewayServerPatchDefinition.EnableIPV6方法的典型用法代码示例。如果您正苦于以下问题:Golang ScalewayServerPatchDefinition.EnableIPV6方法的具体用法?Golang ScalewayServerPatchDefinition.EnableIPV6怎么用?Golang ScalewayServerPatchDefinition.EnableIPV6使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/scaleway/scaleway-cli/pkg/api.ScalewayServerPatchDefinition的用法示例。


在下文中一共展示了ScalewayServerPatchDefinition.EnableIPV6方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: resourceScalewayServerUpdate

func resourceScalewayServerUpdate(d *schema.ResourceData, m interface{}) error {
	scaleway := m.(*Client).scaleway

	var req api.ScalewayServerPatchDefinition

	if d.HasChange("name") {
		name := d.Get("name").(string)
		req.Name = &name
	}

	if d.HasChange("tags") {
		if raw, ok := d.GetOk("tags"); ok {
			var tags []string
			for _, tag := range raw.([]interface{}) {
				tags = append(tags, tag.(string))
			}
			req.Tags = &tags
		}
	}

	if d.HasChange("enable_ipv6") {
		req.EnableIPV6 = Bool(d.Get("enable_ipv6").(bool))
	}

	if d.HasChange("dynamic_ip_required") {
		req.DynamicIPRequired = Bool(d.Get("dynamic_ip_required").(bool))
	}

	if d.HasChange("security_group") {
		req.SecurityGroup = &api.ScalewaySecurityGroup{
			Identifier: d.Get("security_group").(string),
		}
	}

	if err := scaleway.PatchServer(d.Id(), req); err != nil {
		return fmt.Errorf("Failed patching scaleway server: %q", err)
	}

	return resourceScalewayServerRead(d, m)
}
开发者ID:Originate,项目名称:terraform,代码行数:40,代码来源:resource_scaleway_server.go

示例2: runPatch

func runPatch(cmd *Command, args []string) error {
	if patchHelp {
		return cmd.PrintUsage()
	}
	if len(args) != 2 {
		return cmd.PrintShortUsage()
	}

	// Parsing FIELD=VALUE
	updateParts := strings.SplitN(args[1], "=", 2)
	if len(updateParts) != 2 {
		return cmd.PrintShortUsage()
	}
	fieldName := updateParts[0]
	newValue := args[1][len(updateParts[0])+1:]

	changes := 0

	ident, err := api.GetIdentifier(cmd.API, args[0])
	if err != nil {
		return err
	}
	switch ident.Type {
	case api.IdentifierServer:
		currentServer, err := cmd.API.GetServer(ident.Identifier)
		if err != nil {
			return fmt.Errorf("Cannot get server %s: %v", ident.Identifier, err)
		}

		var payload api.ScalewayServerPatchDefinition

		switch fieldName {
		case "state_detail":
			log.Debugf("%s=%s  =>  %s=%s", fieldName, currentServer.StateDetail, fieldName, newValue)
			if currentServer.StateDetail != newValue {
				changes++
				payload.StateDetail = &newValue
			}
		case "name":
			log.Warnf("To rename a server, Use 'scw rename'")
			log.Debugf("%s=%s  =>  %s=%s", fieldName, currentServer.StateDetail, fieldName, newValue)
			if currentServer.Name != newValue {
				changes++
				payload.Name = &newValue
			}
		case "bootscript":
			log.Debugf("%s=%s  =>  %s=%s", fieldName, currentServer.Bootscript.Identifier, fieldName, newValue)
			if currentServer.Bootscript.Identifier != newValue {
				changes++
				payload.Bootscript = &newValue
			}
		case "security_group":
			log.Debugf("%s=%s  =>  %s=%s", fieldName, currentServer.SecurityGroup.Identifier, fieldName, newValue)
			if currentServer.SecurityGroup.Identifier != newValue {
				changes++
				payload.SecurityGroup.Identifier = newValue
			}
		case "tags":
			newTags := strings.Split(newValue, " ")
			log.Debugf("%s=%s  =>  %s=%s", fieldName, currentServer.Tags, fieldName, newTags)
			// fixme test equality with reflect.DeepEqual ?
			changes++
			payload.Tags = &newTags
		case "ipv6":
			log.Debugf("%s=%s  =>  %s=%s", fieldName, currentServer.Tags, fieldName, newValue)
			switch strings.ToLower(newValue) {
			case "true":
				t := true
				payload.EnableIPV6 = &t
				changes++
			case "false":
				f := false
				payload.EnableIPV6 = &f
				changes++
			}
		default:
			return fmt.Errorf("'_patch server %s=' not implemented", fieldName)
		}
		// FIXME: volumes, tags, dynamic_ip_required

		if changes > 0 {
			log.Debugf("updating server: %d change(s)", changes)
			err = cmd.API.PatchServer(ident.Identifier, payload)
		} else {
			log.Debugf("no changes, not updating server")
		}
		if err != nil {
			return fmt.Errorf("Cannot update server: %v", err)
		}
	default:
		return fmt.Errorf("_patch not implemented for this kind of object")
	}
	fmt.Println(ident.Identifier)
	return nil
}
开发者ID:QuentinPerez,项目名称:scaleway-cli,代码行数:95,代码来源:x_patch.go


注:本文中的github.com/scaleway/scaleway-cli/pkg/api.ScalewayServerPatchDefinition.EnableIPV6方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。