Another pass at linting
Signed-off-by: Olivier Gambier <olivier@docker.com>
This commit is contained in:
parent
ace17ece2f
commit
b153a9c218
|
@ -35,16 +35,16 @@ type Client interface {
|
|||
RestartInstance(d *Driver) error
|
||||
DeleteInstance(d *Driver) error
|
||||
WaitForInstanceStatus(d *Driver, status string) error
|
||||
GetInstanceIpAddresses(d *Driver) ([]IpAddress, error)
|
||||
GetInstanceIPAddresses(d *Driver) ([]IPAddress, error)
|
||||
CreateKeyPair(d *Driver, name string, publicKey string) error
|
||||
DeleteKeyPair(d *Driver, name string) error
|
||||
GetNetworkId(d *Driver) (string, error)
|
||||
GetFlavorId(d *Driver) (string, error)
|
||||
GetImageId(d *Driver) (string, error)
|
||||
AssignFloatingIP(d *Driver, floatingIp *FloatingIp) error
|
||||
GetFloatingIPs(d *Driver) ([]FloatingIp, error)
|
||||
GetFloatingIpPoolId(d *Driver) (string, error)
|
||||
GetInstancePortId(d *Driver) (string, error)
|
||||
GetNetworkID(d *Driver) (string, error)
|
||||
GetFlavorID(d *Driver) (string, error)
|
||||
GetImageID(d *Driver) (string, error)
|
||||
AssignFloatingIP(d *Driver, floatingIP *FloatingIP) error
|
||||
GetFloatingIPs(d *Driver) ([]FloatingIP, error)
|
||||
GetFloatingIPPoolID(d *Driver) (string, error)
|
||||
GetInstancePortID(d *Driver) (string, error)
|
||||
}
|
||||
|
||||
type GenericClient struct {
|
||||
|
@ -86,7 +86,7 @@ const (
|
|||
Fixed string = "fixed"
|
||||
)
|
||||
|
||||
type IpAddress struct {
|
||||
type IPAddress struct {
|
||||
Network string
|
||||
AddressType string
|
||||
Address string
|
||||
|
@ -94,7 +94,7 @@ type IpAddress struct {
|
|||
Mac string
|
||||
}
|
||||
|
||||
type FloatingIp struct {
|
||||
type FloatingIP struct {
|
||||
Id string
|
||||
Ip string
|
||||
NetworkId string
|
||||
|
@ -158,12 +158,12 @@ func (c *GenericClient) WaitForInstanceStatus(d *Driver, status string) error {
|
|||
}, (d.ActiveTimeout / 4), 4*time.Second)
|
||||
}
|
||||
|
||||
func (c *GenericClient) GetInstanceIpAddresses(d *Driver) ([]IpAddress, error) {
|
||||
func (c *GenericClient) GetInstanceIPAddresses(d *Driver) ([]IPAddress, error) {
|
||||
server, err := c.GetServerDetail(d)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
addresses := []IpAddress{}
|
||||
addresses := []IPAddress{}
|
||||
for network, networkAddresses := range server.Addresses {
|
||||
for _, element := range networkAddresses.([]interface{}) {
|
||||
address := element.(map[string]interface{})
|
||||
|
@ -173,7 +173,7 @@ func (c *GenericClient) GetInstanceIpAddresses(d *Driver) ([]IpAddress, error) {
|
|||
version = 4
|
||||
}
|
||||
|
||||
addr := IpAddress{
|
||||
addr := IPAddress{
|
||||
Network: network,
|
||||
AddressType: Fixed,
|
||||
Address: address["addr"].(string),
|
||||
|
@ -194,18 +194,18 @@ func (c *GenericClient) GetInstanceIpAddresses(d *Driver) ([]IpAddress, error) {
|
|||
return addresses, nil
|
||||
}
|
||||
|
||||
func (c *GenericClient) GetNetworkId(d *Driver) (string, error) {
|
||||
return c.getNetworkId(d, d.NetworkName)
|
||||
func (c *GenericClient) GetNetworkID(d *Driver) (string, error) {
|
||||
return c.getNetworkID(d, d.NetworkName)
|
||||
}
|
||||
|
||||
func (c *GenericClient) GetFloatingIpPoolId(d *Driver) (string, error) {
|
||||
return c.getNetworkId(d, d.FloatingIpPool)
|
||||
func (c *GenericClient) GetFloatingIPPoolID(d *Driver) (string, error) {
|
||||
return c.getNetworkID(d, d.FloatingIpPool)
|
||||
}
|
||||
|
||||
func (c *GenericClient) getNetworkId(d *Driver, networkName string) (string, error) {
|
||||
func (c *GenericClient) getNetworkID(d *Driver, networkName string) (string, error) {
|
||||
opts := networks.ListOpts{Name: networkName}
|
||||
pager := networks.List(c.Network, opts)
|
||||
networkId := ""
|
||||
networkID := ""
|
||||
|
||||
err := pager.EachPage(func(page pagination.Page) (bool, error) {
|
||||
networkList, err := networks.ExtractNetworks(page)
|
||||
|
@ -215,7 +215,7 @@ func (c *GenericClient) getNetworkId(d *Driver, networkName string) (string, err
|
|||
|
||||
for _, n := range networkList {
|
||||
if n.Name == networkName {
|
||||
networkId = n.ID
|
||||
networkID = n.ID
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
@ -223,12 +223,12 @@ func (c *GenericClient) getNetworkId(d *Driver, networkName string) (string, err
|
|||
return true, nil
|
||||
})
|
||||
|
||||
return networkId, err
|
||||
return networkID, err
|
||||
}
|
||||
|
||||
func (c *GenericClient) GetFlavorId(d *Driver) (string, error) {
|
||||
func (c *GenericClient) GetFlavorID(d *Driver) (string, error) {
|
||||
pager := flavors.ListDetail(c.Compute, nil)
|
||||
flavorId := ""
|
||||
flavorID := ""
|
||||
|
||||
err := pager.EachPage(func(page pagination.Page) (bool, error) {
|
||||
flavorList, err := flavors.ExtractFlavors(page)
|
||||
|
@ -238,7 +238,7 @@ func (c *GenericClient) GetFlavorId(d *Driver) (string, error) {
|
|||
|
||||
for _, f := range flavorList {
|
||||
if f.Name == d.FlavorName {
|
||||
flavorId = f.ID
|
||||
flavorID = f.ID
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
@ -246,13 +246,13 @@ func (c *GenericClient) GetFlavorId(d *Driver) (string, error) {
|
|||
return true, nil
|
||||
})
|
||||
|
||||
return flavorId, err
|
||||
return flavorID, err
|
||||
}
|
||||
|
||||
func (c *GenericClient) GetImageId(d *Driver) (string, error) {
|
||||
func (c *GenericClient) GetImageID(d *Driver) (string, error) {
|
||||
opts := images.ListOpts{Name: d.ImageName}
|
||||
pager := images.ListDetail(c.Compute, opts)
|
||||
imageId := ""
|
||||
imageID := ""
|
||||
|
||||
err := pager.EachPage(func(page pagination.Page) (bool, error) {
|
||||
imageList, err := images.ExtractImages(page)
|
||||
|
@ -262,7 +262,7 @@ func (c *GenericClient) GetImageId(d *Driver) (string, error) {
|
|||
|
||||
for _, i := range imageList {
|
||||
if i.Name == d.ImageName {
|
||||
imageId = i.ID
|
||||
imageID = i.ID
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ func (c *GenericClient) GetImageId(d *Driver) (string, error) {
|
|||
return true, nil
|
||||
})
|
||||
|
||||
return imageId, err
|
||||
return imageID, err
|
||||
}
|
||||
|
||||
func (c *GenericClient) CreateKeyPair(d *Driver, name string, publicKey string) error {
|
||||
|
@ -299,49 +299,48 @@ func (c *GenericClient) GetServerDetail(d *Driver) (*servers.Server, error) {
|
|||
return server, nil
|
||||
}
|
||||
|
||||
func (c *GenericClient) AssignFloatingIP(d *Driver, floatingIp *FloatingIp) error {
|
||||
func (c *GenericClient) AssignFloatingIP(d *Driver, floatingIP *FloatingIP) error {
|
||||
if d.ComputeNetwork {
|
||||
return c.assignNovaFloatingIP(d, floatingIp)
|
||||
} else {
|
||||
return c.assignNeutronFloatingIP(d, floatingIp)
|
||||
return c.assignNovaFloatingIP(d, floatingIP)
|
||||
}
|
||||
return c.assignNeutronFloatingIP(d, floatingIP)
|
||||
}
|
||||
|
||||
func (c *GenericClient) assignNovaFloatingIP(d *Driver, floatingIp *FloatingIp) error {
|
||||
if floatingIp.Ip == "" {
|
||||
func (c *GenericClient) assignNovaFloatingIP(d *Driver, floatingIP *FloatingIP) error {
|
||||
if floatingIP.Ip == "" {
|
||||
f, err := compute_ips.Create(c.Compute, compute_ips.CreateOpts{
|
||||
Pool: d.FloatingIpPool,
|
||||
}).Extract()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
floatingIp.Ip = f.IP
|
||||
floatingIp.Pool = f.Pool
|
||||
floatingIP.Ip = f.IP
|
||||
floatingIP.Pool = f.Pool
|
||||
}
|
||||
return compute_ips.Associate(c.Compute, d.MachineId, floatingIp.Ip).Err
|
||||
return compute_ips.Associate(c.Compute, d.MachineId, floatingIP.Ip).Err
|
||||
}
|
||||
|
||||
func (c *GenericClient) assignNeutronFloatingIP(d *Driver, floatingIp *FloatingIp) error {
|
||||
portId, err := c.GetInstancePortId(d)
|
||||
func (c *GenericClient) assignNeutronFloatingIP(d *Driver, floatingIP *FloatingIP) error {
|
||||
portID, err := c.GetInstancePortID(d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if floatingIp.Id == "" {
|
||||
if floatingIP.Id == "" {
|
||||
f, err := floatingips.Create(c.Network, floatingips.CreateOpts{
|
||||
FloatingNetworkID: d.FloatingIpPoolId,
|
||||
PortID: portId,
|
||||
PortID: portID,
|
||||
}).Extract()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
floatingIp.Id = f.ID
|
||||
floatingIp.Ip = f.FloatingIP
|
||||
floatingIp.NetworkId = f.FloatingNetworkID
|
||||
floatingIp.PortId = f.PortID
|
||||
floatingIP.Id = f.ID
|
||||
floatingIP.Ip = f.FloatingIP
|
||||
floatingIP.NetworkId = f.FloatingNetworkID
|
||||
floatingIP.PortId = f.PortID
|
||||
return nil
|
||||
}
|
||||
_, err = floatingips.Update(c.Network, floatingIp.Id, floatingips.UpdateOpts{
|
||||
PortID: portId,
|
||||
_, err = floatingips.Update(c.Network, floatingIP.Id, floatingips.UpdateOpts{
|
||||
PortID: portID,
|
||||
}).Extract()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -349,25 +348,24 @@ func (c *GenericClient) assignNeutronFloatingIP(d *Driver, floatingIp *FloatingI
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *GenericClient) GetFloatingIPs(d *Driver) ([]FloatingIp, error) {
|
||||
func (c *GenericClient) GetFloatingIPs(d *Driver) ([]FloatingIP, error) {
|
||||
if d.ComputeNetwork {
|
||||
return c.getNovaNetworkFloatingIPs(d)
|
||||
} else {
|
||||
return c.getNeutronNetworkFloatingIPs(d)
|
||||
}
|
||||
return c.getNeutronNetworkFloatingIPs(d)
|
||||
}
|
||||
|
||||
func (c *GenericClient) getNovaNetworkFloatingIPs(d *Driver) ([]FloatingIp, error) {
|
||||
func (c *GenericClient) getNovaNetworkFloatingIPs(d *Driver) ([]FloatingIP, error) {
|
||||
pager := compute_ips.List(c.Compute)
|
||||
|
||||
ips := []FloatingIp{}
|
||||
ips := []FloatingIP{}
|
||||
err := pager.EachPage(func(page pagination.Page) (continue_paging bool, err error) {
|
||||
continue_paging, err = true, nil
|
||||
ip_listing, err := compute_ips.ExtractFloatingIPs(page)
|
||||
ipListing, err := compute_ips.ExtractFloatingIPs(page)
|
||||
|
||||
for _, ip := range ip_listing {
|
||||
for _, ip := range ipListing {
|
||||
if ip.InstanceID == "" && ip.Pool == d.FloatingIpPool {
|
||||
ips = append(ips, FloatingIp{
|
||||
ips = append(ips, FloatingIP{
|
||||
Id: ip.ID,
|
||||
Ip: ip.IP,
|
||||
Pool: ip.Pool,
|
||||
|
@ -379,19 +377,19 @@ func (c *GenericClient) getNovaNetworkFloatingIPs(d *Driver) ([]FloatingIp, erro
|
|||
return ips, err
|
||||
}
|
||||
|
||||
func (c *GenericClient) getNeutronNetworkFloatingIPs(d *Driver) ([]FloatingIp, error) {
|
||||
func (c *GenericClient) getNeutronNetworkFloatingIPs(d *Driver) ([]FloatingIP, error) {
|
||||
pager := floatingips.List(c.Network, floatingips.ListOpts{
|
||||
FloatingNetworkID: d.FloatingIpPoolId,
|
||||
})
|
||||
|
||||
ips := []FloatingIp{}
|
||||
ips := []FloatingIP{}
|
||||
err := pager.EachPage(func(page pagination.Page) (bool, error) {
|
||||
floatingipList, err := floatingips.ExtractFloatingIPs(page)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, f := range floatingipList {
|
||||
ips = append(ips, FloatingIp{
|
||||
ips = append(ips, FloatingIP{
|
||||
Id: f.ID,
|
||||
Ip: f.FloatingIP,
|
||||
NetworkId: f.FloatingNetworkID,
|
||||
|
@ -407,20 +405,20 @@ func (c *GenericClient) getNeutronNetworkFloatingIPs(d *Driver) ([]FloatingIp, e
|
|||
return ips, nil
|
||||
}
|
||||
|
||||
func (c *GenericClient) GetInstancePortId(d *Driver) (string, error) {
|
||||
func (c *GenericClient) GetInstancePortID(d *Driver) (string, error) {
|
||||
pager := ports.List(c.Network, ports.ListOpts{
|
||||
DeviceID: d.MachineId,
|
||||
NetworkID: d.NetworkId,
|
||||
})
|
||||
|
||||
var portId string
|
||||
var portID string
|
||||
err := pager.EachPage(func(page pagination.Page) (bool, error) {
|
||||
portList, err := ports.ExtractPorts(page)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, port := range portList {
|
||||
portId = port.ID
|
||||
portID = port.ID
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
|
@ -429,7 +427,7 @@ func (c *GenericClient) GetInstancePortId(d *Driver) (string, error) {
|
|||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return portId, nil
|
||||
return portID, nil
|
||||
}
|
||||
|
||||
func (c *GenericClient) InitComputeClient(d *Driver) error {
|
||||
|
|
|
@ -222,6 +222,7 @@ func (d *Driver) SetClient(client Client) {
|
|||
d.client = client
|
||||
}
|
||||
|
||||
// DriverName returns the name of the driver
|
||||
func (d *Driver) DriverName() string {
|
||||
return "openstack"
|
||||
}
|
||||
|
@ -289,7 +290,7 @@ func (d *Driver) GetIP() (string, error) {
|
|||
|
||||
// Looking for the IP address in a retry loop to deal with OpenStack latency
|
||||
for retryCount := 0; retryCount < 200; retryCount++ {
|
||||
addresses, err := d.client.GetInstanceIpAddresses(d)
|
||||
addresses, err := d.client.GetInstanceIPAddresses(d)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -352,11 +353,11 @@ func (d *Driver) Create() error {
|
|||
return err
|
||||
}
|
||||
if d.FloatingIpPool != "" {
|
||||
if err := d.assignFloatingIp(); err != nil {
|
||||
if err := d.assignFloatingIP(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := d.lookForIpAddress(); err != nil {
|
||||
if err := d.lookForIPAddress(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -420,7 +421,7 @@ const (
|
|||
errorMandatoryEnvOrOption string = "%s must be specified either using the environment variable %s or the CLI option %s"
|
||||
errorMandatoryOption string = "%s must be specified using the CLI option %s"
|
||||
errorExclusiveOptions string = "Either %s or %s must be specified, not both"
|
||||
errorMandatoryTenantNameOrId string = "Tenant id or name must be provided either using one of the environment variables OS_TENANT_ID and OS_TENANT_NAME or one of the CLI options --openstack-tenant-id and --openstack-tenant-name"
|
||||
errorMandatoryTenantNameOrID string = "Tenant id or name must be provided either using one of the environment variables OS_TENANT_ID and OS_TENANT_NAME or one of the CLI options --openstack-tenant-id and --openstack-tenant-name"
|
||||
errorWrongEndpointType string = "Endpoint type must be 'publicURL', 'adminURL' or 'internalURL'"
|
||||
errorUnknownFlavorName string = "Unable to find flavor named %s"
|
||||
errorUnknownImageName string = "Unable to find image named %s"
|
||||
|
@ -438,7 +439,7 @@ func (d *Driver) checkConfig() error {
|
|||
return fmt.Errorf(errorMandatoryEnvOrOption, "Password", "OS_PASSWORD", "--openstack-password")
|
||||
}
|
||||
if d.TenantName == "" && d.TenantId == "" {
|
||||
return fmt.Errorf(errorMandatoryTenantNameOrId)
|
||||
return fmt.Errorf(errorMandatoryTenantNameOrID)
|
||||
}
|
||||
|
||||
if d.FlavorName == "" && d.FlavorId == "" {
|
||||
|
@ -470,17 +471,17 @@ func (d *Driver) resolveIds() error {
|
|||
return err
|
||||
}
|
||||
|
||||
networkId, err := d.client.GetNetworkId(d)
|
||||
networkID, err := d.client.GetNetworkID(d)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if networkId == "" {
|
||||
if networkID == "" {
|
||||
return fmt.Errorf(errorUnknownNetworkName, d.NetworkName)
|
||||
}
|
||||
|
||||
d.NetworkId = networkId
|
||||
d.NetworkId = networkID
|
||||
log.WithFields(log.Fields{
|
||||
"Name": d.NetworkName,
|
||||
"ID": d.NetworkId,
|
||||
|
@ -491,17 +492,17 @@ func (d *Driver) resolveIds() error {
|
|||
if err := d.initCompute(); err != nil {
|
||||
return err
|
||||
}
|
||||
flavorId, err := d.client.GetFlavorId(d)
|
||||
flavorID, err := d.client.GetFlavorID(d)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if flavorId == "" {
|
||||
if flavorID == "" {
|
||||
return fmt.Errorf(errorUnknownFlavorName, d.FlavorName)
|
||||
}
|
||||
|
||||
d.FlavorId = flavorId
|
||||
d.FlavorId = flavorID
|
||||
log.WithFields(log.Fields{
|
||||
"Name": d.FlavorName,
|
||||
"ID": d.FlavorId,
|
||||
|
@ -512,17 +513,17 @@ func (d *Driver) resolveIds() error {
|
|||
if err := d.initCompute(); err != nil {
|
||||
return err
|
||||
}
|
||||
imageId, err := d.client.GetImageId(d)
|
||||
imageID, err := d.client.GetImageID(d)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if imageId == "" {
|
||||
if imageID == "" {
|
||||
return fmt.Errorf(errorUnknownImageName, d.ImageName)
|
||||
}
|
||||
|
||||
d.ImageId = imageId
|
||||
d.ImageId = imageID
|
||||
log.WithFields(log.Fields{
|
||||
"Name": d.ImageName,
|
||||
"ID": d.ImageId,
|
||||
|
@ -533,7 +534,7 @@ func (d *Driver) resolveIds() error {
|
|||
if err := d.initNetwork(); err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := d.client.GetFloatingIpPoolId(d)
|
||||
f, err := d.client.GetFloatingIPPoolID(d)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -601,15 +602,15 @@ func (d *Driver) createMachine() error {
|
|||
if err := d.initCompute(); err != nil {
|
||||
return err
|
||||
}
|
||||
instanceId, err := d.client.CreateInstance(d)
|
||||
instanceID, err := d.client.CreateInstance(d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
d.MachineId = instanceId
|
||||
d.MachineId = instanceID
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Driver) assignFloatingIp() error {
|
||||
func (d *Driver) assignFloatingIP() error {
|
||||
var err error
|
||||
|
||||
if d.ComputeNetwork {
|
||||
|
@ -627,7 +628,7 @@ func (d *Driver) assignFloatingIp() error {
|
|||
return err
|
||||
}
|
||||
|
||||
var floatingIp *FloatingIp
|
||||
var floatingIP *FloatingIP
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"MachineId": d.MachineId,
|
||||
|
@ -640,22 +641,22 @@ func (d *Driver) assignFloatingIp() error {
|
|||
"MachineId": d.MachineId,
|
||||
"IP": ip.Ip,
|
||||
}).Debugf("Available floating IP found")
|
||||
floatingIp = &ip
|
||||
floatingIP = &ip
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if floatingIp == nil {
|
||||
floatingIp = &FloatingIp{}
|
||||
if floatingIP == nil {
|
||||
floatingIP = &FloatingIP{}
|
||||
log.WithField("MachineId", d.MachineId).Debugf("No available floating IP found. Allocating a new one...")
|
||||
} else {
|
||||
log.WithField("MachineId", d.MachineId).Debugf("Assigning floating IP to the instance")
|
||||
}
|
||||
|
||||
if err := d.client.AssignFloatingIP(d, floatingIp); err != nil {
|
||||
if err := d.client.AssignFloatingIP(d, floatingIP); err != nil {
|
||||
return err
|
||||
}
|
||||
d.IPAddress = floatingIp.Ip
|
||||
d.IPAddress = floatingIP.Ip
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -667,7 +668,7 @@ func (d *Driver) waitForInstanceActive() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (d *Driver) lookForIpAddress() error {
|
||||
func (d *Driver) lookForIPAddress() error {
|
||||
ip, err := d.GetIP()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue