func (provisioner *RedHatProvisioner) dockerDaemonResponding() bool { if _, err := provisioner.SSHCommand("sudo docker version"); err != nil { log.Warn("Error getting SSH command to check if the daemon is up: %s", err) return false } // The daemon is up if the command worked. Carry on. return true }
func matchesState(host *libmachine.Host, states []string) bool { if len(states) == 0 { return true } for _, n := range states { s, err := host.Driver.GetState() if err != nil { log.Warn(err) } if n == s.String() { return true } } return false }
func (osr *OsRelease) ParseOsRelease(osReleaseContents []byte) error { r := bytes.NewReader(osReleaseContents) scanner := bufio.NewScanner(r) for scanner.Scan() { key, val, err := parseLine(scanner.Text()) if err != nil { log.Warn("Warning: got an invalid line error parsing /etc/os-release: %s", err) continue } if err := osr.setIfPossible(key, val); err != nil { log.Debug(err) } } return nil }
func (d *Driver) Remove() error { log.Info("Deleting...") if d.InstanceId == "" { // Instance id is empty due to some errors while creating, log.Warn("InstanceId is empty, assuming it has already bean removed from aliyun.") return nil } // If instance is running, kill it if st, _ := d.GetState(); st == state.Running { err := d.Kill() if err != nil { return err } } // Wait for instance to stop utils.WaitForSpecific(d.waitToStopInstance, 10, 6*time.Second) _, err := d.getClient().Instance.DeleteInstance(map[string]string{ "InstanceId": d.InstanceId, }) return err }
func (d *Driver) Create() error { if err := d.checkPrereqs(); err != nil { return err } log.Infof("Creating key pair for instances...") if err := d.createKeyPair(); err != nil { return fmt.Errorf("unable to create key pair: %s", err) } log.Infof("Configuring security groups...") if err := d.configureSecurityGroup(d.SecurityGroupName); err != nil { return err } // TODO Support data disk if d.SSHPassword == "" { d.SSHPassword = randomPassword() log.Info("Launching instance with generated password, please update password in console or log in with ssh key.") } imageID := d.GetImageID(d.ImageID) log.Infof("Launching instance with image %s ...", imageID) args := ecs.CreateInstanceArgs{ RegionId: d.Region, ImageId: imageID, InstanceType: d.InstanceType, SecurityGroupId: d.SecurityGroupId, Password: d.SSHPassword, VSwitchId: d.VSwitchId, ClientToken: d.getClient().GenerateClientToken(), } // Set InternetMaxBandwidthOut only for classic network if d.VSwitchId == "" { args.InternetMaxBandwidthOut = d.InternetMaxBandwidthOut } //log.Debugf("CreateInstanceArgs: %++v", args) // Create instance instanceId, err := d.getClient().CreateInstance(&args) if err != nil { err = fmt.Errorf("Error create instance: %s", err) log.Error(err) return err } d.InstanceId = instanceId // Wait for creation successfully err = d.getClient().WaitForInstance(instanceId, ecs.Stopped, 300) if err != nil { err = fmt.Errorf("Error wait instance to Stopped: %s", err) log.Error(err) } // Assign public IP if not private IP only if err == nil && !d.PrivateIPOnly { if d.VSwitchId == "" { // Allocate public IP address for classic network _, err = d.getClient().AllocatePublicIpAddress(instanceId) if err != nil { err = fmt.Errorf("Error allocate public IP address for instance %s: %v", instanceId, err) } } else { err = d.configNetwork(instanceId) } } if err == nil { // Start instance err = d.getClient().StartInstance(instanceId) if err == nil { // Wait for running err = d.getClient().WaitForInstance(instanceId, ecs.Running, 300) if err == nil { instance, err := d.getInstance() if err == nil { if len(instance.InnerIpAddress.IpAddress) > 0 { d.PrivateIPAddress = instance.InnerIpAddress.IpAddress[0] } d.IPAddress = d.getIP(instance) ssh.SetDefaultClient(ssh.Native) d.uploadKeyPair() log.Debugf("created instance ID %s, IP address %s, Private IP address %s", d.InstanceId, d.IPAddress, d.PrivateIPAddress, ) } } else { err = fmt.Errorf("Failed to wait instance to running state: %s", err) } } else { err = fmt.Errorf("Failed to start instance %s: %v", instanceId, err) } } if err != nil { log.Warn(err) d.Remove() } return err }