Workaround for missing tenant-network

This commit resolves an issue where the tenant-network api extension
does not exist. The caveat is that the user must either specify no
networks (single network environment) or can only specify UUIDs for
network configurations.
This commit is contained in:
Joe Topjian 2015-04-01 21:31:55 +00:00
parent 4244d0947e
commit ef4e03a729
1 changed files with 33 additions and 13 deletions

View File

@ -768,14 +768,27 @@ func resourceInstanceNetworks(computeClient *gophercloud.ServiceClient, d *schem
newNetworks := make([]map[string]interface{}, len(rawNetworks))
var tenantnet tenantnetworks.Network
tenantNetworkExt := true
for i, raw := range rawNetworks {
rawMap := raw.(map[string]interface{})
allPages, err := tenantnetworks.List(computeClient).AllPages()
if err != nil {
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return nil, err
}
if errCode.Actual == 404 {
tenantNetworkExt = false
} else {
return nil, err
}
}
networkID := ""
networkName := ""
if tenantNetworkExt {
networkList, err := tenantnetworks.ExtractNetworks(allPages)
if err != nil {
return nil, err
@ -790,9 +803,16 @@ func resourceInstanceNetworks(computeClient *gophercloud.ServiceClient, d *schem
}
}
networkID = tenantnet.ID
networkName = tenantnet.Name
} else {
networkID = rawMap["uuid"].(string)
networkName = rawMap["name"].(string)
}
newNetworks[i] = map[string]interface{}{
"uuid": tenantnet.ID,
"name": tenantnet.Name,
"uuid": networkID,
"name": networkName,
"port": rawMap["port"].(string),
"fixed_ip_v4": rawMap["fixed_ip_v4"].(string),
}