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

Golang errors.LogError函数代码示例

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

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



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

示例1: CopyFromHost

// CopyFromHost copies a set of files from the Docker host to the local file system
func (h *HostHelper) CopyFromHost(sourceDir, destDir string) error {
	container, err := h.runner().
		Image(h.image).
		Bind(fmt.Sprintf("%[1]s:%[1]s:ro", sourceDir)).
		Create()
	if err != nil {
		return err
	}
	defer func() {
		errors.LogError(h.client.RemoveContainer(docker.RemoveContainerOptions{ID: container}))
	}()
	localTarFile, err := ioutil.TempFile("", "local-copy-tar-")
	if err != nil {
		return err
	}
	localTarClosed := false
	defer func() {
		if !localTarClosed {
			errors.LogError(localTarFile.Close())
		}
		errors.LogError(os.Remove(localTarFile.Name()))
	}()
	glog.V(4).Infof("Downloading from host path %s to local tar file: %s", sourceDir, localTarFile.Name())
	err = h.client.DownloadFromContainer(container, docker.DownloadFromContainerOptions{
		Path:         sourceDir,
		OutputStream: localTarFile,
	})
	if err != nil {
		return err
	}
	if err = localTarFile.Close(); err != nil {
		return err
	}
	localTarClosed = true
	inputTar, err := os.Open(localTarFile.Name())
	if err != nil {
		return err
	}
	defer func() {
		errors.LogError(inputTar.Close())
	}()
	tarHelper := tarhelper.New()
	tarHelper.SetExclusionPattern(nil)
	glog.V(4).Infof("Extracting temporary tar %s to directory %s", inputTar.Name(), destDir)
	var tarLog io.Writer
	if glog.V(5) {
		tarLog = os.Stderr
	}
	return tarHelper.ExtractTarStreamWithLogging(destDir, inputTar, tarLog)
}
开发者ID:Xmagicer,项目名称:origin,代码行数:51,代码来源:host.go


示例2: TestIP

func (h *Helper) TestIP(ip string) error {

	// Start test server on host
	id, err := h.runHelper.New().Image(h.image).
		Privileged().
		HostNetwork().
		Entrypoint("socat").
		Command("TCP-LISTEN:8443,crlf,reuseaddr,fork", "SYSTEM:\"echo 'hello world'\"").Start()
	if err != nil {
		return errors.NewError("cannnot start simple server on Docker host").WithCause(err)
	}
	defer func() {
		errors.LogError(h.dockerHelper.StopAndRemoveContainer(id))
	}()

	// Attempt to connect to test container
	testHost := fmt.Sprintf("%s:8443", ip)
	glog.V(4).Infof("Attempting to dial %s", testHost)
	if err = cmdutil.WaitForSuccessfulDial(false, "tcp", testHost, 200*time.Millisecond, 1*time.Second, 10); err != nil {
		glog.V(2).Infof("Dial error: %v", err)
		return err
	}
	glog.V(4).Infof("Successfully dialed %s", testHost)
	return nil
}
开发者ID:RomainVabre,项目名称:origin,代码行数:25,代码来源:helper.go


示例3: TestForwardedIP

func (h *Helper) TestForwardedIP(ip string) error {
	// Start test server on host
	id, err := h.runHelper.New().Image(h.image).
		PortForward(8443, 8443).
		Entrypoint("socat").
		Command("TCP-LISTEN:8443,crlf,reuseaddr,fork", "SYSTEM:\"echo 'hello world'\"").Start()
	if err != nil {
		return errors.NewError("cannnot start simple server on Docker host").WithCause(err)
	}
	defer func() {
		errors.LogError(h.dockerHelper.StopAndRemoveContainer(id))
	}()
	return testIPDial(ip)
}
开发者ID:mffiedler,项目名称:origin,代码行数:14,代码来源:helper.go


示例4: makeTempCopy

// makeTempCopy creates a temporary directory and places a copy of the source file
// in it. It returns the directory where the temporary copy was made.
func makeTempCopy(file string) (string, error) {
	tempDir, err := ioutil.TempDir("", "")
	if err != nil {
		return "", err
	}
	destPath := filepath.Join(tempDir, filepath.Base(file))
	destFile, err := os.Create(destPath)
	if err != nil {
		return "", err
	}
	defer func() {
		errors.LogError(destFile.Close())
	}()
	sourceFile, err := os.Open(file)
	if err != nil {
		return "", err
	}
	defer func() {
		errors.LogError(sourceFile.Close())
	}()
	_, err = io.Copy(destFile, sourceFile)
	return tempDir, err
}
开发者ID:Xmagicer,项目名称:origin,代码行数:25,代码来源:host.go


示例5: DownloadDirFromContainer

// DownloadDirFromContainer copies a set of files from the Docker host to the local file system
func (h *HostHelper) DownloadDirFromContainer(sourceDir, destDir string) error {
	container, err := h.runner().
		Image(h.image).
		Bind(h.defaultBinds()...).
		Entrypoint("/bin/true").
		Create()
	if err != nil {
		return err
	}
	defer func() {
		errors.LogError(h.client.RemoveContainer(docker.RemoveContainerOptions{ID: container}))
	}()
	err = dockerhelper.DownloadDirFromContainer(h.client, container, sourceDir, destDir)
	if err != nil {
		glog.V(4).Infof("An error occurred downloading the directory: %v", err)
	} else {
		glog.V(4).Infof("Successfully downloaded directory.")
	}
	return err
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:21,代码来源:host.go


示例6: UploadFileToContainer

// UploadFileToContainer copies a local file to the Docker host
func (h *HostHelper) UploadFileToContainer(src, dst string) error {
	container, err := h.runner().
		Image(h.image).
		Bind(h.defaultBinds()...).
		Entrypoint("/bin/true").
		Create()
	if err != nil {
		return err
	}
	defer func() {
		errors.LogError(h.client.RemoveContainer(docker.RemoveContainerOptions{ID: container}))
	}()
	err = dockerhelper.UploadFileToContainer(h.client, container, src, dst)
	if err != nil {
		glog.V(4).Infof("An error occurred uploading the file: %v", err)
	} else {
		glog.V(4).Infof("Successfully uploaded file.")
	}
	return err
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:21,代码来源:host.go


示例7: Start

// Start starts the OpenShift master as a Docker container
// and returns a directory in the local file system where
// the OpenShift configuration has been copied
func (h *Helper) Start(opt *StartOptions, out io.Writer) (string, error) {
	// Ensure that socat is available locally
	if opt.PortForwarding {
		err := CheckSocat()
		if err != nil {
			return "", err
		}
	}

	binds := openShiftContainerBinds
	env := []string{}
	if opt.UseSharedVolume {
		binds = append(binds, fmt.Sprintf("%[1]s:%[1]s:shared", opt.HostVolumesDir))
		env = append(env, "OPENSHIFT_CONTAINERIZED=false")
	} else {
		binds = append(binds, "/:/rootfs:ro")
		propagationMode := ""
		if opt.SetPropagationMode {
			propagationMode = ":rslave"
		}
		binds = append(binds, fmt.Sprintf("%[1]s:%[1]s%[2]s", opt.HostVolumesDir, propagationMode))
	}
	env = append(env, opt.Environment...)
	binds = append(binds, fmt.Sprintf("%s:/var/lib/origin/openshift.local.config:z", opt.HostConfigDir))

	// Check if a configuration exists before creating one if UseExistingConfig
	// was specified
	var configDir string
	cleanupConfig := func() {
		errors.LogError(os.RemoveAll(configDir))
	}
	skipCreateConfig := false
	if opt.UseExistingConfig {
		var err error
		configDir, err = h.copyConfig(opt.HostConfigDir)
		if err == nil {
			_, err = os.Stat(filepath.Join(configDir, "master", "master-config.yaml"))
			if err == nil {
				skipCreateConfig = true
			}
		}
	}

	// Create configuration if needed
	var nodeHost string
	if !skipCreateConfig {
		glog.V(1).Infof("Creating openshift configuration at %s on Docker host", opt.HostConfigDir)
		fmt.Fprintf(out, "Creating initial OpenShift configuration\n")
		createConfigCmd := []string{
			"start",
			fmt.Sprintf("--images=%s", opt.Images),
			fmt.Sprintf("--volume-dir=%s", opt.HostVolumesDir),
			fmt.Sprintf("--dns=0.0.0.0:%d", opt.DNSPort),
			"--write-config=/var/lib/origin/openshift.local.config",
		}
		if opt.PortForwarding {
			internalIP, err := h.ServerIP()
			if err != nil {
				return "", err
			}
			nodeHost = internalIP
			createConfigCmd = append(createConfigCmd, fmt.Sprintf("--master=%s", internalIP))
			createConfigCmd = append(createConfigCmd, fmt.Sprintf("--public-master=https://%s:8443", opt.ServerIP))
		} else {
			nodeHost = opt.ServerIP
			createConfigCmd = append(createConfigCmd, fmt.Sprintf("--master=%s", opt.ServerIP))
			if len(h.publicHost) > 0 {
				createConfigCmd = append(createConfigCmd, fmt.Sprintf("--public-master=https://%s:8443", h.publicHost))
			}
		}
		createConfigCmd = append(createConfigCmd, fmt.Sprintf("--hostname=%s", nodeHost))
		_, err := h.runHelper.New().Image(h.image).
			Privileged().
			DiscardContainer().
			HostNetwork().
			HostPid().
			Bind(binds...).
			Env(env...).
			Command(createConfigCmd...).Run()
		if err != nil {
			return "", errors.NewError("could not create OpenShift configuration").WithCause(err)
		}
		configDir, err = h.copyConfig(opt.HostConfigDir)
		if err != nil {
			return "", errors.NewError("could not copy OpenShift configuration").WithCause(err)
		}
		err = h.updateConfig(configDir, opt.HostConfigDir, opt.RouterIP, opt.MetricsHost, opt.LoggingHost)
		if err != nil {
			cleanupConfig()
			return "", errors.NewError("could not update OpenShift configuration").WithCause(err)
		}
	}
	if nodeHost == "" {
		if opt.PortForwarding {
			var err error
			nodeHost, err = h.ServerIP()
			if err != nil {
//.........这里部分代码省略.........
开发者ID:mffiedler,项目名称:origin,代码行数:101,代码来源:helper.go


示例8: CopyMasterConfigToHost

// CopyMasterConfigToHost copies a local file to the Docker host
func (h *HostHelper) CopyMasterConfigToHost(sourceFile, destDir string) error {
	localDir, err := makeTempCopy(sourceFile)
	if err != nil {
		return err
	}
	tarHelper := tarhelper.New()
	tarHelper.SetExclusionPattern(nil)
	var tarLog io.Writer
	if glog.V(5) {
		tarLog = os.Stderr
	}
	localTarFile, err := ioutil.TempFile("", "master-config")
	if err != nil {
		return err
	}
	localTarClosed := false
	defer func() {
		if !localTarClosed {
			errors.LogError(localTarFile.Close())
		}
	}()
	glog.V(4).Infof("Creating temporary tar %s to upload to %s", localTarFile.Name(), destDir)
	err = tarHelper.CreateTarStreamWithLogging(localDir, false, localTarFile, tarLog)
	if err != nil {
		return err
	}
	err = localTarFile.Close()
	if err != nil {
		return err
	}
	localTarClosed = true
	localTarInputClosed := false
	localTarInput, err := os.Open(localTarFile.Name())
	if err != nil {
		return err
	}
	defer func() {
		if !localTarInputClosed {
			localTarInput.Close()
		}
	}()
	bind := fmt.Sprintf("%s:/var/lib/origin/openshift.local.config:z", destDir)
	container, err := h.runner().
		Image(h.image).
		Bind(bind).Create()
	_ = container
	if err != nil {
		return err
	}
	defer func() {
		errors.LogError(h.client.RemoveContainer(docker.RemoveContainerOptions{ID: container}))
	}()

	glog.V(4).Infof("Uploading tar file %s to remote dir: %s", localTarFile.Name(), destDir)
	err = h.client.UploadToContainer(container, docker.UploadToContainerOptions{
		InputStream: localTarInput,
		Path:        "/var/lib/origin/openshift.local.config/master",
	})
	if err != nil {
		glog.V(4).Infof("An error occurred uploading the file: %v", err)
	} else {
		// If the upload succeeded the local input stream will be closed automatically
		localTarInputClosed = true
		glog.V(4).Infof("Successfully uploaded file.")
	}
	return err
}
开发者ID:Xmagicer,项目名称:origin,代码行数:68,代码来源:host.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang errors.NewError函数代码示例发布时间:2022-05-28
下一篇:
Golang dockerhelper.NewHelper函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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