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


Golang godo.DropletCreateSSHKey類代碼示例

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


在下文中一共展示了DropletCreateSSHKey類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Create

func (p *digitalOceanProvider) Create(host providers.Host) error {
	var sshKey godo.DropletCreateSSHKey
	if strings.Contains(host.Keyname, ":") {
		sshKey.Fingerprint = host.Keyname
	} else {
		id, err := strconv.Atoi(host.Keyname)
		if err != nil {
			return err
		}
		sshKey.ID = id
	}
	droplet, _, err := p.client.Droplets.Create(&godo.DropletCreateRequest{
		Name:   host.Name,
		Region: host.Region,
		Size:   host.Flavor,
		Image: godo.DropletCreateImage{
			Slug: host.Image,
		},
		SSHKeys:  []godo.DropletCreateSSHKey{sshKey},
		UserData: host.Userdata,
	})
	if err != nil {
		return err
	}
	for {
		droplet, _, err = p.client.Droplets.Get(droplet.ID)
		if droplet != nil && droplet.Status == "active" {
			return nil
		}
		if err != nil {
			return err
		}
		time.Sleep(1 * time.Second)
	}
}
開發者ID:TheNathanBlack,項目名稱:hostctl,代碼行數:35,代碼來源:provider.go

示例2: resourceDigitalOceanDropletCreate

func resourceDigitalOceanDropletCreate(d *schema.ResourceData, meta interface{}) error {
	client := meta.(*godo.Client)

	// Build up our creation options
	opts := &godo.DropletCreateRequest{
		Image: godo.DropletCreateImage{
			Slug: d.Get("image").(string),
		},
		Name:   d.Get("name").(string),
		Region: d.Get("region").(string),
		Size:   d.Get("size").(string),
	}

	if attr, ok := d.GetOk("backups"); ok {
		opts.Backups = attr.(bool)
	}

	if attr, ok := d.GetOk("ipv6"); ok {
		opts.IPv6 = attr.(bool)
	}

	if attr, ok := d.GetOk("private_networking"); ok {
		opts.PrivateNetworking = attr.(bool)
	}

	if attr, ok := d.GetOk("user_data"); ok {
		opts.UserData = attr.(string)
	}

	// Get configured ssh_keys
	sshKeys := d.Get("ssh_keys.#").(int)
	if sshKeys > 0 {
		opts.SSHKeys = make([]godo.DropletCreateSSHKey, 0, sshKeys)
		for i := 0; i < sshKeys; i++ {
			key := fmt.Sprintf("ssh_keys.%d", i)
			sshKeyRef := d.Get(key).(string)

			var sshKey godo.DropletCreateSSHKey
			// sshKeyRef can be either an ID or a fingerprint
			if id, err := strconv.Atoi(sshKeyRef); err == nil {
				sshKey.ID = id
			} else {
				sshKey.Fingerprint = sshKeyRef
			}

			opts.SSHKeys = append(opts.SSHKeys, sshKey)
		}
	}

	log.Printf("[DEBUG] Droplet create configuration: %#v", opts)

	droplet, _, err := client.Droplets.Create(opts)

	if err != nil {
		return fmt.Errorf("Error creating droplet: %s", err)
	}

	// Assign the droplets id
	d.SetId(strconv.Itoa(droplet.ID))

	log.Printf("[INFO] Droplet ID: %s", d.Id())

	_, err = WaitForDropletAttribute(d, "active", []string{"new"}, "status", meta)
	if err != nil {
		return fmt.Errorf(
			"Error waiting for droplet (%s) to become ready: %s", d.Id(), err)
	}

	return resourceDigitalOceanDropletRead(d, meta)
}
開發者ID:AssertSelenium,項目名稱:terraform,代碼行數:70,代碼來源:resource_digitalocean_droplet.go


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