• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang drivers.MachineInState函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/docker/machine/libmachine/drivers.MachineInState函数的典型用法代码示例。如果您正苦于以下问题:Golang MachineInState函数的具体用法?Golang MachineInState怎么用?Golang MachineInState使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了MachineInState函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
}
开发者ID:mschygulla,项目名称:machine,代码行数:54,代码来源:boot2docker.go


示例2: 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))
}
开发者ID:sheltowt,项目名称:machine,代码行数:11,代码来源:host.go


示例3: Restart

func (h *Host) Restart() error {
	if drivers.MachineInState(h.Driver, state.Stopped)() {
		return h.Start()
	}
	if drivers.MachineInState(h.Driver, state.Running)() {
		if err := h.Driver.Restart(); err != nil {
			return err
		}
		return mcnutils.WaitFor(drivers.MachineInState(h.Driver, state.Running))
	}
	return nil
}
开发者ID:sergey-stratoscale,项目名称:machine,代码行数:12,代码来源:host.go


示例4: runActionForState

func (h *Host) runActionForState(action func() error, desiredState state.State) error {
	if drivers.MachineInState(h.Driver, desiredState)() {
		return mcnerror.ErrHostAlreadyInState{
			Name:  h.Name,
			State: desiredState,
		}
	}

	if err := action(); err != nil {
		return err
	}

	return mcnutils.WaitFor(drivers.MachineInState(h.Driver, desiredState))
}
开发者ID:tsuru,项目名称:tsuru,代码行数:14,代码来源:host.go


示例5: Restart

func (h *Host) Restart() error {
	log.Infof("Restarting %q...", h.Name)
	if drivers.MachineInState(h.Driver, state.Stopped)() {
		if err := h.Start(); err != nil {
			return err
		}
	} else if drivers.MachineInState(h.Driver, state.Running)() {
		if err := h.Driver.Restart(); err != nil {
			return err
		}
		if err := mcnutils.WaitFor(drivers.MachineInState(h.Driver, state.Running)); err != nil {
			return err
		}
	}

	return h.WaitForDocker()
}
开发者ID:tsuru,项目名称:tsuru,代码行数:17,代码来源:host.go


示例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))
}
开发者ID:ChristopherBiscardi,项目名称:machine,代码行数:43,代码来源:rancheros.go


示例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
}
开发者ID:chanwit,项目名称:gattai,代码行数:57,代码来源:provision.go


示例8: 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))
}
开发者ID:nlamirault,项目名称:docker-machine-scaleway,代码行数:39,代码来源:boot2docker.go


示例9: performCreate

func (api *Client) performCreate(h *host.Host) error {

	if err := h.Driver.Create(); err != nil {
		return fmt.Errorf("Error in driver during machine creation: %s", err)
	}

	if err := api.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)
		}

		log.Infof("Provisioning with %s...", provisioner.String())
		if err := provisioner.Provision(*h.HostOptions.SwarmOptions, *h.HostOptions.AuthOptions, *h.HostOptions.EngineOptions); err != nil {
			return fmt.Errorf("Error running provisioning: %s", err)
		}

		// We should check the connection to docker here
		log.Info("Checking connection to Docker...")
		if _, _, err = check.DefaultConnChecker.Check(h, false); err != nil {
			return fmt.Errorf("Error checking the host: %s", err)
		}

		log.Info("Docker is up and running!")
	}

	return nil

}
开发者ID:sergey-stratoscale,项目名称:machine,代码行数:45,代码来源:libmachine.go


示例10: Create

func (d *Driver) Create() error {
	log.Infof("Create UHost instance...")

	if d.Password == "" {
		d.Password = generateRandomPassword(16)
		log.Infof("password is not set, we use the random password instead, password:%s", d.Password)
	}

	// create keypair
	log.Infof("Creating key pair for instances...")
	if err := d.createKeyPair(); err != nil {
		return fmt.Errorf("unable to create key pair: %s", err)
	}

	// create uhost instance
	log.Infof("Creating uhost instance...")
	if err := d.createUHost(); err != nil {
		return fmt.Errorf("create UHost failed:%s", err)
	}

	// waiting for creating successful
	if err := mcnutils.WaitForSpecific(drivers.MachineInState(d, state.Running), 120, 3*time.Second); err != nil {
		return fmt.Errorf("wait for machine running failed: %s", err)
	}

	// create networks, like private ip, eip, and security group
	log.Infof("Creating networks...")
	//TODO: user the exist eip and security group to configure network
	if err := d.createUNet(); err != nil {
		return fmt.Errorf("create networks failed:%s", err)
	}

	// upload keypair
	if err := d.uploadKeyPair(); err != nil {
		return fmt.Errorf("upload keypair failed:%s", err)
	}

	return nil
}
开发者ID:ucloud,项目名称:docker-machine-ucloud,代码行数:39,代码来源:ucloud.go


示例11: Create


//.........这里部分代码省略.........
		if err != nil {
			return err
		}
	}

	linodeIPListResponse, err := client.Ip.List(d.LinodeId, -1)
	if err != nil {
		return err
	}
	for _, fullIpAddress := range linodeIPListResponse.FullIPAddresses {
		if fullIpAddress.IsPublic == 1 {
			d.IPAddress = fullIpAddress.IPAddress
		}
	}

	if d.IPAddress == "" {
		return errors.New("Linode IP Address is not found.")
	}

	log.Debugf("Created linode ID %d, IP address %s",
		d.LinodeId,
		d.IPAddress)

	// Deploy distribution
	args := make(map[string]string)
	args["rootPass"] = d.RootPassword
	args["rootSSHKey"] = publicKey
	distributionId := d.DistributionId

	log.Debug("Create disk")
	createDiskJobResponse, err := d.client.Disk.CreateFromDistribution(distributionId, d.LinodeId, "Primary Disk", 24576-256, args)

	if err != nil {
		return err
	}

	jobId := createDiskJobResponse.DiskJob.JobId
	diskId := createDiskJobResponse.DiskJob.DiskId
	log.Debugf("Linode create disk task :%d.", jobId)

	// wait until the creation is finished
	err = d.waitForJob(jobId, "Create Disk Task", 60)
	if err != nil {
		return err
	}

	// create swap
	log.Debug("Create swap disk")
	createDiskJobResponse, err = d.client.Disk.Create(d.LinodeId, "swap", "Swap Disk", 256, nil)
	if err != nil {
		return err
	}

	jobId = createDiskJobResponse.DiskJob.JobId
	swapDiskId := createDiskJobResponse.DiskJob.DiskId
	log.Debugf("Linode create swap disk task :%d.", jobId)

	// wait until the creation is finished
	err = d.waitForJob(jobId, "Create Swap Disk Task", 60)
	if err != nil {
		return err
	}

	// create config
	log.Debug("Create configuration")
	args2 := make(map[string]string)
	args2["DiskList"] = fmt.Sprintf("%d,%d", diskId, swapDiskId)
	args2["RootDeviceNum"] = "1"
	args2["RootDeviceRO"] = "true"
	args2["helper_distro"] = "true"
	kernelId := d.KernelId
	_, err = d.client.Config.Create(d.LinodeId, kernelId, "My Docker Machine Configuration", args2)

	if err != nil {
		return err
	}

	log.Debugf("Linode configuration created.")

	// Boot
	log.Debug("Booting")
	jobResponse, err := d.client.Linode.Boot(d.LinodeId, -1)
	if err != nil {
		return err
	}
	jobId = jobResponse.JobId.JobId
	log.Debugf("Booting linode, job id: %v", jobId)
	// wait for boot
	err = d.waitForJob(jobId, "Booting linode", 60)
	if err != nil {
		return err
	}

	log.Debug("Waiting for Machine Running...")
	if err := mcnutils.WaitForSpecific(drivers.MachineInState(d, state.Running), 120, 3*time.Second); err != nil {
		return fmt.Errorf("wait for machine running failed: %s", err)
	}

	return nil
}
开发者ID:taoh,项目名称:docker-machine-linode,代码行数:101,代码来源:linode.go



注:本文中的github.com/docker/machine/libmachine/drivers.MachineInState函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang drivers.MustBeRunning函数代码示例发布时间:2022-05-23
下一篇:
Golang libmachine.API类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap