本文整理汇总了Golang中github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/routers.UpdateOpts类的典型用法代码示例。如果您正苦于以下问题:Golang UpdateOpts类的具体用法?Golang UpdateOpts怎么用?Golang UpdateOpts使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UpdateOpts类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: resourceNetworkingRouterV2Update
func resourceNetworkingRouterV2Update(d *schema.ResourceData, meta interface{}) error {
routerId := d.Id()
osMutexKV.Lock(routerId)
defer osMutexKV.Unlock(routerId)
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
var updateOpts routers.UpdateOpts
if d.HasChange("name") {
updateOpts.Name = d.Get("name").(string)
}
if d.HasChange("admin_state_up") {
asu := d.Get("admin_state_up").(bool)
updateOpts.AdminStateUp = &asu
}
log.Printf("[DEBUG] Updating Router %s with options: %+v", d.Id(), updateOpts)
_, err = routers.Update(networkingClient, d.Id(), updateOpts).Extract()
if err != nil {
return fmt.Errorf("Error updating OpenStack Neutron Router: %s", err)
}
return resourceNetworkingRouterV2Read(d, meta)
}
开发者ID:Zordrak,项目名称:terraform,代码行数:29,代码来源:resource_openstack_networking_router_v2.go
示例2: resourceNetworkingRouterV2Update
func resourceNetworkingRouterV2Update(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)
}
var updateOpts routers.UpdateOpts
if d.HasChange("name") {
updateOpts.Name = d.Get("name").(string)
}
if d.HasChange("admin_state_up") {
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'")
}
updateOpts.AdminStateUp = &asu
}
}
log.Printf("[DEBUG] Updating Router %s with options: %+v", d.Id(), updateOpts)
_, err = routers.Update(networkingClient, d.Id(), updateOpts).Extract()
if err != nil {
return fmt.Errorf("Error updating OpenStack Neutron Router: %s", err)
}
return resourceNetworkingRouterV2Read(d, meta)
}
开发者ID:NextGenIntelligence,项目名称:terraform,代码行数:31,代码来源:resource_openstack_networking_router_v2.go
示例3: resourceNetworkingRouterRouteV2Delete
func resourceNetworkingRouterRouteV2Delete(d *schema.ResourceData, meta interface{}) error {
routerId := d.Get("router_id").(string)
osMutexKV.Lock(routerId)
defer osMutexKV.Unlock(routerId)
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
n, err := routers.Get(networkingClient, routerId).Extract()
if err != nil {
httpError, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return fmt.Errorf("Error retrieving OpenStack Neutron Router: %s", err)
}
if httpError.Actual == 404 {
return nil
}
return fmt.Errorf("Error retrieving OpenStack Neutron Router: %s", err)
}
var updateOpts routers.UpdateOpts
var destCidr string = d.Get("destination_cidr").(string)
var nextHop string = d.Get("next_hop").(string)
var oldRts []routers.Route = n.Routes
var newRts []routers.Route
for _, r := range oldRts {
if r.DestinationCIDR != destCidr || r.NextHop != nextHop {
newRts = append(newRts, r)
}
}
if len(oldRts) != len(newRts) {
r := routers.Route{DestinationCIDR: destCidr, NextHop: nextHop}
log.Printf(
"[INFO] Deleting route %s", r)
updateOpts.Routes = newRts
log.Printf("[DEBUG] Updating Router %s with options: %+v", routerId, updateOpts)
_, err = routers.Update(networkingClient, routerId, updateOpts).Extract()
if err != nil {
return fmt.Errorf("Error updating OpenStack Neutron Router: %s", err)
}
} else {
return fmt.Errorf("Route did not exist already")
}
return nil
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:59,代码来源:resource_openstack_networking_router_route_v2.go
示例4: resourceNetworkingRouterRouteV2Create
func resourceNetworkingRouterRouteV2Create(d *schema.ResourceData, meta interface{}) error {
routerId := d.Get("router_id").(string)
osMutexKV.Lock(routerId)
defer osMutexKV.Unlock(routerId)
var destCidr string = d.Get("destination_cidr").(string)
var nextHop string = d.Get("next_hop").(string)
config := meta.(*Config)
networkingClient, err := config.networkingV2Client(d.Get("region").(string))
if err != nil {
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}
n, err := routers.Get(networkingClient, routerId).Extract()
if err != nil {
httpError, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return fmt.Errorf("Error retrieving OpenStack Neutron Router: %s", err)
}
if httpError.Actual == 404 {
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving OpenStack Neutron Router: %s", err)
}
var updateOpts routers.UpdateOpts
var routeExists bool = false
var rts []routers.Route = n.Routes
for _, r := range rts {
if r.DestinationCIDR == destCidr && r.NextHop == nextHop {
routeExists = true
break
}
}
if !routeExists {
if destCidr != "" && nextHop != "" {
r := routers.Route{DestinationCIDR: destCidr, NextHop: nextHop}
log.Printf(
"[INFO] Adding route %s", r)
rts = append(rts, r)
}
updateOpts.Routes = rts
log.Printf("[DEBUG] Updating Router %s with options: %+v", routerId, updateOpts)
_, err = routers.Update(networkingClient, routerId, updateOpts).Extract()
if err != nil {
return fmt.Errorf("Error updating OpenStack Neutron Router: %s", err)
}
d.SetId(fmt.Sprintf("%s-route-%s-%s", routerId, destCidr, nextHop))
} else {
log.Printf("[DEBUG] Router %s has route already", routerId)
}
return resourceNetworkingRouterRouteV2Read(d, meta)
}
开发者ID:RezaDKhan,项目名称:terraform,代码行数:66,代码来源:resource_openstack_networking_router_route_v2.go
注:本文中的github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/routers.UpdateOpts类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论