func (d *Driver) waitForVM(client *egoscale.Client, jobid string) (*egoscale.DeployVirtualMachineResponse, error) { if err := d.waitForJob(client, jobid); err != nil { return nil, err } resp, err := client.PollAsyncJob(jobid) if err != nil { return nil, err } vm, err := client.AsyncToVirtualMachine(*resp) if err != nil { return nil, err } return vm, nil }
func (d *Driver) jobIsDone(client *egoscale.Client, jobid string) (bool, error) { resp, err := client.PollAsyncJob(jobid) if err != nil { return true, err } switch resp.Jobstatus { case 0: // Job is still in progress case 1: // Job has successfully completed return true, nil case 2: // Job has failed to complete return true, fmt.Errorf("Operation failed to complete") default: // Some other code } return false, nil }
func (d *Driver) createDefaultSecurityGroup(client *egoscale.Client, group string) (string, error) { rules := []egoscale.SecurityGroupRule{ { SecurityGroupId: "", Cidr: "0.0.0.0/0", Protocol: "TCP", Port: 22, }, { SecurityGroupId: "", Cidr: "0.0.0.0/0", Protocol: "TCP", Port: 2376, }, { SecurityGroupId: "", Cidr: "0.0.0.0/0", Protocol: "TCP", Port: 3376, }, { SecurityGroupId: "", Cidr: "0.0.0.0/0", Protocol: "ICMP", IcmpType: 8, IcmpCode: 0, }, } sgresp, err := client.CreateSecurityGroupWithRules( group, rules, make([]egoscale.SecurityGroupRule, 0, 0)) if err != nil { return "", err } sg := sgresp.Id return sg, nil }
func (d *Driver) createDefaultAffinityGroup(client *egoscale.Client, group string) (string, error) { jobid, err := client.CreateAffinityGroup(group) if err != nil { return "", err } var resp *egoscale.QueryAsyncJobResultResponse for i := 0; i <= 10; i++ { resp, err = client.PollAsyncJob(jobid) if err != nil { fmt.Printf("got error: %+v\n", err) } if resp.Jobstatus == 1 { break } time.Sleep(5 * time.Second) } affinitygroups, err := client.GetAffinityGroups() agid := affinitygroups[group] return agid, nil }