本文整理汇总了Golang中github.com/docker/machine/libmachine/mcnutils.WaitFor函数的典型用法代码示例。如果您正苦于以下问题:Golang WaitFor函数的具体用法?Golang WaitFor怎么用?Golang WaitFor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WaitFor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: upgradeIso
func (provisioner *Boot2DockerProvisioner) upgradeIso() error {
// TODO: Ideally, we should not read from mcndirs directory at all.
// The driver should be able to communicate how and where to place the
// relevant files.
b2dutils := mcnutils.NewB2dUtils(mcndirs.GetBaseDir())
// Check if the driver has specified a custom b2d url
jsonDriver, err := json.Marshal(provisioner.GetDriver())
if err != nil {
return err
}
var d struct {
Boot2DockerURL string
}
json.Unmarshal(jsonDriver, &d)
log.Info("Downloading latest boot2docker iso...")
// Usually we call this implicitly, but call it here explicitly to get
// the latest default boot2docker ISO.
if d.Boot2DockerURL == "" {
if err := b2dutils.DownloadLatestBoot2Docker(d.Boot2DockerURL); err != nil {
return err
}
}
log.Info("Stopping machine to do the upgrade...")
if err := provisioner.Driver.Stop(); err != nil {
return err
}
if err := mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil {
return err
}
machineName := provisioner.GetDriver().GetMachineName()
log.Infof("Upgrading machine %q...", machineName)
// Either download the latest version of the b2d url that was explicitly
// specified when creating the VM or copy the (updated) default ISO
if err := b2dutils.CopyIsoToMachineDir(d.Boot2DockerURL, machineName); err != nil {
return err
}
log.Infof("Starting machine back up...")
if err := provisioner.Driver.Start(); err != nil {
return err
}
return mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running))
}
示例2: WaitForSSH
func WaitForSSH(d Driver) error {
// Try to dial SSH for 30 seconds before timing out.
if err := mcnutils.WaitFor(sshAvailableFunc(d)); err != nil {
return fmt.Errorf("Too many retries waiting for SSH to be available. Last error: %s", err)
}
return nil
}
示例3: Provision
func (provisioner *DebianProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error {
provisioner.SwarmOptions = swarmOptions
provisioner.AuthOptions = authOptions
provisioner.EngineOptions = engineOptions
swarmOptions.Env = engineOptions.Env
storageDriver, err := decideStorageDriver(provisioner, "aufs", engineOptions.StorageDriver)
if err != nil {
return err
}
provisioner.EngineOptions.StorageDriver = storageDriver
// HACK: since debian does not come with sudo by default we install
log.Debug("installing sudo")
if _, err := provisioner.SSHCommand("if ! type sudo; then apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y sudo; fi"); err != nil {
return err
}
log.Debug("setting hostname")
if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil {
return err
}
log.Debug("installing base packages")
for _, pkg := range provisioner.Packages {
if err := provisioner.Package(pkg, pkgaction.Install); err != nil {
return err
}
}
log.Debug("installing docker")
if err := installDockerGeneric(provisioner, engineOptions.InstallURL); err != nil {
return err
}
log.Debug("waiting for docker daemon")
if err := mcnutils.WaitFor(provisioner.dockerDaemonResponding); err != nil {
return err
}
provisioner.AuthOptions = setRemoteAuthOptions(provisioner)
log.Debug("configuring auth")
if err := ConfigureAuth(provisioner); err != nil {
return err
}
log.Debug("configuring swarm")
if err := configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions); err != nil {
return err
}
// enable in systemd
log.Debug("enabling docker in systemd")
if err := provisioner.Service("docker", serviceaction.Enable); err != nil {
return err
}
return nil
}
示例4: waitForInstance
func (d *Driver) waitForInstance() error {
if err := mcnutils.WaitFor(d.instanceIsRunning); err != nil {
return err
}
return nil
}
示例5: Provision
func (provisioner *SUSEProvisioner) Provision(swarmOptions swarm.SwarmOptions, authOptions auth.AuthOptions, engineOptions engine.EngineOptions) error {
provisioner.SwarmOptions = swarmOptions
provisioner.AuthOptions = authOptions
provisioner.EngineOptions = engineOptions
if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil {
return err
}
for _, pkg := range provisioner.Packages {
if err := provisioner.Package(pkg, pkgaction.Install); err != nil {
return err
}
}
// update OS -- this is needed for libdevicemapper and the docker install
if _, err := provisioner.SSHCommand("sudo zypper ref"); err != nil {
return err
}
if _, err := provisioner.SSHCommand("sudo zypper -n update"); err != nil {
return err
}
if err := installDockerGeneric(provisioner, engineOptions.InstallURL); err != nil {
return err
}
if _, err := provisioner.SSHCommand("sudo systemctl start docker"); err != nil {
return err
}
if err := mcnutils.WaitFor(provisioner.dockerDaemonResponding); err != nil {
return err
}
if _, err := provisioner.SSHCommand("sudo systemctl stop docker"); err != nil {
return err
}
// open firewall port required by docker
if _, err := provisioner.SSHCommand("sudo /sbin/yast2 firewall services add ipprotocol=tcp tcpport=2376 zone=EXT"); err != nil {
return err
}
if err := makeDockerOptionsDir(provisioner); err != nil {
return err
}
provisioner.AuthOptions = setRemoteAuthOptions(provisioner)
if err := ConfigureAuth(provisioner); err != nil {
return err
}
if err := configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions); err != nil {
return err
}
return nil
}
示例6: upgradeIso
func (provisioner *RancherProvisioner) upgradeIso() error {
// Largely copied from Boot2Docker provisioner, we should find a way to share this code
log.Info("Stopping machine to do the upgrade...")
if err := provisioner.Driver.Stop(); err != nil {
return err
}
if err := mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil {
return err
}
machineName := provisioner.GetDriver().GetMachineName()
log.Infof("Upgrading machine %s...", machineName)
// TODO: Ideally, we should not read from mcndirs directory at all.
// The driver should be able to communicate how and where to place the
// relevant files.
b2dutils := mcnutils.NewB2dUtils(mcndirs.GetBaseDir())
url, err := provisioner.getLatestISOURL()
if err != nil {
return err
}
if err := b2dutils.DownloadISOFromURL(url); err != nil {
return err
}
// Copy the latest version of boot2docker ISO to the machine's directory
if err := b2dutils.CopyIsoToMachineDir("", machineName); err != nil {
return err
}
log.Infof("Starting machine back up...")
if err := provisioner.Driver.Start(); err != nil {
return err
}
return mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running))
}
示例7: create
// Create is the wrapper method which covers all of the boilerplate around
// actually creating, provisioning, and persisting an instance in the store.
func create(store persist.Store, h *host.Host, callback func(*host.Host)) error {
if err := cert.BootstrapCertificates(h.HostOptions.AuthOptions); err != nil {
return fmt.Errorf("Error generating certificates: %s", err)
}
log.Info("Running pre-create checks...")
if err := h.Driver.PreCreateCheck(); err != nil {
return fmt.Errorf("Error with pre-create check: %s", err)
}
if err := store.Save(h); err != nil {
return fmt.Errorf("Error saving host to store before attempting creation: %s", err)
}
log.Info("Creating machine...")
if err := h.Driver.Create(); err != nil {
return fmt.Errorf("Error in driver during machine creation: %s", err)
}
if err := store.Save(h); err != nil {
return fmt.Errorf("Error saving host to store after attempting creation: %s", err)
}
// TODO: Not really a fan of just checking "none" here.
if h.Driver.DriverName() != "none" {
log.Info("Waiting for machine to be running, this may take a few minutes...")
if err := mcnutils.WaitFor(drivers.MachineInState(h.Driver, state.Running)); err != nil {
return fmt.Errorf("Error waiting for machine to be running: %s", err)
}
log.Info("Machine is running, waiting for SSH to be available...")
if err := drivers.WaitForSSH(h.Driver); err != nil {
return fmt.Errorf("Error waiting for SSH: %s", err)
}
log.Info("Detecting operating system of created instance...")
provisioner, err := provision.DetectProvisioner(h.Driver)
if err != nil {
return fmt.Errorf("Error detecting OS: %s", err)
}
callback(h)
log.Info("Provisioning created instance...")
if err := provisioner.Provision(*h.HostOptions.SwarmOptions, *h.HostOptions.AuthOptions, *h.HostOptions.EngineOptions); err != nil {
return fmt.Errorf("Error running provisioning: %s", err)
}
}
log.Debug("Reticulating splines...")
return nil
}
示例8: Provision
func (provisioner *RedHatProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error {
provisioner.SwarmOptions = swarmOptions
provisioner.AuthOptions = authOptions
provisioner.EngineOptions = engineOptions
swarmOptions.Env = engineOptions.Env
// set default storage driver for redhat
storageDriver, err := decideStorageDriver(provisioner, "devicemapper", engineOptions.StorageDriver)
if err != nil {
return err
}
provisioner.EngineOptions.StorageDriver = storageDriver
if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil {
return err
}
for _, pkg := range provisioner.Packages {
log.Debugf("installing base package: name=%s", pkg)
if err := provisioner.Package(pkg, pkgaction.Install); err != nil {
return err
}
}
// update OS -- this is needed for libdevicemapper and the docker install
if _, err := provisioner.SSHCommand("sudo yum -y update"); err != nil {
return err
}
// install docker
if err := installDocker(provisioner); err != nil {
return err
}
if err := mcnutils.WaitFor(provisioner.dockerDaemonResponding); err != nil {
return err
}
if err := makeDockerOptionsDir(provisioner); err != nil {
return err
}
provisioner.AuthOptions = setRemoteAuthOptions(provisioner)
if err := ConfigureAuth(provisioner); err != nil {
return err
}
if err := configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions); err != nil {
return err
}
return nil
}
示例9: Provision
func (provisioner *UbuntuSystemdProvisioner) Provision(swarmOptions swarm.Options, authOptions auth.Options, engineOptions engine.Options) error {
provisioner.SwarmOptions = swarmOptions
provisioner.AuthOptions = authOptions
provisioner.EngineOptions = engineOptions
swarmOptions.Env = engineOptions.Env
storageDriver, err := decideStorageDriver(provisioner, "aufs", engineOptions.StorageDriver)
if err != nil {
return err
}
provisioner.EngineOptions.StorageDriver = storageDriver
log.Debug("setting hostname")
if err := provisioner.SetHostname(provisioner.Driver.GetMachineName()); err != nil {
return err
}
log.Debug("installing base packages")
for _, pkg := range provisioner.Packages {
if err := provisioner.Package(pkg, pkgaction.Install); err != nil {
return err
}
}
log.Info("Installing Docker...")
if err := installDockerGeneric(provisioner, engineOptions.InstallURL); err != nil {
return err
}
log.Debug("waiting for docker daemon")
if err := mcnutils.WaitFor(provisioner.dockerDaemonResponding); err != nil {
return err
}
provisioner.AuthOptions = setRemoteAuthOptions(provisioner)
log.Debug("configuring auth")
if err := ConfigureAuth(provisioner); err != nil {
return err
}
log.Debug("configuring swarm")
if err := configureSwarm(provisioner, swarmOptions, provisioner.AuthOptions); err != nil {
return err
}
// enable in systemd
log.Debug("enabling docker in systemd")
if err := provisioner.Service("docker", serviceaction.Enable); err != nil {
return err
}
return nil
}
示例10: runActionForState
func (h *Host) runActionForState(action func() error, desiredState state.State) error {
if drivers.MachineInState(h.Driver, desiredState)() {
return fmt.Errorf("Machine %q is already %s.", h.Name, strings.ToLower(desiredState.String()))
}
if err := action(); err != nil {
return err
}
return mcnutils.WaitFor(drivers.MachineInState(h.Driver, desiredState))
}
示例11: Restart
func (h *Host) Restart() error {
if drivers.MachineInState(h.Driver, state.Running)() {
if err := h.Stop(); err != nil {
return err
}
if err := mcnutils.WaitFor(drivers.MachineInState(h.Driver, state.Stopped)); err != nil {
return err
}
}
if err := h.Start(); err != nil {
return err
}
if err := mcnutils.WaitFor(drivers.MachineInState(h.Driver, state.Running)); err != nil {
return err
}
return nil
}
示例12: session
func (client NativeClient) session(command string) (*ssh.Session, error) {
if err := mcnutils.WaitFor(client.dialSuccess); err != nil {
return nil, fmt.Errorf("Error attempting SSH client dial: %s", err)
}
conn, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", client.Hostname, client.Port), &client.Config)
if err != nil {
return nil, fmt.Errorf("Mysterious error dialing TCP for SSH (we already succeeded at least once) : %s", err)
}
return conn.NewSession()
}
示例13: session
func (client *NativeClient) session(command string) (*ssh.Client, *ssh.Session, error) {
if err := mcnutils.WaitFor(client.dialSuccess); err != nil {
return nil, nil, fmt.Errorf("Error attempting SSH client dial: %s", err)
}
conn, err := ssh.Dial("tcp", net.JoinHostPort(client.Hostname, strconv.Itoa(client.Port)), &client.Config)
if err != nil {
return nil, nil, fmt.Errorf("Mysterious error dialing TCP for SSH (we already succeeded at least once) : %s", err)
}
session, err := conn.NewSession()
return conn, session, err
}
示例14: upgradeIso
func (provisioner *Boot2DockerProvisioner) upgradeIso() error {
log.Info("Stopping machine to do the upgrade...")
if err := provisioner.Driver.Stop(); err != nil {
return err
}
if err := mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Stopped)); err != nil {
return err
}
machineName := provisioner.GetDriver().GetMachineName()
log.Infof("Upgrading machine %s...", machineName)
// TODO: Ideally, we should not read from mcndirs directory at all.
// The driver should be able to communicate how and where to place the
// relevant files.
b2dutils := mcnutils.NewB2dUtils("", "", mcndirs.GetBaseDir())
// Usually we call this implicitly, but call it here explicitly to get
// the latest boot2docker ISO.
if err := b2dutils.DownloadLatestBoot2Docker(); err != nil {
return err
}
// Copy the latest version of boot2docker ISO to the machine's directory
if err := b2dutils.CopyIsoToMachineDir("", machineName); err != nil {
return err
}
log.Infof("Starting machine back up...")
if err := provisioner.Driver.Start(); err != nil {
return err
}
return mcnutils.WaitFor(drivers.MachineInState(provisioner.Driver, state.Running))
}
示例15: configureSecurityGroup
func (d *Driver) configureSecurityGroup() error {
var groupId int
groupId, err := d.getSecurityGroup(d.SecurityGroupName)
if err != nil {
log.Debugf("get security group error:%s", err)
}
log.Debugf("groupId:%d", groupId)
if groupId == 0 {
log.Infof("security group is not found, create a new one")
rule := []string{"TCP|22|0.0.0.0/0|ACCEPT|50",
"TCP|3389|0.0.0.0/0|ACCEPT|50",
"TCP|2376|0.0.0.0/0|ACCEPT|50",
}
if d.SwarmMaster && validPort(swarmPort) {
swarmRule := fmt.Sprintf("TCP|%d|0.0.0.0/0|ACCEPT|50", swarmPort)
rule = append(rule, swarmRule)
}
securityGroupParams := unet.CreateSecurityGroupParams{
Region: d.Region,
GroupName: "docker-machine",
Description: "docker machine to open 2379 and 22 port of tcp",
Rule: rule,
}
_, err := d.getUNetService().CreateSecurityGroup(&securityGroupParams)
if err != nil {
return fmt.Errorf("create security group failed:%s", err)
}
log.Debug("waiting for security group to become avaliable")
if err := mcnutils.WaitFor(d.securityGroupAvailableFunc(d.SecurityGroupName)); err != nil {
return err
}
groupId, err = d.getSecurityGroup(d.SecurityGroupName)
}
d.SecurityGroupId = groupId
grantSecurityGroupParams := unet.GrantSecurityGroupParams{
Region: d.Region,
GroupId: groupId,
ResourceType: "uhost",
ResourceId: d.UhostID,
}
log.Debugf("grant security group(%d) to uhost(%s)", groupId, d.UhostID)
_, err = d.getUNetService().GrantSecurityGroup(&grantSecurityGroupParams)
if err != nil {
return fmt.Errorf("grant security group failed:%s", err)
}
return nil
}