Fixes on OpenStack and Rackspace drivers

* Use the initialized client
* Fix the endpointType conditional
* Don't die if OS-EXT-IPS is not present
* Only log Openstack creation for Openstack drivers
* There's no option for MachineName, yet

Signed-off-by: Ash Wilson <ash.wilson@rackspace.com>
This commit is contained in:
Ash Wilson 2014-12-11 14:34:30 -05:00 committed by Guillaume Giamarchi
parent 7c839273c1
commit 816cc3c491
3 changed files with 20 additions and 13 deletions

View File

@ -131,12 +131,20 @@ func (c *GenericClient) GetInstanceIpAddresses(d *Driver) ([]IpAddress, error) {
for network, networkAddresses := range server.Addresses {
for _, element := range networkAddresses.([]interface{}) {
address := element.(map[string]interface{})
addresses = append(addresses, IpAddress{
Network: network,
AddressType: address["OS-EXT-IPS:type"].(string),
Address: address["addr"].(string),
Mac: address["OS-EXT-IPS-MAC:mac_addr"].(string),
})
addr := IpAddress{
Network: network,
Address: address["addr"].(string),
}
if tp, ok := address["OS-EXT-IPS:type"]; ok {
addr.AddressType = tp.(string)
}
if mac, ok := address["OS-EXT-IPS-MAC:mac_addr"]; ok {
addr.Mac = mac.(string)
}
addresses = append(addresses, addr)
}
}
return addresses, nil

View File

@ -159,13 +159,14 @@ func RegisterCreateFlags(cmd *flag.FlagSet) interface{} {
}
func NewDriver(storePath string) (drivers.Driver, error) {
log.WithFields(log.Fields{
"storePath": storePath,
}).Debug("Instantiating OpenStack driver...")
return NewDerivedDriver(storePath, &GenericClient{})
}
func NewDerivedDriver(storePath string, client Client) (*Driver, error) {
log.WithFields(log.Fields{
"storePath": storePath,
}).Debug("Instantiating OpenStack driver...")
return &Driver{
storePath: storePath,
client: client,
@ -430,8 +431,7 @@ func (d *Driver) checkConfig() error {
if d.NetworkName != "" && d.NetworkId != "" {
return fmt.Errorf(errorExclusiveOptions, "Network name", "Network id")
}
if d.EndpointType != "" && (d.EndpointType != "publicURL" || d.EndpointType != "adminURL" || d.EndpointType != "internalURL") {
if d.EndpointType != "" && (d.EndpointType != "publicURL" && d.EndpointType != "adminURL" && d.EndpointType != "internalURL") {
return fmt.Errorf(errorWrongEndpointType)
}
return nil

View File

@ -95,7 +95,7 @@ func NewDriver(storePath string) (drivers.Driver, error) {
}).Info("Instantiating Rackspace driver.")
client := &Client{}
inner, err := openstack.NewDerivedDriver(storePath, &Client{})
inner, err := openstack.NewDerivedDriver(storePath, client)
if err != nil {
return nil, err
}
@ -117,7 +117,6 @@ func (d *Driver) SetConfigFromFlags(flagsInterface interface{}) error {
d.Username = *flags.Username
d.APIKey = *flags.APIKey
d.Region = *flags.Region
d.MachineName = *flags.MachineName
d.EndpointType = *flags.EndpointType
d.ImageId = *flags.ImageID
d.FlavorId = *flags.FlavorID