本文整理汇总了Golang中github.com/rackspace/gophercloud/openstack/networking/v2/networks.CreateOpts.AdminStateUp方法的典型用法代码示例。如果您正苦于以下问题:Golang CreateOpts.AdminStateUp方法的具体用法?Golang CreateOpts.AdminStateUp怎么用?Golang CreateOpts.AdminStateUp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/rackspace/gophercloud/openstack/networking/v2/networks.CreateOpts
的用法示例。
在下文中一共展示了CreateOpts.AdminStateUp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: resourceNetworkingNetworkV2Create
func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
createOpts := networks.CreateOpts{
Name: d.Get("name").(string),
TenantID: d.Get("tenant_id").(string),
}
asuRaw := d.Get("admin_state_up").(string)
if asuRaw != "" {
asu, err := strconv.ParseBool(asuRaw)
if err != nil {
return fmt.Errorf("admin_state_up, if provided, must be either 'true' or 'false'")
}
createOpts.AdminStateUp = &asu
}
sharedRaw := d.Get("shared").(string)
if sharedRaw != "" {
shared, err := strconv.ParseBool(sharedRaw)
if err != nil {
return fmt.Errorf("shared, if provided, must be either 'true' or 'false': %v", err)
}
createOpts.Shared = &shared
}
log.Printf("[DEBUG] Create Options: %#v", createOpts)
n, err := networks.Create(networkingClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack Neutron network: %s", err)
}
log.Printf("[INFO] Network ID: %s", n.ID)
log.Printf("[DEBUG] Waiting for Network (%s) to become available", n.ID)
stateConf := &resource.StateChangeConf{
Pending: []string{"BUILD"},
Target: "ACTIVE",
Refresh: waitForNetworkActive(networkingClient, n.ID),
Timeout: 2 * time.Minute,
Delay: 5 * time.Second,
MinTimeout: 3 * time.Second,
}
_, err = stateConf.WaitForState()
d.SetId(n.ID)
return resourceNetworkingNetworkV2Read(d, meta)
}
示例2: resourceNetworkingNetworkV2Create
func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
createOpts := networks.CreateOpts{
Name: d.Get("name").(string),
TenantID: d.Get("tenant_id").(string),
}
asuRaw := d.Get("admin_state_up").(string)
if asuRaw != "" {
asu, err := strconv.ParseBool(asuRaw)
if err != nil {
return fmt.Errorf("admin_state_up, if provided, must be either 'true' or 'false'")
}
createOpts.AdminStateUp = &asu
}
sharedRaw := d.Get("shared").(string)
if sharedRaw != "" {
shared, err := strconv.ParseBool(sharedRaw)
if err != nil {
return fmt.Errorf("shared, if provided, must be either 'true' or 'false': %v", err)
}
createOpts.Shared = &shared
}
log.Printf("[DEBUG] Create Options: %#v", createOpts)
n, err := networks.Create(networkingClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack Neutron network: %s", err)
}
log.Printf("[INFO] Network ID: %s", n.ID)
d.SetId(n.ID)
return resourceNetworkingNetworkV2Read(d, meta)
}