Skip to content

Commit

Permalink
minor fixes in README and logging
Browse files Browse the repository at this point in the history
fix:
 Huawei#14
 Huawei#11
 Huawei#8

Signed-off-by: dengguangxing <[email protected]>
  • Loading branch information
dengguangxing committed Jun 4, 2018
1 parent 523e7e2 commit ddaa9b5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 54 deletions.
69 changes: 33 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,50 +30,46 @@ Option Name | Description
------------------------------------------------------|----------------------------------------------------|----|
``--otc-access-key-id`` | Your access key ID. |**yes**|
``--otc-access-key-secret``|Your secret access key.| **yes** |
``--otc-api-endpoint``|The custom API endpoint.| |
``--otc-description`` | The description of instance.| |
``-otcs-disk-size``| The data disk size for /var/lib/docker (in GB)||
``-otcs-disk-category``|The category of data disk, the valid values could be `cloud` (default), `cloud_efficiency` or `cloud_ssd`.||
``--otc-service-endpoint``|The custom API endpoint.| |
``--otc-image-id``| The image ID of the instance to use, default is the Ubuntu server 14.04 64bits provided by system||
``--otc-io-optimized``| The I/O optimized instance type, the valid values could be `none` (default) or `optimized`||
``--otc-instance-type``| The instance type to run. Default: `ecs.t1.small`||
``--otc-internet-max-bandwidth``| Maxium bandwidth for Internet access (in Mbps), default 1||
``--otc-private-address-only``| Use the private IP address only||
``--otc-region``| The region to use when launching the instance. Default: `cn-hangzhou`||
``--otc-route-cidr``| The CIDR to use configure the route entry for the instance in VPC. Sample: 192.168.200.0/24||
``--otc-region``| The region to use when launching the instance||
``--otc-security-group``| Security group name. Default: `docker-machine`||
``--otc-slb-id``|SLB id for instance association||
``--otc-ssh-password``| SSH password for created virtual machine. Default is random generated.||
``--otc-system-disk-category``|System disk category for instance||
``--otc-tag``| Tag for the instance.||
``--otc-admin-password``| Admin password for created virtual machine. Default is random generated.||
``--otc-vpc-id``| Your VPC ID to launch the instance in. (required for VPC network only)||
``--otc-vswitch-id``| Your VSwitch ID to launch the instance with. (required for VPC network only)||
``--otc-available-zone``| The availabilty zone to launch the instance||
``--otc-bandwidth-size``|Bandwidth Size for Elastic IP||
``--otc-bandwidth-type``|Bandwidth Type for Elastic IP||
``--otc-elasticip-type``|Your Elastic IP Type||
``--otc-flavor-id``|Flavor for you instance||
``--otc-root-volume-size``|Root Volume Size for your instance||
``--otc-root-volume-type``|Root Volume type for your instance||
``--otc-ssh-user``|Instance's optional ssh user||
``--otc-subnet-id``|Subnet ID for your instance private network||
``--otc-tenant-id``|Tenant ID||


## Environment variables and default values:

| CLI option | Environment variable | Default |
|-------------------------------------|-----------------------------|------------------|
| **`--otc-access-key-id`** | `ACCESS_KEY_ID` | - |
| **`--otc-access-key-key`** | `ACCESS_KEY_SECRET` | - |
| `--otc-api-endpoint` | `API_ENDPOINT` | - |
| `--otc-description` | `DESCRIPTION` | - |
| `--otc-disk-size` | `DISK_SIZE` | - |
| `--otc-disk-category` | `DISK_CATEGORY` | - |
| `--otc-image-id` | `IMAGE_ID` | - |
| `--otc-aliyunecs-io-optimized`| `IO_OPTIMIZED` | `none` |
| `--otc-instance-type` | `INSTANCE_TYPE` | `ecs.t1.small` |
| `--otc-internet-max-bandwidth`| `INTERNET_MAX_BANDWIDTH`| `1` |
| `--otc-private-address-only` | `PRIVATE_ADDR_ONLY` | `false` |
| `--otc-region` | `REGION` | `cn-hangzhou` |
| `--otc-route-cidr` | `ROUTE_CIDR` | - |
| `--otc-security-group` | `SECURITY_GROUP` | - |
| `--otc-slb-id` | `SLB_ID` | - |
| `--otc-ssh-password` | `SSH_PASSWORD` | Random generated |
| `--otc-tag` | `TAGS` | - |
| `--otc-vpc-id` | `VPC_ID` | - |
| `--otc-vswitch-id` | `VSWITCH_ID` | - |
| `--otc-available-zone` | `ZONE` | - |
| **`--otc-access-key-id`** | `ACCESS_KEY_ID` | - |
| **`--otc-access-key-key`** | `ACCESS_KEY_SECRET` | - |
| `--otc-admin-password` | `ADMIN_PWD` | - |
| `--otc-available-zone` | `AVAILABLE_ZONE` | - |
| `--otc-service-endpoint` | `SERVICE_ENDPOINT` | - |
| `--otc-image-id` | `IMAGE_ID` | - |
| `--otc-region` | `REGION` | - |
| `--otc-security-group` | `SECURITY_GROUP` | - |
| `--otc-vpc-id` | `VPC_ID` | - |
| `--otc-bandwidth-size` | `BANDWIDTH_SIZE` | `10` |
| `--otc-bandwidth-type` | `BANDWIDTH_TYPE` | `PER` |
| `--otc-elasticip-type` | `ELASTICIP_TYPE` | `5_bgp` |
| `--otc-flavor-id` | `FLAVOR_ID` | - |
| `--otc-root-volume-size` | `ROOT_VOLUME_SIZE` | `40` |
| `--otc-root-volume-type` | `ROOT_VOLUME_TYPE` | `SATA` |
| `--otc-ssh-user` | `SSH_USER` | - |
| `--otc-subnet-id` | `SUBNET_ID` | - |
| `--otc-tenant-id` | `TENANT_ID` | - |

Each environment variable may be overloaded by its option equivalent at runtime.

Expand All @@ -99,5 +95,6 @@ export PATH=$GOPATH/src/github.com/huawei/DockerMachineDriver4OTC:$PATH
Apache 2.0

## test command
./bin/docker-machine -D create -d otc --otc-access-key-id=DFNQWPE4JSXA6BQEOEBY --otc-access-key-secret=1DUumFBPMcE5AIcO6olMNvjmaOA76k0MLTAOfAyM --otc-security-group=default --otc-tenant-id=15eae18081ba40fabd76979bdbf35d0e --otc-region=southchina --otc-vpc-id=ecbd1d70-8c7e-4bdf-bb2c-b3e2b7f7e15b --otc-flavor-id=103 --otc-image-id=627a1223-2ca3-46a7-8d5f-7aef22c74ee6 --otc-subnet-id=a81eee33-c0c3-445f-988a-248ee426fd8d test
docker-machine -D create -d otc --otc-access-key-id BCE_shortened --otc-access-key-secret 4UR_shortened --otc-available-zone eu-de-01 --otc-bandwidth-size 10 --otc-bandwidth-type PER --otc-elasticip-type 5_bgp --otc-flavor-id normal1 --otc-image-id d6944a41-5ec7-44a4-970e-ce330da390d2 --otc-region eu-de --otc-root-volume-size 40 --otc-root-volume-type SATA --otc-security-group sg-tino --otc-service-endpoint https://ecs.eu-de.otc.t-systems.com --otc-ssh-user ubuntu --otc-subnet-id 91e2f28b-50dc-4a2d-b856-39d9204323e2 --otc-tenant-id 16d53a84a13b49529d2e2c3646691288 --otc-vpc-id 9d5c46ec-b3f0-42a2-9a65-f2d77e124516 test

**parameters may vary on different cloud platforms**
12 changes: 8 additions & 4 deletions com/client/ecsClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package client

import (
"encoding/json"
"github.com/docker/machine/libmachine/log"
"github.com/huawei/DockerMachineDriver4OTC/com/cpp_sdk_core"
"github.com/huawei/DockerMachineDriver4OTC/com/modules"
"github.com/huawei/DockerMachineDriver4OTC/com/modules/ecsModules"
Expand All @@ -25,7 +26,7 @@ import (
func (client *Client) CreateCloudServer(createCloudServerReq ecsModules.CreateCloudServerReq) ecsModules.CreateCloudServerResp {
createCloudServerResp := ecsModules.CreateCloudServerResp{}

client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v1/" + client.TenantID + "/cloudservers"
client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v1/" + client.TenantID + "/cloudservers"
client.RequestParam.Method = modules.HTTP_POST
client.RequestParam.RequestContentType = modules.ApplicationJson
client.RequestParam.BodyContent = createCloudServerReq.GetBodyContent()
Expand All @@ -37,6 +38,7 @@ func (client *Client) CreateCloudServer(createCloudServerReq ecsModules.CreateCl
json.Unmarshal([]byte(Result.RespMessage), &createCloudServerResp)
} else {
createCloudServerResp.ResponseCode = Result.ResponseCode
log.Errorf("CreateCloudServer failed with: %s", Result.RespMessage)
var Error modules.ErrorInfo
json.Unmarshal([]byte(Result.RespMessage), &Error)
createCloudServerResp.ErrorInfo = Error
Expand All @@ -48,7 +50,7 @@ func (client *Client) CreateCloudServer(createCloudServerReq ecsModules.CreateCl
func (client *Client) DeleteCloudServer(deleteCloudServerReq ecsModules.DeleteCloudServerReq) ecsModules.DeleteCloudServerResp {
deleteCloudServerResp := ecsModules.DeleteCloudServerResp{}

client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v1/" + client.TenantID + "/cloudservers/delete"
client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v1/" + client.TenantID + "/cloudservers/delete"
client.RequestParam.Method = modules.HTTP_POST
client.RequestParam.RequestContentType = modules.ApplicationJson
client.RequestParam.BodyContent = deleteCloudServerReq.GetBodyContent()
Expand All @@ -71,7 +73,7 @@ func (client *Client) DeleteCloudServer(deleteCloudServerReq ecsModules.DeleteCl
func (client *Client) ShowEcsJob(job_id string) ecsModules.ShowEcsJobResp {
showEcsJobResp := ecsModules.ShowEcsJobResp{}

client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v1/" + client.TenantID + "/jobs/" + job_id
client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v1/" + client.TenantID + "/jobs/" + job_id
client.RequestParam.Method = modules.HTTP_GET
client.RequestParam.RequestContentType = modules.ApplicationJson
client.RequestParam.BodyContent = ""
Expand All @@ -81,11 +83,13 @@ func (client *Client) ShowEcsJob(job_id string) ecsModules.ShowEcsJobResp {
if modules.IsHttpOk(Result.ResponseCode) {
showEcsJobResp.ResponseCode = modules.HttpOK
json.Unmarshal([]byte(Result.RespMessage), &showEcsJobResp)
log.Debugf("get ECS job status: %v", Result.RespMessage)
} else {
showEcsJobResp.ResponseCode = Result.ResponseCode
var Error modules.ErrorInfo
json.Unmarshal([]byte(Result.RespMessage), &Error)
showEcsJobResp.ErrorInfo = Error
log.Debugf("get ECS job status failed: %v", Result.RespMessage)
}

return showEcsJobResp
Expand All @@ -94,7 +98,7 @@ func (client *Client) ShowEcsJob(job_id string) ecsModules.ShowEcsJobResp {
func (client *Client) ListCloudServerFlavorsExt() ecsModules.ListCloudServerFlavorsExtResp {
listCloudServerFlavorsExtResp := ecsModules.ListCloudServerFlavorsExtResp{}

client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v1/" + client.TenantID + "/cloudservers/flavors"
client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v1/" + client.TenantID + "/cloudservers/flavors"
client.RequestParam.Method = modules.HTTP_GET
client.RequestParam.RequestContentType = modules.ApplicationJson
client.RequestParam.BodyContent = ""
Expand Down
16 changes: 8 additions & 8 deletions com/client/novaClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
func (client *Client) ListInterfaces(server_id string) novaModules.ListInterfacesResp {
listInterfacesResp := novaModules.ListInterfacesResp{}

client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/servers/" + server_id + "/os-interface"
client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/servers/" + server_id + "/os-interface"
client.RequestParam.Method = modules.HTTP_GET
client.RequestParam.RequestContentType = modules.ApplicationJson
client.RequestParam.BodyContent = ""
Expand All @@ -49,7 +49,7 @@ func (client *Client) ListInterfaces(server_id string) novaModules.ListInterface
func (client *Client) CreateKeypair(createKeypairReq novaModules.CreateKeypairReq) novaModules.CreateKeypairResp {
createKeypairResp := novaModules.CreateKeypairResp{}

client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/os-keypairs"
client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/os-keypairs"
client.RequestParam.Method = modules.HTTP_POST
client.RequestParam.RequestContentType = modules.ApplicationJson
client.RequestParam.BodyContent = createKeypairReq.GetBodyContent()
Expand All @@ -72,7 +72,7 @@ func (client *Client) CreateKeypair(createKeypairReq novaModules.CreateKeypairRe
func (client *Client) DeleteKeyPair(keypair_name string) novaModules.DeleteKeyPairResp {
deleteKeyPairResp := novaModules.DeleteKeyPairResp{}

client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/os-keypairs/" + keypair_name
client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/os-keypairs/" + keypair_name
client.RequestParam.Method = modules.HTTP_DELETE
client.RequestParam.RequestContentType = modules.ApplicationJson
client.RequestParam.BodyContent = ""
Expand All @@ -94,7 +94,7 @@ func (client *Client) DeleteKeyPair(keypair_name string) novaModules.DeleteKeyPa
func (client *Client) StartServer(server_id string) novaModules.StartServerResp {
startServer := novaModules.StartServerResp{}

client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/servers/" + server_id + "/action"
client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/servers/" + server_id + "/action"
client.RequestParam.Method = modules.HTTP_POST
client.RequestParam.RequestContentType = modules.ApplicationJson
client.RequestParam.BodyContent = "{ \"os-start\": {} }"
Expand All @@ -116,7 +116,7 @@ func (client *Client) StartServer(server_id string) novaModules.StartServerResp
func (client *Client) StopServer(server_id string) novaModules.StopServerResp {
stopServer := novaModules.StopServerResp{}

client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/servers/" + server_id + "/action"
client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/servers/" + server_id + "/action"
client.RequestParam.Method = modules.HTTP_POST
client.RequestParam.RequestContentType = modules.ApplicationJson
client.RequestParam.BodyContent = "{ \"os-stop\": {} }"
Expand All @@ -138,7 +138,7 @@ func (client *Client) StopServer(server_id string) novaModules.StopServerResp {
func (client *Client) RebootServer(server_id, rebootType string) novaModules.RebootServerResp {
rebootServer := novaModules.RebootServerResp{}

client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/servers/" + server_id + "/action"
client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/servers/" + server_id + "/action"
client.RequestParam.Method = modules.HTTP_POST
client.RequestParam.RequestContentType = modules.ApplicationJson
bodyMap := make(map[string]map[string]string)
Expand Down Expand Up @@ -166,7 +166,7 @@ func (client *Client) RebootServer(server_id, rebootType string) novaModules.Reb
func (client *Client) DeleteAnServer(server_id string) novaModules.DeleteAnServerResp {
deleteAnServerResp := novaModules.DeleteAnServerResp{}

client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/servers/" + server_id
client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/servers/" + server_id
client.RequestParam.Method = modules.HTTP_DELETE
client.RequestParam.RequestContentType = modules.ApplicationJson
client.RequestParam.BodyContent = ""
Expand All @@ -192,7 +192,7 @@ func (client *Client) ShowServer(server_id string) novaModules.ShowServerResp {
showServerResp.Server.NumaOpts = -1
showServerResp.Server.Progress = -1

client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/servers/" + server_id
client.RequestParam.Url = "https://ecs." + client.RequestParam.Endpoint + "/v2/" + client.TenantID + "/servers/" + server_id
client.RequestParam.Method = modules.HTTP_GET
client.RequestParam.RequestContentType = modules.ApplicationJson
client.RequestParam.BodyContent = ""
Expand Down
25 changes: 19 additions & 6 deletions otc/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type Driver struct {
/*ecsclient *ecs.Client
imsclient *ims.Client
vpcclient *vpc.Client*/
PrivateIPAddress string
}

func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Expand Down Expand Up @@ -339,7 +340,7 @@ func (d *Driver) Create() error {
if deleteKeyPairResp.ResponseCode != modules.HttpOK {
return fmt.Errorf("%s | Failed to delete key pair %s: %v", d.MachineName, d.InstanceId, deleteKeyPairResp.ErrorInfo.Description)
}
return fmt.Errorf("%s | Failed to crate instance: %v", d.MachineName, err)
return fmt.Errorf("%s | Failed to create instance: %v, response code is %d", d.MachineName, err, createResp.ResponseCode)
}
d.JobId = createResp.Job_id
log.Infof("%s | job for creating instance: %s and reponse code: %d and err: %v", d.MachineName, d.JobId, createResp.ResponseCode, createResp.ErrorInfo)
Expand Down Expand Up @@ -412,6 +413,17 @@ func (d *Driver) GetState() (state.State, error) {
return state.None, err
}

// FIXME: PrivateIPAddress is not stored to config.json for now
// because docker-machine did not get any update from drivers
for _, paddrs := range stateResp.Server.Addresses {
for _, paddr := range paddrs {
if paddr.Addr != "" {
split := strings.Split(paddr.Addr, " ")
d.PrivateIPAddress = split[0]
}
}
}

switch stateResp.Server.Status {
case "ACTIVE":
return state.Running, nil
Expand All @@ -420,6 +432,7 @@ func (d *Driver) GetState() (state.State, error) {
case "ERROR":
return state.Error, nil
}

return state.None, nil
}

Expand Down Expand Up @@ -465,7 +478,7 @@ func (d *Driver) Remove() error {
}

if d.KeyName != "" {
log.Infof("%s | Removing instance key pair(%s)...", d.MachineName,d.KeyName)
log.Infof("%s | Removing instance key pair(%s)...", d.MachineName, d.KeyName)
pClient = d.initClient()
deleteKeyPairResp := pClient.DeleteKeyPair(d.KeyName)
if deleteKeyPairResp.ResponseCode != modules.HttpOK {
Expand Down Expand Up @@ -506,8 +519,8 @@ func (d *Driver) instanceKeyPairCreate() error {
log.Debugf("%s | Success to create key pair: %s", d.MachineName, kp.Keypair.Name)
d.KeyName = kp.Keypair.Name
return nil
} else if kp.ResponseCode == 409 {
return fmt.Errorf("Keypair(%s) existed, please removev it from the console, err %v", d.MachineName, kp.ErrorInfo)
} else if kp.ResponseCode == 409 {
return fmt.Errorf("Keypair(%s) existed, please remove it from the console, err %v", d.MachineName, kp.ErrorInfo)
} else {
return fmt.Errorf("unknown error, status code: %d, err: %v", kp.ResponseCode, kp.ErrorInfo)
}
Expand Down Expand Up @@ -577,7 +590,7 @@ func (d *Driver) checkJobStatus(jobid string) error {

for {
ecsJobStatusResp := pClient.ShowEcsJob(jobid)
if len( ecsJobStatusResp.Entities.SubJobs) > 0 {
if len(ecsJobStatusResp.Entities.SubJobs) > 0 {
d.InstanceId = ecsJobStatusResp.Entities.SubJobs[0].Entities.Server_id
}

Expand Down Expand Up @@ -657,7 +670,7 @@ func (d *Driver) configureSubnet(subnetId string) error {
pClient := d.initClient()

subnetList := pClient.ListSubnets(subnetListNumPerPage, "", d.VpcId)
log.Debugf("subnets:%v response code:%s error infor:%v", subnetList.Subnets, subnetList.ResponseCode, subnetList.ErrorInfo)
log.Debugf("subnets:%v response code:%d error info:%v", subnetList.Subnets, subnetList.ResponseCode, subnetList.ErrorInfo)

for _, subnet := range subnetList.Subnets {
if subnetId == subnet.Id {
Expand Down

0 comments on commit ddaa9b5

Please sign in to comment.