当前位置: 首页>>代码示例>>Golang>>正文


Golang Host.GetURL方法代码示例

本文整理汇总了Golang中github.com/docker/machine/libmachine/host.Host.GetURL方法的典型用法代码示例。如果您正苦于以下问题:Golang Host.GetURL方法的具体用法?Golang Host.GetURL怎么用?Golang Host.GetURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/docker/machine/libmachine/host.Host的用法示例。


在下文中一共展示了Host.GetURL方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: engineExecute

func engineExecute(h *host.Host, line string) error {
	p := shellwords.NewParser()
	args, err := p.Parse(line)
	if err != nil {
		return err
	}

	url, err := h.GetURL()
	if err != nil {
		return err
	}

	args = append([]string{
		"-H", url,
		"--tlscacert=" + h.HostOptions.AuthOptions.CaCertPath,
		"--tlscert=" + h.HostOptions.AuthOptions.ClientCertPath,
		"--tlskey=" + h.HostOptions.AuthOptions.ClientKeyPath,
		"--tlsverify=true"}, args...)

	cmd := exec.Command(os.Args[0], args...)
	log.Debugf("[engineExecute] Executing: %s", cmd)

	b, err := cmd.CombinedOutput()
	if err != nil {
		fmt.Print(string(b))
		return err
	}

	return nil
}
开发者ID:chanwit,项目名称:gattai,代码行数:30,代码来源:provision.go

示例2: isActive

// IsActive provides a single function for determining if a host is active
// based on both the url and if the host is stopped.
func isActive(h *host.Host) (bool, error) {
	currentState, err := h.Driver.GetState()

	if err != nil {
		log.Errorf("error getting state for host %s: %s", h.Name, err)
		return false, err
	}

	url, err := h.GetURL()

	if err != nil {
		if err == drivers.ErrHostIsNotRunning {
			url = ""
		} else {
			log.Errorf("error getting URL for host %s: %s", h.Name, err)
			return false, err
		}
	}

	dockerHost := os.Getenv("DOCKER_HOST")

	notStopped := currentState != state.Stopped
	correctURL := url == dockerHost

	isActive := notStopped && correctURL

	return isActive, nil
}
开发者ID:chanwit,项目名称:gattai,代码行数:30,代码来源:ls.go

示例3: attemptGetHostState

func attemptGetHostState(h *host.Host, stateQueryChan chan<- HostListItem) {
	currentState, err := h.Driver.GetState()
	if err != nil {
		log.Errorf("error getting state for host %s: %s", h.Name, err)
	}

	url, err := h.GetURL()
	if err != nil {
		if err == drivers.ErrHostIsNotRunning {
			url = ""
		} else {
			log.Errorf("error getting URL for host %s: %s", h.Name, err)
		}
	}

	active, err := isActive(h)
	if err != nil {
		log.Errorf("error determining if host is active for host %s: %s",
			h.Name, err)
	}

	stateQueryChan <- HostListItem{
		Name:         h.Name,
		Active:       active,
		DriverName:   h.Driver.DriverName(),
		State:        currentState,
		URL:          url,
		SwarmOptions: h.HostOptions.SwarmOptions,
	}
}
开发者ID:chanwit,项目名称:gattai,代码行数:30,代码来源:ls.go

示例4: attemptGetHostState

func attemptGetHostState(h *host.Host, stateQueryChan chan<- HostListItem) {
	url := ""
	hostError := ""

	currentState, err := h.Driver.GetState()
	if err == nil {
		url, err = h.GetURL()
	}
	if err != nil {
		hostError = err.Error()
	}
	if hostError == drivers.ErrHostIsNotRunning.Error() {
		hostError = ""
	}

	var swarmOptions *swarm.Options
	if h.HostOptions != nil {
		swarmOptions = h.HostOptions.SwarmOptions
	}

	stateQueryChan <- HostListItem{
		Name:         h.Name,
		Active:       isActive(currentState, url),
		DriverName:   h.Driver.DriverName(),
		State:        currentState,
		URL:          url,
		SwarmOptions: swarmOptions,
		Error:        hostError,
	}
}
开发者ID:usmanismail,项目名称:machine,代码行数:30,代码来源:ls.go

示例5: attemptGetHostState

func attemptGetHostState(h *host.Host, stateQueryChan chan<- HostListItem) {
	stateCh := make(chan state.State)
	urlCh := make(chan string)

	go func() {
		currentState, err := h.Driver.GetState()
		if err != nil {
			log.Errorf("error getting state for host %s: %s", h.Name, err)
		}

		stateCh <- currentState
	}()

	go func() {
		url, err := h.GetURL()
		if err != nil {
			if err.Error() == drivers.ErrHostIsNotRunning.Error() {
				url = ""
			} else {
				log.Errorf("error getting URL for host %s: %s", h.Name, err)
			}
		}

		urlCh <- url
	}()

	currentState := <-stateCh
	url := <-urlCh

	close(stateCh)
	close(urlCh)

	active, err := isActive(h, currentState, url)
	if err != nil {
		log.Errorf("error determining if host is active for host %s: %s",
			h.Name, err)
	}

	stateQueryChan <- HostListItem{
		Name:         h.Name,
		Active:       active,
		DriverName:   h.Driver.DriverName(),
		State:        currentState,
		URL:          url,
		SwarmOptions: h.HostOptions.SwarmOptions,
	}
}
开发者ID:mschygulla,项目名称:machine,代码行数:47,代码来源:ls.go

示例6: swarmManage

func swarmManage(h *host.Host, image string, token string) error {

	provisioner, err := provision.DetectProvisioner(h.Driver)
	dockerDir := provisioner.GetDockerOptionsDir()
	authOptions := setRemoteAuthOptions(provisioner)

	url, err := h.GetURL()
	if err != nil {
		return err
	}

	retryCount := 0

retry:
	exec.Command(os.Args[0], []string{
		"-H", url,
		"--tlscacert=" + h.HostOptions.AuthOptions.CaCertPath,
		"--tlscert=" + h.HostOptions.AuthOptions.ClientCertPath,
		"--tlskey=" + h.HostOptions.AuthOptions.ClientKeyPath,
		"--tlsverify=true",
		"rm", "-f", "swarm-manager"}...).Output()

	cmd := exec.Command(os.Args[0], []string{
		"-H", url,
		"--tlscacert=" + h.HostOptions.AuthOptions.CaCertPath,
		"--tlscert=" + h.HostOptions.AuthOptions.ClientCertPath,
		"--tlskey=" + h.HostOptions.AuthOptions.ClientKeyPath,
		"--tlsverify=true",
		"run", "-d", "--restart=always",
		"--net=bridge",
		"--name", "swarm-manager",
		"-p", "3376:3376",
		"-v", dockerDir + ":" + dockerDir,
		image, "manage",
		"--tlsverify",
		"--tlscacert=" + authOptions.CaCertRemotePath,
		"--tlscert=" + authOptions.ServerCertRemotePath,
		"--tlskey=" + authOptions.ServerKeyRemotePath,
		"-H", "0.0.0.0:3376",
		token}...)

	err = cmd.Run()
	if err == nil {
		fmt.Printf("Manager '%s' started successfully...\n", h.Name)
		return nil
	}

	if _, ok := err.(*exec.ExitError); ok {
		retryCount++
		if retryCount <= 5 {
			fmt.Printf("Failed to start manager. Retry: %d\n", retryCount)
			goto retry
		}
		// if s, ok := exiterr.Sys().(syscall.WaitStatus); ok {
		// 	if s.ExitCode == 8 {
		// 		goto retry
		// 	}
		// }
	}

	return err
}
开发者ID:chanwit,项目名称:gattai,代码行数:62,代码来源:cluster.go


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