Merge pull request #2241 from dgageot/linting

Another pass at linting
This commit is contained in:
David Gageot 2015-11-10 17:43:58 +01:00
commit ae027c355d
34 changed files with 324 additions and 311 deletions

View File

@ -60,7 +60,7 @@ func (c *contextCommandLine) Application() *cli.App {
} }
func newPluginDriver(driverName string, rawContent []byte) (drivers.Driver, error) { func newPluginDriver(driverName string, rawContent []byte) (drivers.Driver, error) {
d, err := rpcdriver.NewRpcClientDriver(rawContent, driverName) d, err := rpcdriver.NewRPCClientDriver(rawContent, driverName)
if err != nil { if err != nil {
// Not being able to find a driver binary is a "known error" // Not being able to find a driver binary is a "known error"
if _, ok := err.(localbinary.ErrPluginBinaryNotFound); ok { if _, ok := err.(localbinary.ErrPluginBinaryNotFound); ok {

View File

@ -296,7 +296,7 @@ func cmdCreateOuter(c CommandLine) error {
} }
if _, ok := driver.(*errdriver.Driver); ok { if _, ok := driver.(*errdriver.Driver); ok {
return errdriver.ErrDriverNotLoadable{driverName} return errdriver.NotLoadable{driverName}
} }
// TODO: So much flag manipulation and voodoo here, it seems to be // TODO: So much flag manipulation and voodoo here, it seems to be
@ -324,7 +324,7 @@ func cmdCreateOuter(c CommandLine) error {
driver = serialDriver.Driver driver = serialDriver.Driver
} }
if rpcd, ok := driver.(*rpcdriver.RpcClientDriver); ok { if rpcd, ok := driver.(*rpcdriver.RPCClientDriver); ok {
if err := rpcd.Close(); err != nil { if err := rpcd.Close(); err != nil {
return err return err
} }
@ -340,7 +340,7 @@ func getDriverOpts(c CommandLine, mcnflags []mcnflag.Flag) drivers.DriverOptions
// But, we need it so that we can actually send the flags for creating // But, we need it so that we can actually send the flags for creating
// a machine over the wire (cli.Context is a no go since there is so // a machine over the wire (cli.Context is a no go since there is so
// much stuff in it). // much stuff in it).
driverOpts := rpcdriver.RpcFlags{ driverOpts := rpcdriver.RPCFlags{
Values: make(map[string]interface{}), Values: make(map[string]interface{}),
} }

View File

@ -267,6 +267,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
return nil return nil
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return driverName return driverName
} }

View File

@ -12,7 +12,7 @@ import (
) )
const ( const (
testSshPort = 22 testSSHPort = 22
testDockerPort = 2376 testDockerPort = 2376
testStoreDir = ".store-test" testStoreDir = ".store-test"
machineTestName = "test-host" machineTestName = "test-host"
@ -133,8 +133,8 @@ func TestConfigureSecurityGroupPermissionsSshOnly(t *testing.T) {
group.IpPermissions = []amz.IpPermission{ group.IpPermissions = []amz.IpPermission{
{ {
IpProtocol: "tcp", IpProtocol: "tcp",
FromPort: testSshPort, FromPort: testSSHPort,
ToPort: testSshPort, ToPort: testSSHPort,
}, },
} }
@ -172,8 +172,8 @@ func TestConfigureSecurityGroupPermissionsDockerOnly(t *testing.T) {
} }
receivedPort := perms[0].FromPort receivedPort := perms[0].FromPort
if receivedPort != testSshPort { if receivedPort != testSSHPort {
t.Fatalf("expected permission on port %d; received port %d", testSshPort, receivedPort) t.Fatalf("expected permission on port %d; received port %d", testSSHPort, receivedPort)
} }
} }
@ -189,8 +189,8 @@ func TestConfigureSecurityGroupPermissionsDockerAndSsh(t *testing.T) {
group.IpPermissions = []amz.IpPermission{ group.IpPermissions = []amz.IpPermission{
{ {
IpProtocol: "tcp", IpProtocol: "tcp",
FromPort: testSshPort, FromPort: testSSHPort,
ToPort: testSshPort, ToPort: testSSHPort,
}, },
{ {
IpProtocol: "tcp", IpProtocol: "tcp",

View File

@ -131,6 +131,7 @@ func (d *Driver) GetSSHUsername() string {
return d.SSHUser return d.SSHUser
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "azure" return "azure"
} }
@ -406,13 +407,13 @@ func (d *Driver) addDockerEndpoints(vmConfig *vmClient.Role) error {
LocalPort: d.DockerPort, LocalPort: d.DockerPort,
} }
if d.SwarmMaster { if d.SwarmMaster {
swarm_ep := vmClient.InputEndpoint{ swarmEp := vmClient.InputEndpoint{
Name: "docker swarm", Name: "docker swarm",
Protocol: "tcp", Protocol: "tcp",
Port: d.DockerSwarmMasterPort, Port: d.DockerSwarmMasterPort,
LocalPort: d.DockerSwarmMasterPort, LocalPort: d.DockerSwarmMasterPort,
} }
configSets[i].InputEndpoints.InputEndpoint = append(configSets[i].InputEndpoints.InputEndpoint, swarm_ep) configSets[i].InputEndpoints.InputEndpoint = append(configSets[i].InputEndpoints.InputEndpoint, swarmEp)
log.Debugf("added Docker swarm master endpoint (port %d) to configuration", d.DockerSwarmMasterPort) log.Debugf("added Docker swarm master endpoint (port %d) to configuration", d.DockerSwarmMasterPort)
} }
configSets[i].InputEndpoints.InputEndpoint = append(configSets[i].InputEndpoints.InputEndpoint, ep) configSets[i].InputEndpoints.InputEndpoint = append(configSets[i].InputEndpoints.InputEndpoint, ep)

View File

@ -101,6 +101,7 @@ func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP() return d.GetIP()
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "digitalocean" return "digitalocean"
} }

View File

@ -12,11 +12,11 @@ type Driver struct {
Name string Name string
} }
type ErrDriverNotLoadable struct { type NotLoadable struct {
Name string Name string
} }
func (e ErrDriverNotLoadable) Error() string { func (e NotLoadable) Error() string {
return fmt.Sprintf("Driver %q not found. Do you have the plugin binary accessible in your PATH?", e.Name) return fmt.Sprintf("Driver %q not found. Do you have the plugin binary accessible in your PATH?", e.Name)
} }
@ -26,6 +26,7 @@ func NewDriver(Name string) drivers.Driver {
} }
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "not-found" return "not-found"
} }
@ -39,11 +40,11 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
} }
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
return ErrDriverNotLoadable{d.Name} return NotLoadable{d.Name}
} }
func (d *Driver) GetURL() (string, error) { func (d *Driver) GetURL() (string, error) {
return "", ErrDriverNotLoadable{d.Name} return "", NotLoadable{d.Name}
} }
func (d *Driver) GetMachineName() string { func (d *Driver) GetMachineName() string {
@ -51,11 +52,11 @@ func (d *Driver) GetMachineName() string {
} }
func (d *Driver) GetIP() (string, error) { func (d *Driver) GetIP() (string, error) {
return "1.2.3.4", ErrDriverNotLoadable{d.Name} return "1.2.3.4", NotLoadable{d.Name}
} }
func (d *Driver) GetSSHHostname() (string, error) { func (d *Driver) GetSSHHostname() (string, error) {
return "", ErrDriverNotLoadable{d.Name} return "", NotLoadable{d.Name}
} }
func (d *Driver) GetSSHKeyPath() string { func (d *Driver) GetSSHKeyPath() string {
@ -63,7 +64,7 @@ func (d *Driver) GetSSHKeyPath() string {
} }
func (d *Driver) GetSSHPort() (int, error) { func (d *Driver) GetSSHPort() (int, error) {
return 0, ErrDriverNotLoadable{d.Name} return 0, NotLoadable{d.Name}
} }
func (d *Driver) GetSSHUsername() string { func (d *Driver) GetSSHUsername() string {
@ -71,33 +72,33 @@ func (d *Driver) GetSSHUsername() string {
} }
func (d *Driver) GetState() (state.State, error) { func (d *Driver) GetState() (state.State, error) {
return state.Error, ErrDriverNotLoadable{d.Name} return state.Error, NotLoadable{d.Name}
} }
func (d *Driver) Create() error { func (d *Driver) Create() error {
return ErrDriverNotLoadable{d.Name} return NotLoadable{d.Name}
} }
func (d *Driver) Remove() error { func (d *Driver) Remove() error {
return ErrDriverNotLoadable{d.Name} return NotLoadable{d.Name}
} }
func (d *Driver) Start() error { func (d *Driver) Start() error {
return ErrDriverNotLoadable{d.Name} return NotLoadable{d.Name}
} }
func (d *Driver) Stop() error { func (d *Driver) Stop() error {
return ErrDriverNotLoadable{d.Name} return NotLoadable{d.Name}
} }
func (d *Driver) Restart() error { func (d *Driver) Restart() error {
return ErrDriverNotLoadable{d.Name} return NotLoadable{d.Name}
} }
func (d *Driver) Kill() error { func (d *Driver) Kill() error {
return ErrDriverNotLoadable{d.Name} return NotLoadable{d.Name}
} }
func (d *Driver) Upgrade() error { func (d *Driver) Upgrade() error {
return ErrDriverNotLoadable{d.Name} return NotLoadable{d.Name}
} }

View File

@ -19,8 +19,8 @@ import (
type Driver struct { type Driver struct {
*drivers.BaseDriver *drivers.BaseDriver
URL string URL string
ApiKey string APIKey string `json:"ApiKey"`
ApiSecretKey string APISecretKey string `json:"ApiSecretKey"`
InstanceProfile string InstanceProfile string
DiskSize int DiskSize int
Image string Image string
@ -28,7 +28,7 @@ type Driver struct {
AvailabilityZone string AvailabilityZone string
KeyPair string KeyPair string
PublicKey string PublicKey string
Id string ID string `json:"Id"`
} }
const ( const (
@ -38,7 +38,7 @@ const (
defaultAvailabilityZone = "ch-gva-2" defaultAvailabilityZone = "ch-gva-2"
) )
// RegisterCreateFlags registers the flags this driver adds to // GetCreateFlags registers the flags this driver adds to
// "docker hosts create" // "docker hosts create"
func (d *Driver) GetCreateFlags() []mcnflag.Flag { func (d *Driver) GetCreateFlags() []mcnflag.Flag {
return []mcnflag.Flag{ return []mcnflag.Flag{
@ -111,14 +111,15 @@ func (d *Driver) GetSSHUsername() string {
return "ubuntu" return "ubuntu"
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "exoscale" return "exoscale"
} }
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error { func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.URL = flags.String("exoscale-endpoint") d.URL = flags.String("exoscale-endpoint")
d.ApiKey = flags.String("exoscale-api-key") d.APIKey = flags.String("exoscale-api-key")
d.ApiSecretKey = flags.String("exoscale-api-secret-key") d.APISecretKey = flags.String("exoscale-api-secret-key")
d.InstanceProfile = flags.String("exoscale-instance-profile") d.InstanceProfile = flags.String("exoscale-instance-profile")
d.DiskSize = flags.Int("exoscale-disk-size") d.DiskSize = flags.Int("exoscale-disk-size")
d.Image = flags.String("exoscale-image") d.Image = flags.String("exoscale-image")
@ -135,7 +136,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
if d.URL == "" { if d.URL == "" {
d.URL = "https://api.exoscale.ch/compute" d.URL = "https://api.exoscale.ch/compute"
} }
if d.ApiKey == "" || d.ApiSecretKey == "" { if d.APIKey == "" || d.APISecretKey == "" {
return fmt.Errorf("Please specify an API key (--exoscale-api-key) and an API secret key (--exoscale-api-secret-key).") return fmt.Errorf("Please specify an API key (--exoscale-api-key) and an API secret key (--exoscale-api-secret-key).")
} }
@ -151,8 +152,8 @@ func (d *Driver) GetURL() (string, error) {
} }
func (d *Driver) GetState() (state.State, error) { func (d *Driver) GetState() (state.State, error) {
client := egoscale.NewClient(d.URL, d.ApiKey, d.ApiSecretKey) client := egoscale.NewClient(d.URL, d.APIKey, d.APISecretKey)
vm, err := client.GetVirtualMachine(d.Id) vm, err := client.GetVirtualMachine(d.ID)
if err != nil { if err != nil {
return state.Error, err return state.Error, err
} }
@ -222,7 +223,7 @@ func (d *Driver) createDefaultSecurityGroup(client *egoscale.Client, group strin
func (d *Driver) Create() error { func (d *Driver) Create() error {
log.Infof("Querying exoscale for the requested parameters...") log.Infof("Querying exoscale for the requested parameters...")
client := egoscale.NewClient(d.URL, d.ApiKey, d.ApiSecretKey) client := egoscale.NewClient(d.URL, d.APIKey, d.APISecretKey)
topology, err := client.GetTopology() topology, err := client.GetTopology()
if err != nil { if err != nil {
return err return err
@ -314,7 +315,7 @@ func (d *Driver) Create() error {
return err return err
} }
d.IPAddress = vm.Nic[0].Ipaddress d.IPAddress = vm.Nic[0].Ipaddress
d.Id = vm.Id d.ID = vm.Id
return nil return nil
} }
@ -329,8 +330,8 @@ func (d *Driver) Start() error {
return nil return nil
} }
client := egoscale.NewClient(d.URL, d.ApiKey, d.ApiSecretKey) client := egoscale.NewClient(d.URL, d.APIKey, d.APISecretKey)
svmresp, err := client.StartVirtualMachine(d.Id) svmresp, err := client.StartVirtualMachine(d.ID)
if err != nil { if err != nil {
return err return err
} }
@ -350,8 +351,8 @@ func (d *Driver) Stop() error {
return nil return nil
} }
client := egoscale.NewClient(d.URL, d.ApiKey, d.ApiSecretKey) client := egoscale.NewClient(d.URL, d.APIKey, d.APISecretKey)
svmresp, err := client.StopVirtualMachine(d.Id) svmresp, err := client.StopVirtualMachine(d.ID)
if err != nil { if err != nil {
return err return err
} }
@ -362,7 +363,7 @@ func (d *Driver) Stop() error {
} }
func (d *Driver) Remove() error { func (d *Driver) Remove() error {
client := egoscale.NewClient(d.URL, d.ApiKey, d.ApiSecretKey) client := egoscale.NewClient(d.URL, d.APIKey, d.APISecretKey)
// Destroy the SSH key // Destroy the SSH key
if _, err := client.DeleteKeypair(d.KeyPair); err != nil { if _, err := client.DeleteKeypair(d.KeyPair); err != nil {
@ -370,7 +371,7 @@ func (d *Driver) Remove() error {
} }
// Destroy the virtual machine // Destroy the virtual machine
dvmresp, err := client.DestroyVirtualMachine(d.Id) dvmresp, err := client.DestroyVirtualMachine(d.ID)
if err != nil { if err != nil {
return err return err
} }
@ -389,8 +390,8 @@ func (d *Driver) Restart() error {
return fmt.Errorf("Host is stopped, use start command to start it") return fmt.Errorf("Host is stopped, use start command to start it")
} }
client := egoscale.NewClient(d.URL, d.ApiKey, d.ApiSecretKey) client := egoscale.NewClient(d.URL, d.APIKey, d.APISecretKey)
svmresp, err := client.RebootVirtualMachine(d.Id) svmresp, err := client.RebootVirtualMachine(d.ID)
if err != nil { if err != nil {
return err return err
} }

View File

@ -17,6 +17,7 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
return []mcnflag.Flag{} return []mcnflag.Flag{}
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "Driver" return "Driver"
} }

View File

@ -66,6 +66,7 @@ func NewDriver(hostName, storePath string) drivers.Driver {
} }
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "generic" return "generic"
} }

View File

@ -142,7 +142,7 @@ func (d *Driver) GetSSHUsername() string {
return d.SSHUser return d.SSHUser
} }
// DriverName returns the name of the driver. // DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "google" return "google"
} }

View File

@ -97,6 +97,7 @@ func (d *Driver) GetSSHUsername() string {
return d.SSHUser return d.SSHUser
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "hyperv" return "hyperv"
} }

View File

@ -42,6 +42,7 @@ func (d *Driver) Create() error {
return nil return nil
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return driverName return driverName
} }

View File

@ -35,16 +35,16 @@ type Client interface {
RestartInstance(d *Driver) error RestartInstance(d *Driver) error
DeleteInstance(d *Driver) error DeleteInstance(d *Driver) error
WaitForInstanceStatus(d *Driver, status string) 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 CreateKeyPair(d *Driver, name string, publicKey string) error
DeleteKeyPair(d *Driver, name string) error DeleteKeyPair(d *Driver, name string) error
GetNetworkId(d *Driver) (string, error) GetNetworkID(d *Driver) (string, error)
GetFlavorId(d *Driver) (string, error) GetFlavorID(d *Driver) (string, error)
GetImageId(d *Driver) (string, error) GetImageID(d *Driver) (string, error)
AssignFloatingIP(d *Driver, floatingIp *FloatingIp) error AssignFloatingIP(d *Driver, floatingIP *FloatingIP) error
GetFloatingIPs(d *Driver) ([]FloatingIp, error) GetFloatingIPs(d *Driver) ([]FloatingIP, error)
GetFloatingIpPoolId(d *Driver) (string, error) GetFloatingIPPoolID(d *Driver) (string, error)
GetInstancePortId(d *Driver) (string, error) GetInstancePortID(d *Driver) (string, error)
} }
type GenericClient struct { type GenericClient struct {
@ -86,7 +86,7 @@ const (
Fixed string = "fixed" Fixed string = "fixed"
) )
type IpAddress struct { type IPAddress struct {
Network string Network string
AddressType string AddressType string
Address string Address string
@ -94,7 +94,7 @@ type IpAddress struct {
Mac string Mac string
} }
type FloatingIp struct { type FloatingIP struct {
Id string Id string
Ip string Ip string
NetworkId string NetworkId string
@ -158,12 +158,12 @@ func (c *GenericClient) WaitForInstanceStatus(d *Driver, status string) error {
}, (d.ActiveTimeout / 4), 4*time.Second) }, (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) server, err := c.GetServerDetail(d)
if err != nil { if err != nil {
return nil, err return nil, err
} }
addresses := []IpAddress{} addresses := []IPAddress{}
for network, networkAddresses := range server.Addresses { for network, networkAddresses := range server.Addresses {
for _, element := range networkAddresses.([]interface{}) { for _, element := range networkAddresses.([]interface{}) {
address := element.(map[string]interface{}) address := element.(map[string]interface{})
@ -173,7 +173,7 @@ func (c *GenericClient) GetInstanceIpAddresses(d *Driver) ([]IpAddress, error) {
version = 4 version = 4
} }
addr := IpAddress{ addr := IPAddress{
Network: network, Network: network,
AddressType: Fixed, AddressType: Fixed,
Address: address["addr"].(string), Address: address["addr"].(string),
@ -194,18 +194,18 @@ func (c *GenericClient) GetInstanceIpAddresses(d *Driver) ([]IpAddress, error) {
return addresses, nil return addresses, nil
} }
func (c *GenericClient) GetNetworkId(d *Driver) (string, error) { func (c *GenericClient) GetNetworkID(d *Driver) (string, error) {
return c.getNetworkId(d, d.NetworkName) return c.getNetworkID(d, d.NetworkName)
} }
func (c *GenericClient) GetFloatingIpPoolId(d *Driver) (string, error) { func (c *GenericClient) GetFloatingIPPoolID(d *Driver) (string, error) {
return c.getNetworkId(d, d.FloatingIpPool) 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} opts := networks.ListOpts{Name: networkName}
pager := networks.List(c.Network, opts) pager := networks.List(c.Network, opts)
networkId := "" networkID := ""
err := pager.EachPage(func(page pagination.Page) (bool, error) { err := pager.EachPage(func(page pagination.Page) (bool, error) {
networkList, err := networks.ExtractNetworks(page) networkList, err := networks.ExtractNetworks(page)
@ -215,7 +215,7 @@ func (c *GenericClient) getNetworkId(d *Driver, networkName string) (string, err
for _, n := range networkList { for _, n := range networkList {
if n.Name == networkName { if n.Name == networkName {
networkId = n.ID networkID = n.ID
return false, nil return false, nil
} }
} }
@ -223,12 +223,12 @@ func (c *GenericClient) getNetworkId(d *Driver, networkName string) (string, err
return true, nil 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) pager := flavors.ListDetail(c.Compute, nil)
flavorId := "" flavorID := ""
err := pager.EachPage(func(page pagination.Page) (bool, error) { err := pager.EachPage(func(page pagination.Page) (bool, error) {
flavorList, err := flavors.ExtractFlavors(page) flavorList, err := flavors.ExtractFlavors(page)
@ -238,7 +238,7 @@ func (c *GenericClient) GetFlavorId(d *Driver) (string, error) {
for _, f := range flavorList { for _, f := range flavorList {
if f.Name == d.FlavorName { if f.Name == d.FlavorName {
flavorId = f.ID flavorID = f.ID
return false, nil return false, nil
} }
} }
@ -246,13 +246,13 @@ func (c *GenericClient) GetFlavorId(d *Driver) (string, error) {
return true, nil 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} opts := images.ListOpts{Name: d.ImageName}
pager := images.ListDetail(c.Compute, opts) pager := images.ListDetail(c.Compute, opts)
imageId := "" imageID := ""
err := pager.EachPage(func(page pagination.Page) (bool, error) { err := pager.EachPage(func(page pagination.Page) (bool, error) {
imageList, err := images.ExtractImages(page) imageList, err := images.ExtractImages(page)
@ -262,7 +262,7 @@ func (c *GenericClient) GetImageId(d *Driver) (string, error) {
for _, i := range imageList { for _, i := range imageList {
if i.Name == d.ImageName { if i.Name == d.ImageName {
imageId = i.ID imageID = i.ID
return false, nil return false, nil
} }
} }
@ -270,7 +270,7 @@ func (c *GenericClient) GetImageId(d *Driver) (string, error) {
return true, nil return true, nil
}) })
return imageId, err return imageID, err
} }
func (c *GenericClient) CreateKeyPair(d *Driver, name string, publicKey string) error { 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 return server, nil
} }
func (c *GenericClient) AssignFloatingIP(d *Driver, floatingIp *FloatingIp) error { func (c *GenericClient) AssignFloatingIP(d *Driver, floatingIP *FloatingIP) error {
if d.ComputeNetwork { if d.ComputeNetwork {
return c.assignNovaFloatingIP(d, floatingIp) return c.assignNovaFloatingIP(d, floatingIP)
} else {
return c.assignNeutronFloatingIP(d, floatingIp)
} }
return c.assignNeutronFloatingIP(d, floatingIP)
} }
func (c *GenericClient) assignNovaFloatingIP(d *Driver, floatingIp *FloatingIp) error { func (c *GenericClient) assignNovaFloatingIP(d *Driver, floatingIP *FloatingIP) error {
if floatingIp.Ip == "" { if floatingIP.Ip == "" {
f, err := compute_ips.Create(c.Compute, compute_ips.CreateOpts{ f, err := compute_ips.Create(c.Compute, compute_ips.CreateOpts{
Pool: d.FloatingIpPool, Pool: d.FloatingIpPool,
}).Extract() }).Extract()
if err != nil { if err != nil {
return err return err
} }
floatingIp.Ip = f.IP floatingIP.Ip = f.IP
floatingIp.Pool = f.Pool 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 { func (c *GenericClient) assignNeutronFloatingIP(d *Driver, floatingIP *FloatingIP) error {
portId, err := c.GetInstancePortId(d) portID, err := c.GetInstancePortID(d)
if err != nil { if err != nil {
return err return err
} }
if floatingIp.Id == "" { if floatingIP.Id == "" {
f, err := floatingips.Create(c.Network, floatingips.CreateOpts{ f, err := floatingips.Create(c.Network, floatingips.CreateOpts{
FloatingNetworkID: d.FloatingIpPoolId, FloatingNetworkID: d.FloatingIpPoolId,
PortID: portId, PortID: portID,
}).Extract() }).Extract()
if err != nil { if err != nil {
return err return err
} }
floatingIp.Id = f.ID floatingIP.Id = f.ID
floatingIp.Ip = f.FloatingIP floatingIP.Ip = f.FloatingIP
floatingIp.NetworkId = f.FloatingNetworkID floatingIP.NetworkId = f.FloatingNetworkID
floatingIp.PortId = f.PortID floatingIP.PortId = f.PortID
return nil return nil
} }
_, err = floatingips.Update(c.Network, floatingIp.Id, floatingips.UpdateOpts{ _, err = floatingips.Update(c.Network, floatingIP.Id, floatingips.UpdateOpts{
PortID: portId, PortID: portID,
}).Extract() }).Extract()
if err != nil { if err != nil {
return err return err
@ -349,25 +348,24 @@ func (c *GenericClient) assignNeutronFloatingIP(d *Driver, floatingIp *FloatingI
return nil return nil
} }
func (c *GenericClient) GetFloatingIPs(d *Driver) ([]FloatingIp, error) { func (c *GenericClient) GetFloatingIPs(d *Driver) ([]FloatingIP, error) {
if d.ComputeNetwork { if d.ComputeNetwork {
return c.getNovaNetworkFloatingIPs(d) 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) pager := compute_ips.List(c.Compute)
ips := []FloatingIp{} ips := []FloatingIP{}
err := pager.EachPage(func(page pagination.Page) (continue_paging bool, err error) { err := pager.EachPage(func(page pagination.Page) (continue_paging bool, err error) {
continue_paging, err = true, nil 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 { if ip.InstanceID == "" && ip.Pool == d.FloatingIpPool {
ips = append(ips, FloatingIp{ ips = append(ips, FloatingIP{
Id: ip.ID, Id: ip.ID,
Ip: ip.IP, Ip: ip.IP,
Pool: ip.Pool, Pool: ip.Pool,
@ -379,19 +377,19 @@ func (c *GenericClient) getNovaNetworkFloatingIPs(d *Driver) ([]FloatingIp, erro
return ips, err 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{ pager := floatingips.List(c.Network, floatingips.ListOpts{
FloatingNetworkID: d.FloatingIpPoolId, FloatingNetworkID: d.FloatingIpPoolId,
}) })
ips := []FloatingIp{} ips := []FloatingIP{}
err := pager.EachPage(func(page pagination.Page) (bool, error) { err := pager.EachPage(func(page pagination.Page) (bool, error) {
floatingipList, err := floatingips.ExtractFloatingIPs(page) floatingipList, err := floatingips.ExtractFloatingIPs(page)
if err != nil { if err != nil {
return false, err return false, err
} }
for _, f := range floatingipList { for _, f := range floatingipList {
ips = append(ips, FloatingIp{ ips = append(ips, FloatingIP{
Id: f.ID, Id: f.ID,
Ip: f.FloatingIP, Ip: f.FloatingIP,
NetworkId: f.FloatingNetworkID, NetworkId: f.FloatingNetworkID,
@ -407,20 +405,20 @@ func (c *GenericClient) getNeutronNetworkFloatingIPs(d *Driver) ([]FloatingIp, e
return ips, nil 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{ pager := ports.List(c.Network, ports.ListOpts{
DeviceID: d.MachineId, DeviceID: d.MachineId,
NetworkID: d.NetworkId, NetworkID: d.NetworkId,
}) })
var portId string var portID string
err := pager.EachPage(func(page pagination.Page) (bool, error) { err := pager.EachPage(func(page pagination.Page) (bool, error) {
portList, err := ports.ExtractPorts(page) portList, err := ports.ExtractPorts(page)
if err != nil { if err != nil {
return false, err return false, err
} }
for _, port := range portList { for _, port := range portList {
portId = port.ID portID = port.ID
return false, nil return false, nil
} }
return true, nil return true, nil
@ -429,7 +427,7 @@ func (c *GenericClient) GetInstancePortId(d *Driver) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
return portId, nil return portID, nil
} }
func (c *GenericClient) InitComputeClient(d *Driver) error { func (c *GenericClient) InitComputeClient(d *Driver) error {

View File

@ -222,6 +222,7 @@ func (d *Driver) SetClient(client Client) {
d.client = client d.client = client
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "openstack" 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 // Looking for the IP address in a retry loop to deal with OpenStack latency
for retryCount := 0; retryCount < 200; retryCount++ { for retryCount := 0; retryCount < 200; retryCount++ {
addresses, err := d.client.GetInstanceIpAddresses(d) addresses, err := d.client.GetInstanceIPAddresses(d)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -352,11 +353,11 @@ func (d *Driver) Create() error {
return err return err
} }
if d.FloatingIpPool != "" { if d.FloatingIpPool != "" {
if err := d.assignFloatingIp(); err != nil { if err := d.assignFloatingIP(); err != nil {
return err return err
} }
} }
if err := d.lookForIpAddress(); err != nil { if err := d.lookForIPAddress(); err != nil {
return err return err
} }
return nil return nil
@ -420,7 +421,7 @@ const (
errorMandatoryEnvOrOption string = "%s must be specified either using the environment variable %s or the CLI option %s" 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" errorMandatoryOption string = "%s must be specified using the CLI option %s"
errorExclusiveOptions string = "Either %s or %s must be specified, not both" 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'" errorWrongEndpointType string = "Endpoint type must be 'publicURL', 'adminURL' or 'internalURL'"
errorUnknownFlavorName string = "Unable to find flavor named %s" errorUnknownFlavorName string = "Unable to find flavor named %s"
errorUnknownImageName string = "Unable to find image 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") return fmt.Errorf(errorMandatoryEnvOrOption, "Password", "OS_PASSWORD", "--openstack-password")
} }
if d.TenantName == "" && d.TenantId == "" { if d.TenantName == "" && d.TenantId == "" {
return fmt.Errorf(errorMandatoryTenantNameOrId) return fmt.Errorf(errorMandatoryTenantNameOrID)
} }
if d.FlavorName == "" && d.FlavorId == "" { if d.FlavorName == "" && d.FlavorId == "" {
@ -470,17 +471,17 @@ func (d *Driver) resolveIds() error {
return err return err
} }
networkId, err := d.client.GetNetworkId(d) networkID, err := d.client.GetNetworkID(d)
if err != nil { if err != nil {
return err return err
} }
if networkId == "" { if networkID == "" {
return fmt.Errorf(errorUnknownNetworkName, d.NetworkName) return fmt.Errorf(errorUnknownNetworkName, d.NetworkName)
} }
d.NetworkId = networkId d.NetworkId = networkID
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"Name": d.NetworkName, "Name": d.NetworkName,
"ID": d.NetworkId, "ID": d.NetworkId,
@ -491,17 +492,17 @@ func (d *Driver) resolveIds() error {
if err := d.initCompute(); err != nil { if err := d.initCompute(); err != nil {
return err return err
} }
flavorId, err := d.client.GetFlavorId(d) flavorID, err := d.client.GetFlavorID(d)
if err != nil { if err != nil {
return err return err
} }
if flavorId == "" { if flavorID == "" {
return fmt.Errorf(errorUnknownFlavorName, d.FlavorName) return fmt.Errorf(errorUnknownFlavorName, d.FlavorName)
} }
d.FlavorId = flavorId d.FlavorId = flavorID
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"Name": d.FlavorName, "Name": d.FlavorName,
"ID": d.FlavorId, "ID": d.FlavorId,
@ -512,17 +513,17 @@ func (d *Driver) resolveIds() error {
if err := d.initCompute(); err != nil { if err := d.initCompute(); err != nil {
return err return err
} }
imageId, err := d.client.GetImageId(d) imageID, err := d.client.GetImageID(d)
if err != nil { if err != nil {
return err return err
} }
if imageId == "" { if imageID == "" {
return fmt.Errorf(errorUnknownImageName, d.ImageName) return fmt.Errorf(errorUnknownImageName, d.ImageName)
} }
d.ImageId = imageId d.ImageId = imageID
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"Name": d.ImageName, "Name": d.ImageName,
"ID": d.ImageId, "ID": d.ImageId,
@ -533,7 +534,7 @@ func (d *Driver) resolveIds() error {
if err := d.initNetwork(); err != nil { if err := d.initNetwork(); err != nil {
return err return err
} }
f, err := d.client.GetFloatingIpPoolId(d) f, err := d.client.GetFloatingIPPoolID(d)
if err != nil { if err != nil {
return err return err
@ -601,15 +602,15 @@ func (d *Driver) createMachine() error {
if err := d.initCompute(); err != nil { if err := d.initCompute(); err != nil {
return err return err
} }
instanceId, err := d.client.CreateInstance(d) instanceID, err := d.client.CreateInstance(d)
if err != nil { if err != nil {
return err return err
} }
d.MachineId = instanceId d.MachineId = instanceID
return nil return nil
} }
func (d *Driver) assignFloatingIp() error { func (d *Driver) assignFloatingIP() error {
var err error var err error
if d.ComputeNetwork { if d.ComputeNetwork {
@ -627,7 +628,7 @@ func (d *Driver) assignFloatingIp() error {
return err return err
} }
var floatingIp *FloatingIp var floatingIP *FloatingIP
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"MachineId": d.MachineId, "MachineId": d.MachineId,
@ -640,22 +641,22 @@ func (d *Driver) assignFloatingIp() error {
"MachineId": d.MachineId, "MachineId": d.MachineId,
"IP": ip.Ip, "IP": ip.Ip,
}).Debugf("Available floating IP found") }).Debugf("Available floating IP found")
floatingIp = &ip floatingIP = &ip
break break
} }
} }
if floatingIp == nil { if floatingIP == nil {
floatingIp = &FloatingIp{} floatingIP = &FloatingIP{}
log.WithField("MachineId", d.MachineId).Debugf("No available floating IP found. Allocating a new one...") log.WithField("MachineId", d.MachineId).Debugf("No available floating IP found. Allocating a new one...")
} else { } else {
log.WithField("MachineId", d.MachineId).Debugf("Assigning floating IP to the instance") 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 return err
} }
d.IPAddress = floatingIp.Ip d.IPAddress = floatingIP.Ip
return nil return nil
} }
@ -667,7 +668,7 @@ func (d *Driver) waitForInstanceActive() error {
return nil return nil
} }
func (d *Driver) lookForIpAddress() error { func (d *Driver) lookForIPAddress() error {
ip, err := d.GetIP() ip, err := d.GetIP()
if err != nil { if err != nil {
return err return err

View File

@ -63,13 +63,13 @@ func (c *Client) StopInstance(d *openstack.Driver) error {
return unsupportedOpErr("stop") return unsupportedOpErr("stop")
} }
// GetInstanceIpAddresses can be short-circuited with the server's AccessIPv4Addr on Rackspace. // GetInstanceIPAddresses can be short-circuited with the server's AccessIPv4Addr on Rackspace.
func (c *Client) GetInstanceIpAddresses(d *openstack.Driver) ([]openstack.IpAddress, error) { func (c *Client) GetInstanceIPAddresses(d *openstack.Driver) ([]openstack.IPAddress, error) {
server, err := c.GetServerDetail(d) server, err := c.GetServerDetail(d)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return []openstack.IpAddress{ return []openstack.IPAddress{
{ {
Network: "public", Network: "public",
Address: server.AccessIPv4, Address: server.AccessIPv4,

View File

@ -18,7 +18,7 @@ type Driver struct {
const ( const (
defaultEndpointType = "publicURL" defaultEndpointType = "publicURL"
defaultFlavorId = "general1-1" defaultFlavorID = "general1-1"
defaultSSHUser = "root" defaultSSHUser = "root"
defaultSSHPort = 22 defaultSSHPort = 22
defaultDockerInstall = "true" defaultDockerInstall = "true"
@ -59,7 +59,7 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
mcnflag.StringFlag{ mcnflag.StringFlag{
Name: "rackspace-flavor-id", Name: "rackspace-flavor-id",
Usage: "Rackspace flavor ID. Default: General Purpose 1GB", Usage: "Rackspace flavor ID. Default: General Purpose 1GB",
Value: defaultFlavorId, Value: defaultFlavorID,
EnvVar: "OS_FLAVOR_ID", EnvVar: "OS_FLAVOR_ID",
}, },
mcnflag.StringFlag{ mcnflag.StringFlag{
@ -97,7 +97,7 @@ func NewDriver(machineName, storePath string) drivers.Driver {
return driver return driver
} }
// DriverName is the user-visible name of this driver. // DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "rackspace" return "rackspace"
} }

View File

@ -15,7 +15,7 @@ import (
) )
const ( const (
ApiEndpoint = "https://api.softlayer.com/rest/v3" APIEndpoint = "https://api.softlayer.com/rest/v3"
) )
type Driver struct { type Driver struct {
@ -54,7 +54,7 @@ const (
func NewDriver(hostName, storePath string) drivers.Driver { func NewDriver(hostName, storePath string) drivers.Driver {
return &Driver{ return &Driver{
Client: &Client{ Client: &Client{
Endpoint: ApiEndpoint, Endpoint: APIEndpoint,
}, },
deviceConfig: &deviceConfig{ deviceConfig: &deviceConfig{
HourlyBilling: true, HourlyBilling: true,
@ -131,7 +131,7 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
EnvVar: "SOFTLAYER_API_ENDPOINT", EnvVar: "SOFTLAYER_API_ENDPOINT",
Name: "softlayer-api-endpoint", Name: "softlayer-api-endpoint",
Usage: "softlayer api endpoint to use", Usage: "softlayer api endpoint to use",
Value: ApiEndpoint, Value: APIEndpoint,
}, },
mcnflag.BoolFlag{ mcnflag.BoolFlag{
EnvVar: "SOFTLAYER_HOURLY_BILLING", EnvVar: "SOFTLAYER_HOURLY_BILLING",
@ -252,6 +252,7 @@ func (d *Driver) getClient() *Client {
return d.Client return d.Client
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "softlayer" return "softlayer"
} }
@ -272,10 +273,9 @@ func (d *Driver) GetIP() (string, error) {
return d.IPAddress, nil return d.IPAddress, nil
} }
if d.deviceConfig != nil && d.deviceConfig.PrivateNet == true { if d.deviceConfig != nil && d.deviceConfig.PrivateNet == true {
return d.getClient().VirtualGuest().GetPrivateIp(d.Id) return d.getClient().VirtualGuest().GetPrivateIP(d.Id)
} else {
return d.getClient().VirtualGuest().GetPublicIp(d.Id)
} }
return d.getClient().VirtualGuest().GetPublicIP(d.Id)
} }
func (d *Driver) GetState() (state.State, error) { func (d *Driver) GetState() (state.State, error) {
@ -321,7 +321,7 @@ func (d *Driver) waitForStart() {
} }
} }
func (d *Driver) getIp() (string, error) { func (d *Driver) getIP() (string, error) {
log.Infof("Getting Host IP") log.Infof("Getting Host IP")
for { for {
var ( var (
@ -329,9 +329,9 @@ func (d *Driver) getIp() (string, error) {
err error err error
) )
if d.deviceConfig.PrivateNet { if d.deviceConfig.PrivateNet {
ip, err = d.getClient().VirtualGuest().GetPrivateIp(d.Id) ip, err = d.getClient().VirtualGuest().GetPrivateIP(d.Id)
} else { } else {
ip, err = d.getClient().VirtualGuest().GetPublicIp(d.Id) ip, err = d.getClient().VirtualGuest().GetPublicIP(d.Id)
} }
if err != nil { if err != nil {
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
@ -386,14 +386,14 @@ func (d *Driver) Create() error {
log.Infof("SSH key %s (%d) created in SoftLayer", key.Label, key.Id) log.Infof("SSH key %s (%d) created in SoftLayer", key.Label, key.Id)
d.SSHKeyID = key.Id d.SSHKeyID = key.Id
spec.SshKeys = []*SshKey{key} spec.SshKeys = []*SSHKey{key}
id, err := d.getClient().VirtualGuest().Create(spec) id, err := d.getClient().VirtualGuest().Create(spec)
if err != nil { if err != nil {
return fmt.Errorf("Error creating host: %q", err) return fmt.Errorf("Error creating host: %q", err)
} }
d.Id = id d.Id = id
d.getIp() d.getIP()
d.waitForStart() d.waitForStart()
d.waitForSetupTransactions() d.waitForSetupTransactions()
@ -433,7 +433,7 @@ func (d *Driver) buildHostSpec() *HostSpec {
return spec return spec
} }
func (d *Driver) createSSHKey() (*SshKey, error) { func (d *Driver) createSSHKey() (*SSHKey, error) {
if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil { if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
return nil, err return nil, err
} }
@ -443,7 +443,7 @@ func (d *Driver) createSSHKey() (*SshKey, error) {
return nil, err return nil, err
} }
key, err := d.getClient().SshKey().Create(d.deviceConfig.Hostname, string(publicKey)) key, err := d.getClient().SSHKey().Create(d.deviceConfig.Hostname, string(publicKey))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -474,7 +474,7 @@ func (d *Driver) Remove() error {
} }
log.Infof("Removing SSH Key %d...", d.SSHKeyID) log.Infof("Removing SSH Key %d...", d.SSHKeyID)
if err = d.getClient().SshKey().Delete(d.SSHKeyID); err != nil { if err = d.getClient().SSHKey().Delete(d.SSHKeyID); err != nil {
return err return err
} }

View File

@ -21,7 +21,7 @@ type HostSpec struct {
Cpu int `json:"startCpus"` Cpu int `json:"startCpus"`
Memory int `json:"maxMemory"` Memory int `json:"maxMemory"`
Datacenter Datacenter `json:"datacenter"` Datacenter Datacenter `json:"datacenter"`
SshKeys []*SshKey `json:"sshKeys"` SshKeys []*SSHKey `json:"sshKeys"`
BlockDevices []BlockDevice `json:"blockDevices"` BlockDevices []BlockDevice `json:"blockDevices"`
InstallScript string `json:"postInstallScriptUri"` InstallScript string `json:"postInstallScriptUri"`
PrivateNetOnly bool `json:"privateNetworkOnlyFlag"` PrivateNetOnly bool `json:"privateNetworkOnlyFlag"`
@ -40,7 +40,7 @@ type NetworkVLAN struct {
Id int `json:"id"` Id int `json:"id"`
} }
type SshKey struct { type SSHKey struct {
Key string `json:"key,omitempty"` Key string `json:"key,omitempty"`
Id int `json:"id,omitempty"` Id int `json:"id,omitempty"`
Label string `json:"label,omitempty"` Label string `json:"label,omitempty"`
@ -63,7 +63,7 @@ type sshKey struct {
*Client *Client
} }
type virtualGuest struct { type VirtualGuest struct {
*Client *Client
} }
@ -95,11 +95,11 @@ func (c *Client) newRequest(method, uri string, body interface{}) ([]byte, error
) )
if body != nil { if body != nil {
bodyJson, err := json.Marshal(body) bodyJSON, err := json.Marshal(body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
req, err = http.NewRequest(method, url, bytes.NewBuffer(bodyJson)) req, err = http.NewRequest(method, url, bytes.NewBuffer(bodyJSON))
} else { } else {
req, err = http.NewRequest(method, url, nil) req, err = http.NewRequest(method, url, nil)
} }
@ -132,7 +132,7 @@ func (c *Client) newRequest(method, uri string, body interface{}) ([]byte, error
return data, nil return data, nil
} }
func (c *Client) SshKey() *sshKey { func (c *Client) SSHKey() *sshKey {
return &sshKey{c} return &sshKey{c}
} }
@ -140,11 +140,11 @@ func (c *sshKey) namespace() string {
return "SoftLayer_Security_Ssh_Key" return "SoftLayer_Security_Ssh_Key"
} }
func (c *sshKey) Create(label, key string) (*SshKey, error) { func (c *sshKey) Create(label, key string) (*SSHKey, error) {
var ( var (
method = "POST" method = "POST"
uri = c.namespace() uri = c.namespace()
body = SshKey{Key: key, Label: label} body = SSHKey{Key: key, Label: label}
) )
data, err := c.newRequest(method, uri, map[string]interface{}{"parameters": []interface{}{body}}) data, err := c.newRequest(method, uri, map[string]interface{}{"parameters": []interface{}{body}})
@ -152,7 +152,7 @@ func (c *sshKey) Create(label, key string) (*SshKey, error) {
return nil, err return nil, err
} }
var k SshKey var k SSHKey
if err := json.Unmarshal(data, &k); err != nil { if err := json.Unmarshal(data, &k); err != nil {
return nil, err return nil, err
} }
@ -173,15 +173,15 @@ func (c *sshKey) Delete(id int) error {
return nil return nil
} }
func (c *Client) VirtualGuest() *virtualGuest { func (c *Client) VirtualGuest() *VirtualGuest {
return &virtualGuest{c} return &VirtualGuest{c}
} }
func (c *virtualGuest) namespace() string { func (c *VirtualGuest) namespace() string {
return "SoftLayer_Virtual_Guest" return "SoftLayer_Virtual_Guest"
} }
func (c *virtualGuest) PowerState(id int) (string, error) { func (c *VirtualGuest) PowerState(id int) (string, error) {
type state struct { type state struct {
KeyName string `json:"keyName"` KeyName string `json:"keyName"`
Name string `json:"name"` Name string `json:"name"`
@ -203,7 +203,7 @@ func (c *virtualGuest) PowerState(id int) (string, error) {
return s.Name, nil return s.Name, nil
} }
func (c *virtualGuest) ActiveTransaction(id int) (string, error) { func (c *VirtualGuest) ActiveTransaction(id int) (string, error) {
type transactionStatus struct { type transactionStatus struct {
AverageDuration string `json:"averageDuration"` AverageDuration string `json:"averageDuration"`
FriendlyName string `json:"friendlyName"` FriendlyName string `json:"friendlyName"`
@ -236,7 +236,7 @@ func (c *virtualGuest) ActiveTransaction(id int) (string, error) {
return t.TransactionStatus.Name, nil return t.TransactionStatus.Name, nil
} }
func (c *virtualGuest) Create(spec *HostSpec) (int, error) { func (c *VirtualGuest) Create(spec *HostSpec) (int, error) {
var ( var (
method = "POST" method = "POST"
uri = c.namespace() + ".json" uri = c.namespace() + ".json"
@ -248,7 +248,7 @@ func (c *virtualGuest) Create(spec *HostSpec) (int, error) {
} }
type createResp struct { type createResp struct {
Id int `json:"id"` ID int `json:"id"`
} }
var r createResp var r createResp
@ -256,10 +256,10 @@ func (c *virtualGuest) Create(spec *HostSpec) (int, error) {
return -1, err return -1, err
} }
return r.Id, nil return r.ID, nil
} }
func (c *virtualGuest) Cancel(id int) error { func (c *VirtualGuest) Cancel(id int) error {
var ( var (
method = "DELETE" method = "DELETE"
uri = fmt.Sprintf("%s/%v", c.namespace(), id) uri = fmt.Sprintf("%s/%v", c.namespace(), id)
@ -272,7 +272,7 @@ func (c *virtualGuest) Cancel(id int) error {
return nil return nil
} }
func (c *virtualGuest) PowerOn(id int) error { func (c *VirtualGuest) PowerOn(id int) error {
var ( var (
method = "GET" method = "GET"
uri = fmt.Sprintf("%s/%v/powerOn.json", c.namespace(), id) uri = fmt.Sprintf("%s/%v/powerOn.json", c.namespace(), id)
@ -285,7 +285,7 @@ func (c *virtualGuest) PowerOn(id int) error {
return nil return nil
} }
func (c *virtualGuest) PowerOff(id int) error { func (c *VirtualGuest) PowerOff(id int) error {
var ( var (
method = "GET" method = "GET"
uri = fmt.Sprintf("%s/%v/powerOff.json", c.namespace(), id) uri = fmt.Sprintf("%s/%v/powerOff.json", c.namespace(), id)
@ -298,7 +298,7 @@ func (c *virtualGuest) PowerOff(id int) error {
return nil return nil
} }
func (c *virtualGuest) Pause(id int) error { func (c *VirtualGuest) Pause(id int) error {
var ( var (
method = "GET" method = "GET"
uri = fmt.Sprintf("%s/%v/pause.json", c.namespace(), id) uri = fmt.Sprintf("%s/%v/pause.json", c.namespace(), id)
@ -311,7 +311,7 @@ func (c *virtualGuest) Pause(id int) error {
return nil return nil
} }
func (c *virtualGuest) Resume(id int) error { func (c *VirtualGuest) Resume(id int) error {
var ( var (
method = "GET" method = "GET"
uri = fmt.Sprintf("%s/%v/resume.json", c.namespace(), id) uri = fmt.Sprintf("%s/%v/resume.json", c.namespace(), id)
@ -324,7 +324,7 @@ func (c *virtualGuest) Resume(id int) error {
return nil return nil
} }
func (c *virtualGuest) Reboot(id int) error { func (c *VirtualGuest) Reboot(id int) error {
var ( var (
method = "GET" method = "GET"
uri = fmt.Sprintf("%s/%v/rebootSoft.json", c.namespace(), id) uri = fmt.Sprintf("%s/%v/rebootSoft.json", c.namespace(), id)
@ -337,7 +337,7 @@ func (c *virtualGuest) Reboot(id int) error {
return nil return nil
} }
func (c *virtualGuest) GetPublicIp(id int) (string, error) { func (c *VirtualGuest) GetPublicIP(id int) (string, error) {
var ( var (
method = "GET" method = "GET"
uri = fmt.Sprintf("%s/%v/getPrimaryIpAddress.json", c.namespace(), id) uri = fmt.Sprintf("%s/%v/getPrimaryIpAddress.json", c.namespace(), id)
@ -350,7 +350,7 @@ func (c *virtualGuest) GetPublicIp(id int) (string, error) {
return strings.Replace(string(data), "\"", "", -1), nil return strings.Replace(string(data), "\"", "", -1), nil
} }
func (c *virtualGuest) GetPrivateIp(id int) (string, error) { func (c *VirtualGuest) GetPrivateIP(id int) (string, error) {
var ( var (
method = "GET" method = "GET"
uri = fmt.Sprintf("%s/%v/getPrimaryBackendIpAddress.json", c.namespace(), id) uri = fmt.Sprintf("%s/%v/getPrimaryBackendIpAddress.json", c.namespace(), id)

View File

@ -147,6 +147,7 @@ func (d *Driver) GetSSHUsername() string {
return d.SSHUser return d.SSHUser
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "virtualbox" return "virtualbox"
} }
@ -401,7 +402,7 @@ func (d *Driver) Create() error {
return d.Start() return d.Start()
} }
func (d *Driver) hostOnlyIpAvailable() bool { func (d *Driver) hostOnlyIPAvailable() bool {
ip, err := d.GetIP() ip, err := d.GetIP()
if err != nil { if err != nil {
log.Debugf("ERROR getting IP: %s", err) log.Debugf("ERROR getting IP: %s", err)
@ -464,7 +465,7 @@ func (d *Driver) Start() error {
} }
// Bail if we don't get an IP from DHCP after a given number of seconds. // Bail if we don't get an IP from DHCP after a given number of seconds.
if err := mcnutils.WaitForSpecific(d.hostOnlyIpAvailable, 5, 4*time.Second); err != nil { if err := mcnutils.WaitForSpecific(d.hostOnlyIPAvailable, 5, 4*time.Second); err != nil {
return err return err
} }

View File

@ -7,12 +7,12 @@ import (
"strings" "strings"
) )
type VirtualBoxVM struct { type VM struct {
CPUs int CPUs int
Memory int Memory int
} }
func (d *Driver) getVMInfo(name string) (*VirtualBoxVM, error) { func (d *Driver) getVMInfo(name string) (*VM, error) {
out, err := d.vbmOut("showvminfo", name, "--machinereadable") out, err := d.vbmOut("showvminfo", name, "--machinereadable")
if err != nil { if err != nil {
return nil, err return nil, err
@ -22,9 +22,9 @@ func (d *Driver) getVMInfo(name string) (*VirtualBoxVM, error) {
return parseVMInfo(r) return parseVMInfo(r)
} }
func parseVMInfo(r io.Reader) (*VirtualBoxVM, error) { func parseVMInfo(r io.Reader) (*VM, error) {
s := bufio.NewScanner(r) s := bufio.NewScanner(r)
vm := &VirtualBoxVM{} vm := &VM{}
for s.Scan() { for s.Scan() {
line := s.Text() line := s.Text()
if line == "" { if line == "" {

View File

@ -131,6 +131,7 @@ func (d *Driver) GetSSHUsername() string {
return d.SSHUser return d.SSHUser
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "vmwarefusion" return "vmwarefusion"
} }

View File

@ -142,7 +142,7 @@ func (d *Driver) GetSSHHostname() (string, error) {
return d.GetIP() return d.GetIP()
} }
// Driver interface implementation // DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "vmwarevcloudair" return "vmwarevcloudair"
} }

View File

@ -147,6 +147,7 @@ func (d *Driver) GetSSHUsername() string {
return d.SSHUser return d.SSHUser
} }
// DriverName returns the name of the driver
func (d *Driver) DriverName() string { func (d *Driver) DriverName() string {
return "vmwarevsphere" return "vmwarevsphere"
} }
@ -212,7 +213,7 @@ func (d *Driver) GetState() (state.State, error) {
return state.None, nil return state.None, nil
} }
// the current implementation does the following: // Create has the following implementation:
// 1. check whether the docker directory contains the boot2docker ISO // 1. check whether the docker directory contains the boot2docker ISO
// 2. generate an SSH keypair and bundle it in a tar. // 2. generate an SSH keypair and bundle it in a tar.
// 3. create a virtual machine with the boot2docker ISO mounted; // 3. create a virtual machine with the boot2docker ISO mounted;

View File

@ -10,7 +10,7 @@ import (
func TestIP(t *testing.T) { func TestIP(t *testing.T) {
cases := []struct { cases := []struct {
baseDriver *BaseDriver baseDriver *BaseDriver
expectedIp string expectedIP string
expectedErr error expectedErr error
}{ }{
{&BaseDriver{}, "", errors.New("IP address is not set")}, {&BaseDriver{}, "", errors.New("IP address is not set")},
@ -22,7 +22,7 @@ func TestIP(t *testing.T) {
for _, c := range cases { for _, c := range cases {
ip, err := c.baseDriver.GetIP() ip, err := c.baseDriver.GetIP()
assert.Equal(t, c.expectedIp, ip) assert.Equal(t, c.expectedIP, ip)
assert.Equal(t, c.expectedErr, err) assert.Equal(t, c.expectedErr, err)
} }
} }

View File

@ -15,7 +15,7 @@ type Driver interface {
// Create a host using the driver's config // Create a host using the driver's config
Create() error Create() error
// DriverName returns the name of the driver as it is registered // DriverName returns the name of the driver
DriverName() string DriverName() string
// GetCreateFlags returns the mcnflag.Flag slice representing the flags // GetCreateFlags returns the mcnflag.Flag slice representing the flags

View File

@ -62,7 +62,7 @@ type DriverPlugin interface {
PluginStreamer PluginStreamer
} }
type LocalBinaryPlugin struct { type Plugin struct {
Executor McnBinaryExecutor Executor McnBinaryExecutor
Addr string Addr string
MachineName string MachineName string
@ -70,7 +70,7 @@ type LocalBinaryPlugin struct {
stopCh chan bool stopCh chan bool
} }
type LocalBinaryExecutor struct { type Executor struct {
pluginStdout, pluginStderr io.ReadCloser pluginStdout, pluginStderr io.ReadCloser
DriverName string DriverName string
binaryPath string binaryPath string
@ -84,7 +84,7 @@ func (e ErrPluginBinaryNotFound) Error() string {
return fmt.Sprintf("Driver %q not found. Do you have the plugin binary accessible in your PATH?", e.driverName) return fmt.Sprintf("Driver %q not found. Do you have the plugin binary accessible in your PATH?", e.driverName)
} }
func NewLocalBinaryPlugin(driverName string) (*LocalBinaryPlugin, error) { func NewPlugin(driverName string) (*Plugin, error) {
binaryPath, err := exec.LookPath(fmt.Sprintf("docker-machine-driver-%s", driverName)) binaryPath, err := exec.LookPath(fmt.Sprintf("docker-machine-driver-%s", driverName))
if err != nil { if err != nil {
return nil, ErrPluginBinaryNotFound{driverName} return nil, ErrPluginBinaryNotFound{driverName}
@ -92,17 +92,17 @@ func NewLocalBinaryPlugin(driverName string) (*LocalBinaryPlugin, error) {
log.Debugf("Found binary path at %s", binaryPath) log.Debugf("Found binary path at %s", binaryPath)
return &LocalBinaryPlugin{ return &Plugin{
stopCh: make(chan bool), stopCh: make(chan bool),
addrCh: make(chan string, 1), addrCh: make(chan string, 1),
Executor: &LocalBinaryExecutor{ Executor: &Executor{
DriverName: driverName, DriverName: driverName,
binaryPath: binaryPath, binaryPath: binaryPath,
}, },
}, nil }, nil
} }
func (lbe *LocalBinaryExecutor) Start() (*bufio.Scanner, *bufio.Scanner, error) { func (lbe *Executor) Start() (*bufio.Scanner, *bufio.Scanner, error) {
var err error var err error
log.Debugf("Launching plugin server for driver %s", lbe.DriverName) log.Debugf("Launching plugin server for driver %s", lbe.DriverName)
@ -131,7 +131,7 @@ func (lbe *LocalBinaryExecutor) Start() (*bufio.Scanner, *bufio.Scanner, error)
return outScanner, errScanner, nil return outScanner, errScanner, nil
} }
func (lbe *LocalBinaryExecutor) Close() error { func (lbe *Executor) Close() error {
if err := lbe.pluginStdout.Close(); err != nil { if err := lbe.pluginStdout.Close(); err != nil {
return err return err
} }
@ -164,14 +164,14 @@ func stream(scanner *bufio.Scanner, streamOutCh chan<- string, stopCh <-chan boo
} }
} }
func (lbp *LocalBinaryPlugin) AttachStream(scanner *bufio.Scanner) (<-chan string, chan<- bool) { func (lbp *Plugin) AttachStream(scanner *bufio.Scanner) (<-chan string, chan<- bool) {
streamOutCh := make(chan string) streamOutCh := make(chan string)
stopCh := make(chan bool) stopCh := make(chan bool)
go stream(scanner, streamOutCh, stopCh) go stream(scanner, streamOutCh, stopCh)
return streamOutCh, stopCh return streamOutCh, stopCh
} }
func (lbp *LocalBinaryPlugin) execServer() error { func (lbp *Plugin) execServer() error {
outScanner, errScanner, err := lbp.Executor.Start() outScanner, errScanner, err := lbp.Executor.Start()
if err != nil { if err != nil {
return err return err
@ -207,11 +207,11 @@ func (lbp *LocalBinaryPlugin) execServer() error {
} }
} }
func (lbp *LocalBinaryPlugin) Serve() error { func (lbp *Plugin) Serve() error {
return lbp.execServer() return lbp.execServer()
} }
func (lbp *LocalBinaryPlugin) Address() (string, error) { func (lbp *Plugin) Address() (string, error) {
if lbp.Addr == "" { if lbp.Addr == "" {
select { select {
case lbp.Addr = <-lbp.addrCh: case lbp.Addr = <-lbp.addrCh:
@ -225,7 +225,7 @@ func (lbp *LocalBinaryPlugin) Address() (string, error) {
return lbp.Addr, nil return lbp.Addr, nil
} }
func (lbp *LocalBinaryPlugin) Close() error { func (lbp *Plugin) Close() error {
lbp.stopCh <- true lbp.stopCh <- true
return nil return nil
} }

View File

@ -26,7 +26,7 @@ func (fe *FakeExecutor) Close() error {
} }
func TestLocalBinaryPluginAddress(t *testing.T) { func TestLocalBinaryPluginAddress(t *testing.T) {
lbp := &LocalBinaryPlugin{} lbp := &Plugin{}
expectedAddr := "127.0.0.1:12345" expectedAddr := "127.0.0.1:12345"
lbp.addrCh = make(chan string, 1) lbp.addrCh = make(chan string, 1)
@ -55,7 +55,7 @@ func TestLocalBinaryPluginAddressTimeout(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("Skipping timeout test") t.Skip("Skipping timeout test")
} }
lbp := &LocalBinaryPlugin{} lbp := &Plugin{}
lbp.addrCh = make(chan string, 1) lbp.addrCh = make(chan string, 1)
go func() { go func() {
_, err := lbp.Address() _, err := lbp.Address()
@ -67,7 +67,7 @@ func TestLocalBinaryPluginAddressTimeout(t *testing.T) {
} }
func TestLocalBinaryPluginClose(t *testing.T) { func TestLocalBinaryPluginClose(t *testing.T) {
lbp := &LocalBinaryPlugin{} lbp := &Plugin{}
lbp.stopCh = make(chan bool, 1) lbp.stopCh = make(chan bool, 1)
go lbp.Close() go lbp.Close()
stopped := <-lbp.stopCh stopped := <-lbp.stopCh
@ -99,7 +99,7 @@ func TestExecServer(t *testing.T) {
stderr: stderrReader, stderr: stderrReader,
} }
lbp := &LocalBinaryPlugin{ lbp := &Plugin{
MachineName: machineName, MachineName: machineName,
Executor: fe, Executor: fe,
addrCh: make(chan string, 1), addrCh: make(chan string, 1),

View File

@ -31,7 +31,7 @@ Please use this plugin through the main 'docker-machine' binary.
libmachine.SetDebug(true) libmachine.SetDebug(true)
rpcd := rpcdriver.NewRpcServerDriver(d) rpcd := rpcdriver.NewRPCServerDriver(d)
rpc.Register(rpcd) rpc.Register(rpcd)
rpc.HandleHTTP() rpc.HandleHTTP()

View File

@ -17,13 +17,13 @@ var (
heartbeatInterval = 200 * time.Millisecond heartbeatInterval = 200 * time.Millisecond
) )
type RpcClientDriver struct { type RPCClientDriver struct {
plugin localbinary.DriverPlugin plugin localbinary.DriverPlugin
heartbeatDoneCh chan bool heartbeatDoneCh chan bool
Client *InternalClient Client *InternalClient
} }
type RpcCall struct { type RPCCall struct {
ServiceMethod string ServiceMethod string
Args interface{} Args interface{}
Reply interface{} Reply interface{}
@ -31,26 +31,26 @@ type RpcCall struct {
type InternalClient struct { type InternalClient struct {
MachineName string MachineName string
RpcClient *rpc.Client RPCClient *rpc.Client
} }
func (ic *InternalClient) Call(serviceMethod string, args interface{}, reply interface{}) error { func (ic *InternalClient) Call(serviceMethod string, args interface{}, reply interface{}) error {
if serviceMethod != "RpcServerDriver.Heartbeat" { if serviceMethod != "RPCServerDriver.Heartbeat" {
log.Debugf("(%s) Calling %+v", ic.MachineName, serviceMethod) log.Debugf("(%s) Calling %+v", ic.MachineName, serviceMethod)
} }
return ic.RpcClient.Call(serviceMethod, args, reply) return ic.RPCClient.Call(serviceMethod, args, reply)
} }
func NewInternalClient(rpcclient *rpc.Client) *InternalClient { func NewInternalClient(rpcclient *rpc.Client) *InternalClient {
return &InternalClient{ return &InternalClient{
RpcClient: rpcclient, RPCClient: rpcclient,
} }
} }
func NewRpcClientDriver(rawDriverData []byte, driverName string) (*RpcClientDriver, error) { func NewRPCClientDriver(rawDriverData []byte, driverName string) (*RPCClientDriver, error) {
mcnName := "" mcnName := ""
p, err := localbinary.NewLocalBinaryPlugin(driverName) p, err := localbinary.NewPlugin(driverName)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -73,18 +73,18 @@ func NewRpcClientDriver(rawDriverData []byte, driverName string) (*RpcClientDriv
return nil, err return nil, err
} }
c := &RpcClientDriver{ c := &RPCClientDriver{
Client: NewInternalClient(rpcclient), Client: NewInternalClient(rpcclient),
heartbeatDoneCh: make(chan bool), heartbeatDoneCh: make(chan bool),
} }
go func(c *RpcClientDriver) { go func(c *RPCClientDriver) {
for { for {
select { select {
case <-c.heartbeatDoneCh: case <-c.heartbeatDoneCh:
return return
default: default:
if err := c.Client.Call("RpcServerDriver.Heartbeat", struct{}{}, nil); err != nil { if err := c.Client.Call("RPCServerDriver.Heartbeat", struct{}{}, nil); err != nil {
log.Warnf("Error attempting heartbeat call to plugin server: %s", err) log.Warnf("Error attempting heartbeat call to plugin server: %s", err)
c.Close() c.Close()
return return
@ -95,7 +95,7 @@ func NewRpcClientDriver(rawDriverData []byte, driverName string) (*RpcClientDriv
}(c) }(c)
var serverVersion int var serverVersion int
if err := c.Client.Call("RpcServerDriver.GetVersion", struct{}{}, &serverVersion); err != nil { if err := c.Client.Call("RPCServerDriver.GetVersion", struct{}{}, &serverVersion); err != nil {
return nil, err return nil, err
} }
@ -116,15 +116,15 @@ func NewRpcClientDriver(rawDriverData []byte, driverName string) (*RpcClientDriv
return c, nil return c, nil
} }
func (c *RpcClientDriver) MarshalJSON() ([]byte, error) { func (c *RPCClientDriver) MarshalJSON() ([]byte, error) {
return c.GetConfigRaw() return c.GetConfigRaw()
} }
func (c *RpcClientDriver) UnmarshalJSON(data []byte) error { func (c *RPCClientDriver) UnmarshalJSON(data []byte) error {
return c.SetConfigRaw(data) return c.SetConfigRaw(data)
} }
func (c *RpcClientDriver) Close() error { func (c *RPCClientDriver) Close() error {
c.heartbeatDoneCh <- true c.heartbeatDoneCh <- true
close(c.heartbeatDoneCh) close(c.heartbeatDoneCh)
@ -136,7 +136,7 @@ func (c *RpcClientDriver) Close() error {
log.Debug("Making call to close driver server") log.Debug("Making call to close driver server")
if err := c.Client.Call("RpcServerDriver.Close", struct{}{}, nil); err != nil { if err := c.Client.Call("RPCServerDriver.Close", struct{}{}, nil); err != nil {
return err return err
} }
@ -147,7 +147,7 @@ func (c *RpcClientDriver) Close() error {
// Helper method to make requests which take no arguments and return simply a // Helper method to make requests which take no arguments and return simply a
// string, e.g. "GetIP". // string, e.g. "GetIP".
func (c *RpcClientDriver) rpcStringCall(method string) (string, error) { func (c *RPCClientDriver) rpcStringCall(method string) (string, error) {
var info string var info string
if err := c.Client.Call(method, struct{}{}, &info); err != nil { if err := c.Client.Call(method, struct{}{}, &info); err != nil {
@ -157,32 +157,33 @@ func (c *RpcClientDriver) rpcStringCall(method string) (string, error) {
return info, nil return info, nil
} }
func (c *RpcClientDriver) GetCreateFlags() []mcnflag.Flag { func (c *RPCClientDriver) GetCreateFlags() []mcnflag.Flag {
var flags []mcnflag.Flag var flags []mcnflag.Flag
if err := c.Client.Call("RpcServerDriver.GetCreateFlags", struct{}{}, &flags); err != nil { if err := c.Client.Call("RPCServerDriver.GetCreateFlags", struct{}{}, &flags); err != nil {
log.Warnf("Error attempting call to get create flags: %s", err) log.Warnf("Error attempting call to get create flags: %s", err)
} }
return flags return flags
} }
func (c *RpcClientDriver) SetConfigRaw(data []byte) error { func (c *RPCClientDriver) SetConfigRaw(data []byte) error {
return c.Client.Call("RpcServerDriver.SetConfigRaw", data, nil) return c.Client.Call("RPCServerDriver.SetConfigRaw", data, nil)
} }
func (c *RpcClientDriver) GetConfigRaw() ([]byte, error) { func (c *RPCClientDriver) GetConfigRaw() ([]byte, error) {
var data []byte var data []byte
if err := c.Client.Call("RpcServerDriver.GetConfigRaw", struct{}{}, &data); err != nil { if err := c.Client.Call("RPCServerDriver.GetConfigRaw", struct{}{}, &data); err != nil {
return nil, err return nil, err
} }
return data, nil return data, nil
} }
func (c *RpcClientDriver) DriverName() string { // DriverName returns the name of the driver
driverName, err := c.rpcStringCall("RpcServerDriver.DriverName") func (c *RPCClientDriver) DriverName() string {
driverName, err := c.rpcStringCall("RPCServerDriver.DriverName")
if err != nil { if err != nil {
log.Warnf("Error attempting call to get driver name: %s", err) log.Warnf("Error attempting call to get driver name: %s", err)
} }
@ -190,16 +191,16 @@ func (c *RpcClientDriver) DriverName() string {
return driverName return driverName
} }
func (c *RpcClientDriver) SetConfigFromFlags(flags drivers.DriverOptions) error { func (c *RPCClientDriver) SetConfigFromFlags(flags drivers.DriverOptions) error {
return c.Client.Call("RpcServerDriver.SetConfigFromFlags", &flags, nil) return c.Client.Call("RPCServerDriver.SetConfigFromFlags", &flags, nil)
} }
func (c *RpcClientDriver) GetURL() (string, error) { func (c *RPCClientDriver) GetURL() (string, error) {
return c.rpcStringCall("RpcServerDriver.GetURL") return c.rpcStringCall("RPCServerDriver.GetURL")
} }
func (c *RpcClientDriver) GetMachineName() string { func (c *RPCClientDriver) GetMachineName() string {
name, err := c.rpcStringCall("RpcServerDriver.GetMachineName") name, err := c.rpcStringCall("RPCServerDriver.GetMachineName")
if err != nil { if err != nil {
log.Warnf("Error attempting call to get machine name: %s", err) log.Warnf("Error attempting call to get machine name: %s", err)
} }
@ -207,17 +208,18 @@ func (c *RpcClientDriver) GetMachineName() string {
return name return name
} }
func (c *RpcClientDriver) GetIP() (string, error) { func (c *RPCClientDriver) GetIP() (string, error) {
return c.rpcStringCall("RpcServerDriver.GetIP") return c.rpcStringCall("RPCServerDriver.GetIP")
} }
func (c *RpcClientDriver) GetSSHHostname() (string, error) { func (c *RPCClientDriver) GetSSHHostname() (string, error) {
return c.rpcStringCall("RpcServerDriver.GetSSHHostname") return c.rpcStringCall("RPCServerDriver.GetSSHHostname")
} }
// GetSSHKeyPath returns the key path
// TODO: This method doesn't even make sense to have with RPC. // TODO: This method doesn't even make sense to have with RPC.
func (c *RpcClientDriver) GetSSHKeyPath() string { func (c *RPCClientDriver) GetSSHKeyPath() string {
path, err := c.rpcStringCall("RpcServerDriver.GetSSHKeyPath") path, err := c.rpcStringCall("RPCServerDriver.GetSSHKeyPath")
if err != nil { if err != nil {
log.Warnf("Error attempting call to get SSH key path: %s", err) log.Warnf("Error attempting call to get SSH key path: %s", err)
} }
@ -225,18 +227,18 @@ func (c *RpcClientDriver) GetSSHKeyPath() string {
return path return path
} }
func (c *RpcClientDriver) GetSSHPort() (int, error) { func (c *RPCClientDriver) GetSSHPort() (int, error) {
var port int var port int
if err := c.Client.Call("RpcServerDriver.GetSSHPort", struct{}{}, &port); err != nil { if err := c.Client.Call("RPCServerDriver.GetSSHPort", struct{}{}, &port); err != nil {
return 0, err return 0, err
} }
return port, nil return port, nil
} }
func (c *RpcClientDriver) GetSSHUsername() string { func (c *RPCClientDriver) GetSSHUsername() string {
username, err := c.rpcStringCall("RpcServerDriver.GetSSHUsername") username, err := c.rpcStringCall("RPCServerDriver.GetSSHUsername")
if err != nil { if err != nil {
log.Warnf("Error attempting call to get SSH username: %s", err) log.Warnf("Error attempting call to get SSH username: %s", err)
} }
@ -244,56 +246,56 @@ func (c *RpcClientDriver) GetSSHUsername() string {
return username return username
} }
func (c *RpcClientDriver) GetState() (state.State, error) { func (c *RPCClientDriver) GetState() (state.State, error) {
var s state.State var s state.State
if err := c.Client.Call("RpcServerDriver.GetState", struct{}{}, &s); err != nil { if err := c.Client.Call("RPCServerDriver.GetState", struct{}{}, &s); err != nil {
return state.Error, err return state.Error, err
} }
return s, nil return s, nil
} }
func (c *RpcClientDriver) PreCreateCheck() error { func (c *RPCClientDriver) PreCreateCheck() error {
return c.Client.Call("RpcServerDriver.PreCreateCheck", struct{}{}, nil) return c.Client.Call("RPCServerDriver.PreCreateCheck", struct{}{}, nil)
} }
func (c *RpcClientDriver) Create() error { func (c *RPCClientDriver) Create() error {
return c.Client.Call("RpcServerDriver.Create", struct{}{}, nil) return c.Client.Call("RPCServerDriver.Create", struct{}{}, nil)
} }
func (c *RpcClientDriver) Remove() error { func (c *RPCClientDriver) Remove() error {
return c.Client.Call("RpcServerDriver.Remove", struct{}{}, nil) return c.Client.Call("RPCServerDriver.Remove", struct{}{}, nil)
} }
func (c *RpcClientDriver) Start() error { func (c *RPCClientDriver) Start() error {
return c.Client.Call("RpcServerDriver.Start", struct{}{}, nil) return c.Client.Call("RPCServerDriver.Start", struct{}{}, nil)
} }
func (c *RpcClientDriver) Stop() error { func (c *RPCClientDriver) Stop() error {
return c.Client.Call("RpcServerDriver.Stop", struct{}{}, nil) return c.Client.Call("RPCServerDriver.Stop", struct{}{}, nil)
} }
func (c *RpcClientDriver) Restart() error { func (c *RPCClientDriver) Restart() error {
return c.Client.Call("RpcServerDriver.Restart", struct{}{}, nil) return c.Client.Call("RPCServerDriver.Restart", struct{}{}, nil)
} }
func (c *RpcClientDriver) Kill() error { func (c *RPCClientDriver) Kill() error {
return c.Client.Call("RpcServerDriver.Kill", struct{}{}, nil) return c.Client.Call("RPCServerDriver.Kill", struct{}{}, nil)
} }
func (c *RpcClientDriver) LocalArtifactPath(file string) string { func (c *RPCClientDriver) LocalArtifactPath(file string) string {
var path string var path string
if err := c.Client.Call("RpcServerDriver.LocalArtifactPath", file, &path); err != nil { if err := c.Client.Call("RPCServerDriver.LocalArtifactPath", file, &path); err != nil {
log.Warnf("Error attempting call to get LocalArtifactPath: %s", err) log.Warnf("Error attempting call to get LocalArtifactPath: %s", err)
} }
return path return path
} }
func (c *RpcClientDriver) GlobalArtifactPath() string { func (c *RPCClientDriver) GlobalArtifactPath() string {
globalArtifactPath, err := c.rpcStringCall("RpcServerDriver.GlobalArtifactPath") globalArtifactPath, err := c.rpcStringCall("RPCServerDriver.GlobalArtifactPath")
if err != nil { if err != nil {
log.Warnf("Error attempting call to get GlobalArtifactPath: %s", err) log.Warnf("Error attempting call to get GlobalArtifactPath: %s", err)
} }
@ -301,6 +303,6 @@ func (c *RpcClientDriver) GlobalArtifactPath() string {
return globalArtifactPath return globalArtifactPath
} }
func (c *RpcClientDriver) Upgrade() error { func (c *RPCClientDriver) Upgrade() error {
return c.Client.Call("RpcServerDriver.Upgrade", struct{}{}, nil) return c.Client.Call("RPCServerDriver.Upgrade", struct{}{}, nil)
} }

View File

@ -12,18 +12,18 @@ import (
) )
func init() { func init() {
gob.Register(new(RpcFlags)) gob.Register(new(RPCFlags))
gob.Register(new(mcnflag.IntFlag)) gob.Register(new(mcnflag.IntFlag))
gob.Register(new(mcnflag.StringFlag)) gob.Register(new(mcnflag.StringFlag))
gob.Register(new(mcnflag.StringSliceFlag)) gob.Register(new(mcnflag.StringSliceFlag))
gob.Register(new(mcnflag.BoolFlag)) gob.Register(new(mcnflag.BoolFlag))
} }
type RpcFlags struct { type RPCFlags struct {
Values map[string]interface{} Values map[string]interface{}
} }
func (r RpcFlags) Get(key string) interface{} { func (r RPCFlags) Get(key string) interface{} {
val, ok := r.Values[key] val, ok := r.Values[key]
if !ok { if !ok {
log.Warnf("Trying to access option %s which does not exist", key) log.Warnf("Trying to access option %s which does not exist", key)
@ -32,7 +32,7 @@ func (r RpcFlags) Get(key string) interface{} {
return val return val
} }
func (r RpcFlags) String(key string) string { func (r RPCFlags) String(key string) string {
val, ok := r.Get(key).(string) val, ok := r.Get(key).(string)
if !ok { if !ok {
log.Warnf("Type assertion did not go smoothly to string for key %s", key) log.Warnf("Type assertion did not go smoothly to string for key %s", key)
@ -40,7 +40,7 @@ func (r RpcFlags) String(key string) string {
return val return val
} }
func (r RpcFlags) StringSlice(key string) []string { func (r RPCFlags) StringSlice(key string) []string {
val, ok := r.Get(key).([]string) val, ok := r.Get(key).([]string)
if !ok { if !ok {
log.Warnf("Type assertion did not go smoothly to string slice for key %s", key) log.Warnf("Type assertion did not go smoothly to string slice for key %s", key)
@ -48,7 +48,7 @@ func (r RpcFlags) StringSlice(key string) []string {
return val return val
} }
func (r RpcFlags) Int(key string) int { func (r RPCFlags) Int(key string) int {
val, ok := r.Get(key).(int) val, ok := r.Get(key).(int)
if !ok { if !ok {
log.Warnf("Type assertion did not go smoothly to int for key %s", key) log.Warnf("Type assertion did not go smoothly to int for key %s", key)
@ -56,7 +56,7 @@ func (r RpcFlags) Int(key string) int {
return val return val
} }
func (r RpcFlags) Bool(key string) bool { func (r RPCFlags) Bool(key string) bool {
val, ok := r.Get(key).(bool) val, ok := r.Get(key).(bool)
if !ok { if !ok {
log.Warnf("Type assertion did not go smoothly to bool for key %s", key) log.Warnf("Type assertion did not go smoothly to bool for key %s", key)
@ -64,31 +64,31 @@ func (r RpcFlags) Bool(key string) bool {
return val return val
} }
type RpcServerDriver struct { type RPCServerDriver struct {
ActualDriver drivers.Driver ActualDriver drivers.Driver
CloseCh chan bool CloseCh chan bool
HeartbeatCh chan bool HeartbeatCh chan bool
} }
func NewRpcServerDriver(d drivers.Driver) *RpcServerDriver { func NewRPCServerDriver(d drivers.Driver) *RPCServerDriver {
return &RpcServerDriver{ return &RPCServerDriver{
ActualDriver: d, ActualDriver: d,
CloseCh: make(chan bool), CloseCh: make(chan bool),
HeartbeatCh: make(chan bool), HeartbeatCh: make(chan bool),
} }
} }
func (r *RpcServerDriver) Close(_, _ *struct{}) error { func (r *RPCServerDriver) Close(_, _ *struct{}) error {
r.CloseCh <- true r.CloseCh <- true
return nil return nil
} }
func (r *RpcServerDriver) GetVersion(_ *struct{}, reply *int) error { func (r *RPCServerDriver) GetVersion(_ *struct{}, reply *int) error {
*reply = version.APIVersion *reply = version.APIVersion
return nil return nil
} }
func (r *RpcServerDriver) GetConfigRaw(_ *struct{}, reply *[]byte) error { func (r *RPCServerDriver) GetConfigRaw(_ *struct{}, reply *[]byte) error {
driverData, err := json.Marshal(r.ActualDriver) driverData, err := json.Marshal(r.ActualDriver)
if err != nil { if err != nil {
return err return err
@ -99,99 +99,99 @@ func (r *RpcServerDriver) GetConfigRaw(_ *struct{}, reply *[]byte) error {
return nil return nil
} }
func (r *RpcServerDriver) GetCreateFlags(_ *struct{}, reply *[]mcnflag.Flag) error { func (r *RPCServerDriver) GetCreateFlags(_ *struct{}, reply *[]mcnflag.Flag) error {
*reply = r.ActualDriver.GetCreateFlags() *reply = r.ActualDriver.GetCreateFlags()
return nil return nil
} }
func (r *RpcServerDriver) SetConfigRaw(data []byte, _ *struct{}) error { func (r *RPCServerDriver) SetConfigRaw(data []byte, _ *struct{}) error {
return json.Unmarshal(data, &r.ActualDriver) return json.Unmarshal(data, &r.ActualDriver)
} }
func (r *RpcServerDriver) Create(_, _ *struct{}) error { func (r *RPCServerDriver) Create(_, _ *struct{}) error {
return r.ActualDriver.Create() return r.ActualDriver.Create()
} }
func (r *RpcServerDriver) DriverName(_ *struct{}, reply *string) error { func (r *RPCServerDriver) DriverName(_ *struct{}, reply *string) error {
*reply = r.ActualDriver.DriverName() *reply = r.ActualDriver.DriverName()
return nil return nil
} }
func (r *RpcServerDriver) GetIP(_ *struct{}, reply *string) error { func (r *RPCServerDriver) GetIP(_ *struct{}, reply *string) error {
ip, err := r.ActualDriver.GetIP() ip, err := r.ActualDriver.GetIP()
*reply = ip *reply = ip
return err return err
} }
func (r *RpcServerDriver) GetMachineName(_ *struct{}, reply *string) error { func (r *RPCServerDriver) GetMachineName(_ *struct{}, reply *string) error {
*reply = r.ActualDriver.GetMachineName() *reply = r.ActualDriver.GetMachineName()
return nil return nil
} }
func (r *RpcServerDriver) GetSSHHostname(_ *struct{}, reply *string) error { func (r *RPCServerDriver) GetSSHHostname(_ *struct{}, reply *string) error {
hostname, err := r.ActualDriver.GetSSHHostname() hostname, err := r.ActualDriver.GetSSHHostname()
*reply = hostname *reply = hostname
return err return err
} }
func (r *RpcServerDriver) GetSSHKeyPath(_ *struct{}, reply *string) error { func (r *RPCServerDriver) GetSSHKeyPath(_ *struct{}, reply *string) error {
*reply = r.ActualDriver.GetSSHKeyPath() *reply = r.ActualDriver.GetSSHKeyPath()
return nil return nil
} }
// GetSSHPort returns port for use with ssh // GetSSHPort returns port for use with ssh
func (r *RpcServerDriver) GetSSHPort(_ *struct{}, reply *int) error { func (r *RPCServerDriver) GetSSHPort(_ *struct{}, reply *int) error {
port, err := r.ActualDriver.GetSSHPort() port, err := r.ActualDriver.GetSSHPort()
*reply = port *reply = port
return err return err
} }
func (r *RpcServerDriver) GetSSHUsername(_ *struct{}, reply *string) error { func (r *RPCServerDriver) GetSSHUsername(_ *struct{}, reply *string) error {
*reply = r.ActualDriver.GetSSHUsername() *reply = r.ActualDriver.GetSSHUsername()
return nil return nil
} }
func (r *RpcServerDriver) GetURL(_ *struct{}, reply *string) error { func (r *RPCServerDriver) GetURL(_ *struct{}, reply *string) error {
info, err := r.ActualDriver.GetURL() info, err := r.ActualDriver.GetURL()
*reply = info *reply = info
return err return err
} }
func (r *RpcServerDriver) GetState(_ *struct{}, reply *state.State) error { func (r *RPCServerDriver) GetState(_ *struct{}, reply *state.State) error {
s, err := r.ActualDriver.GetState() s, err := r.ActualDriver.GetState()
*reply = s *reply = s
return err return err
} }
func (r *RpcServerDriver) Kill(_ *struct{}, _ *struct{}) error { func (r *RPCServerDriver) Kill(_ *struct{}, _ *struct{}) error {
return r.ActualDriver.Kill() return r.ActualDriver.Kill()
} }
func (r *RpcServerDriver) PreCreateCheck(_ *struct{}, _ *struct{}) error { func (r *RPCServerDriver) PreCreateCheck(_ *struct{}, _ *struct{}) error {
return r.ActualDriver.PreCreateCheck() return r.ActualDriver.PreCreateCheck()
} }
func (r *RpcServerDriver) Remove(_ *struct{}, _ *struct{}) error { func (r *RPCServerDriver) Remove(_ *struct{}, _ *struct{}) error {
return r.ActualDriver.Remove() return r.ActualDriver.Remove()
} }
func (r *RpcServerDriver) Restart(_ *struct{}, _ *struct{}) error { func (r *RPCServerDriver) Restart(_ *struct{}, _ *struct{}) error {
return r.ActualDriver.Restart() return r.ActualDriver.Restart()
} }
func (r *RpcServerDriver) SetConfigFromFlags(flags *drivers.DriverOptions, _ *struct{}) error { func (r *RPCServerDriver) SetConfigFromFlags(flags *drivers.DriverOptions, _ *struct{}) error {
return r.ActualDriver.SetConfigFromFlags(*flags) return r.ActualDriver.SetConfigFromFlags(*flags)
} }
func (r *RpcServerDriver) Start(_ *struct{}, _ *struct{}) error { func (r *RPCServerDriver) Start(_ *struct{}, _ *struct{}) error {
return r.ActualDriver.Start() return r.ActualDriver.Start()
} }
func (r *RpcServerDriver) Stop(_ *struct{}, _ *struct{}) error { func (r *RPCServerDriver) Stop(_ *struct{}, _ *struct{}) error {
return r.ActualDriver.Stop() return r.ActualDriver.Stop()
} }
func (r *RpcServerDriver) Heartbeat(_ *struct{}, _ *struct{}) error { func (r *RPCServerDriver) Heartbeat(_ *struct{}, _ *struct{}) error {
r.HeartbeatCh <- true r.HeartbeatCh <- true
return nil return nil
} }

View File

@ -9,11 +9,11 @@ import (
var stdLock = &sync.Mutex{} var stdLock = &sync.Mutex{}
// SerialDriver is a wrapper struct which is used to ensure that RPC calls
// to a driver only occur one at a time.
// Some providers, e.g. virtualbox, should not run driver operations at the // Some providers, e.g. virtualbox, should not run driver operations at the
// same time as other driver instances of the same type. Otherwise, we scrape // same time as other driver instances of the same type. Otherwise, we scrape
// up against VirtualBox's own locking mechanisms. Therefore this is a wrapper // up against VirtualBox's own locking mechanisms.
// struct which is used to ensure that RPC calls to these drivers only occur
// one at a time.
// //
// It would be preferable to simply have a lock around, say, the VBoxManage // It would be preferable to simply have a lock around, say, the VBoxManage
// command, but with our current one-server-process-per-machine model it is // command, but with our current one-server-process-per-machine model it is

View File

@ -45,7 +45,7 @@ func (s Filestore) Save(host *host.Host) error {
} }
// TODO: Does this belong here? // TODO: Does this belong here?
if rpcClientDriver, ok := host.Driver.(*rpcdriver.RpcClientDriver); ok { if rpcClientDriver, ok := host.Driver.(*rpcdriver.RPCClientDriver); ok {
data, err := rpcClientDriver.GetConfigRaw() data, err := rpcClientDriver.GetConfigRaw()
if err != nil { if err != nil {
return fmt.Errorf("Error getting raw config for driver: %s", err) return fmt.Errorf("Error getting raw config for driver: %s", err)

View File

@ -20,4 +20,4 @@ vet: build
lint: lint:
$(if $(GOLINT), , \ $(if $(GOLINT), , \
$(error Please install golint: go get -u github.com/golang/lint/golint)) $(error Please install golint: go get -u github.com/golang/lint/golint))
@test -z "$$($(GOLINT) ./... 2>&1 | grep -v vendor/ | grep -v drivers/ | grep -v cli/ | grep -v "should have comment" | tee /dev/stderr)" @test -z "$$($(GOLINT) ./... 2>&1 | grep -v vendor/ | grep -v "cli/" | grep -v "amazonec2/" |grep -v "openstack/" |grep -v "softlayer/" | grep -v "should have comment" | tee /dev/stderr)"