當前位置: 首頁>>代碼示例>>Golang>>正文


Golang api.ScalewayServerPatchDefinition類代碼示例

本文整理匯總了Golang中github.com/scaleway/scaleway-cli/pkg/api.ScalewayServerPatchDefinition的典型用法代碼示例。如果您正苦於以下問題:Golang ScalewayServerPatchDefinition類的具體用法?Golang ScalewayServerPatchDefinition怎麽用?Golang ScalewayServerPatchDefinition使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ScalewayServerPatchDefinition類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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("dynamic_ip_required") {
		req.DynamicIPRequired = Bool(d.Get("dynamic_ip_required").(bool))
	}

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

	return resourceScalewayServerRead(d, m)
}
開發者ID:yonatanp,項目名稱:terraform,代碼行數:30,代碼來源:resource_scaleway_server.go

示例2: RunRename

// RunRename is the handler for 'scw rename'
func RunRename(ctx CommandContext, args RenameArgs) error {
	serverID, err := ctx.API.GetServerID(args.Server)
	if err != nil {
		return err
	}
	var server api.ScalewayServerPatchDefinition

	server.Name = &args.NewName
	if err = ctx.API.PatchServer(serverID, server); err != nil {
		return fmt.Errorf("cannot rename server: %v", err)
	}
	// FIXME region, arch, owner, title
	ctx.API.Cache.InsertServer(serverID, "fr-1", *server.Arch, *server.Organization, *server.Name)
	return nil
}
開發者ID:awesome-docker,項目名稱:scaleway-cli,代碼行數:16,代碼來源:rename.go

示例3: RunRename

// RunRename is the handler for 'scw rename'
func RunRename(ctx CommandContext, args RenameArgs) error {
	serverID := ctx.API.GetServerID(args.Server)

	var server api.ScalewayServerPatchDefinition
	server.Name = &args.NewName

	err := ctx.API.PatchServer(serverID, server)
	if err != nil {
		return fmt.Errorf("cannot rename server: %v", err)
	}

	ctx.API.Cache.InsertServer(serverID, *server.Name)

	return nil
}
開發者ID:ebfe,項目名稱:scaleway-cli,代碼行數:16,代碼來源:rename.go

示例4: resourceServerUpdate

func resourceServerUpdate(d *schema.ResourceData, m interface{}) error {
	scaleway := m.(*api.ScalewayAPI)

	var server api.ScalewayServerPatchDefinition

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

	if d.HasChange("volumes") {
		volumes := make(map[string]api.ScalewayVolume)
		for k, v := range d.Get("volumes").(map[string]interface{}) {
			volumes[k] = api.ScalewayVolume{
				Identifier: v.(string),
			}
		}
		server.Volumes = &volumes
	}

	scaleway.PatchServer(d.Id(), server)

	return nil
}
開發者ID:hex-sh,項目名稱:terraform-provider-scaleway,代碼行數:24,代碼來源:resource_server.go

示例5: 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 := updateParts[1]

	changes := 0

	ident := api.GetIdentifier(cmd.API, args[0])
	switch ident.Type {
	case api.IdentifierServer:
		currentServer, err := cmd.API.GetServer(ident.Identifier)
		if err != nil {
			log.Fatalf("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.Identifier = 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
		default:
			log.Fatalf("'_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 {
			log.Fatalf("Cannot update server: %v", err)
		}
	default:
		log.Fatalf("_patch not implemented for this kind of object")
	}
	fmt.Println(ident.Identifier)

	return nil
}
開發者ID:arianvp,項目名稱:scaleway-cli,代碼行數:81,代碼來源:x_patch.go


注:本文中的github.com/scaleway/scaleway-cli/pkg/api.ScalewayServerPatchDefinition類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。