本文整理汇总了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;未经允许,请勿转载。 |
请发表评论