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


Golang log.WithField函数代码示例

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


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

示例1: Remove

// Remove deletes a machine and it's SSH keys from OVH Cloud
func (d *Driver) Remove() error {
	log.WithField("MachineId", d.InstanceID).Debug("deleting instance...")
	log.Info("Deleting OVH instance...")

	client := d.getClient()

	// Deletes instance
	err := client.DeleteInstance(d.ProjectID, d.InstanceID)
	if err != nil {
		return err
	}

	// If key name  does not starts with the machine ID, this is a pre-existing key, keep it
	if !strings.HasPrefix(d.KeyPairName, d.MachineName) {
		log.WithField("KeyPairID", d.KeyPairID).Debug("keeping key pair...")
		return nil
	}

	// Deletes ssh key
	log.WithField("KeyPairID", d.KeyPairID).Debug("deleting key pair...")
	err = client.DeleteSshkey(d.ProjectID, d.KeyPairID)
	if err != nil {
		return err
	}

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

示例2: assignFloatingIP

func (d *Driver) assignFloatingIP() error {
	var err error

	if d.ComputeNetwork {
		err = d.initCompute()
	} else {
		err = d.initNetwork()
	}

	if err != nil {
		return err
	}

	ips, err := d.client.GetFloatingIPs(d)
	if err != nil {
		return err
	}

	var floatingIP *FloatingIP

	log.WithFields(log.Fields{
		"MachineId": d.MachineId,
		"Pool":      d.FloatingIpPool,
	}).Debugf("Looking for an available floating IP")

	for _, ip := range ips {
		if ip.PortId == "" {
			log.WithFields(log.Fields{
				"MachineId": d.MachineId,
				"IP":        ip.Ip,
			}).Debugf("Available floating IP found")
			floatingIP = &ip
			break
		}
	}

	if floatingIP == nil {
		floatingIP = &FloatingIP{}
		log.WithField("MachineId", d.MachineId).Debugf("No available floating IP found. Allocating a new one...")
	} else {
		log.WithField("MachineId", d.MachineId).Debugf("Assigning floating IP to the instance")
	}

	if err := d.client.AssignFloatingIP(d, floatingIP); err != nil {
		return err
	}
	d.IPAddress = floatingIP.Ip
	return nil
}
开发者ID:rogaha,项目名称:machine,代码行数:49,代码来源:openstack.go

示例3: Remove

func (d *Driver) Remove() error {
	log.WithField("MachineId", d.MachineId).Debug("deleting instance...")
	log.Info("Deleting OpenStack instance...")
	if err := d.initCompute(); err != nil {
		return err
	}
	if err := d.client.DeleteInstance(d); err != nil {
		return err
	}
	log.WithField("Name", d.KeyPairName).Debug("deleting key pair...")
	if err := d.client.DeleteKeyPair(d, d.KeyPairName); err != nil {
		return err
	}
	return nil
}
开发者ID:chuchengcao,项目名称:machine,代码行数:15,代码来源:openstack.go

示例4: waitForInstanceActive

func (d *Driver) waitForInstanceActive() error {
	log.WithField("MachineId", d.MachineId).Debug("Waiting for the OpenStack instance to be ACTIVE...")
	if err := d.client.WaitForInstanceStatus(d, "ACTIVE"); err != nil {
		return err
	}
	return nil
}
开发者ID:chuchengcao,项目名称:machine,代码行数:7,代码来源:openstack.go

示例5: GetState

func (d *Driver) GetState() (state.State, error) {
	log.WithField("MachineId", d.MachineId).Debug("Get status for OpenStack instance...")
	if err := d.initCompute(); err != nil {
		return state.None, err
	}

	s, err := d.client.GetInstanceState(d)
	if err != nil {
		return state.None, err
	}

	log.WithFields(log.Fields{
		"MachineId": d.MachineId,
		"State":     s,
	}).Debug("State for OpenStack instance")

	switch s {
	case "ACTIVE":
		return state.Running, nil
	case "PAUSED":
		return state.Paused, nil
	case "SUSPENDED":
		return state.Saved, nil
	case "SHUTOFF":
		return state.Stopped, nil
	case "BUILDING":
		return state.Starting, nil
	case "ERROR":
		return state.Error, nil
	}
	return state.None, nil
}
开发者ID:chuchengcao,项目名称:machine,代码行数:32,代码来源:openstack.go

示例6: GetIP

func (d *Driver) GetIP() (string, error) {
	if d.IPAddress != "" {
		return d.IPAddress, nil
	}

	log.WithField("MachineId", d.MachineId).Debug("Looking for the IP address...")

	if err := d.initCompute(); err != nil {
		return "", err
	}

	addressType := Fixed
	if d.FloatingIpPool != "" {
		addressType = Floating
	}

	// Looking for the IP address in a retry loop to deal with OpenStack latency
	for retryCount := 0; retryCount < 200; retryCount++ {
		addresses, err := d.client.GetInstanceIpAddresses(d)
		if err != nil {
			return "", err
		}
		for _, a := range addresses {
			if a.AddressType == addressType && a.Version == d.IpVersion {
				return a.Address, nil
			}
		}
		time.Sleep(2 * time.Second)
	}
	return "", fmt.Errorf("No IP found for the machine")
}
开发者ID:chuchengcao,项目名称:machine,代码行数:31,代码来源:openstack.go

示例7: GetState

// GetState return instance status
func (d *Driver) GetState() (state.State, error) {
	log.WithField("MachineId", d.InstanceID).Debug("Get status for OVH instance...")

	client := d.getClient()

	instance, err := client.GetInstance(d.ProjectID, d.InstanceID)
	if err != nil {
		return state.None, err
	}

	log.WithFields(log.Fields{
		"MachineId": d.InstanceID,
		"State":     instance.Status,
	}).Debug("State for OVH instance")

	switch instance.Status {
	case "ACTIVE":
		return state.Running, nil
	case "PAUSED":
		return state.Paused, nil
	case "SUSPENDED":
		return state.Saved, nil
	case "SHUTOFF":
		return state.Stopped, nil
	case "BUILDING":
		return state.Starting, nil
	case "ERROR":
		return state.Error, nil
	}

	return state.None, nil
}
开发者ID:thbkrkr,项目名称:docker-machine-driver-ovh,代码行数:33,代码来源:driver.go

示例8: Restart

func (d *Driver) Restart() error {
	log.WithField("MachineId", d.MachineId).Info("Restarting OpenStack instance...")
	if err := d.initCompute(); err != nil {
		return err
	}
	if err := d.client.RestartInstance(d); err != nil {
		return err
	}
	return nil
}
开发者ID:chuchengcao,项目名称:machine,代码行数:10,代码来源:openstack.go

示例9: Restart

// Restart this docker-machine
func (d *Driver) Restart() error {
	log.WithField("MachineId", d.InstanceID).Info("Restarting OVH instance...")

	client := d.getClient()

	err := client.RebootInstance(d.ProjectID, d.InstanceID, false)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:thbkrkr,项目名称:docker-machine-driver-ovh,代码行数:12,代码来源:driver.go

示例10: Create

// Create a new docker machine instance on OVH Cloud
func (d *Driver) Create() error {
	client := d.getClient()

	// Ensure ssh key
	err := d.ensureSSHKey()
	if err != nil {
		return err
	}

	// Create instance
	log.Debug("Creating OVH instance...")
	instance, err := client.CreateInstance(
		d.ProjectID,
		d.MachineName,
		d.KeyPairID,
		d.FlavorID,
		d.ImageID,
		d.RegionName,
		false,
	)
	if err != nil {
		return err
	}
	d.InstanceID = instance.Id

	// Wait until instance is ACTIVE
	log.WithField("MachineId", d.InstanceID).Debug("Waiting for OVH instance...")
	instance, err = d.waitForInstanceStatus("ACTIVE")
	if err != nil {
		return err
	}

	// Save Ip address
	d.IPAddress = ""
	for _, ip := range instance.IpAddresses {
		if ip.Type == "public" {
			d.IPAddress = ip.Ip
			break
		}
	}

	if d.IPAddress == "" {
		return fmt.Errorf("No IP found for instance %s", instance.Id)
	}

	log.WithFields(log.Fields{
		"IP":        d.IPAddress,
		"MachineId": d.InstanceID,
	}).Debug("IP address found")

	// All done !
	return nil
}
开发者ID:thbkrkr,项目名称:docker-machine-driver-ovh,代码行数:54,代码来源:driver.go

示例11: ensureSSHKey

// ensureSSHKey makes sure an SSH key for the machine exists with requested name
func (d *Driver) ensureSSHKey() error {
	client := d.getClient()

	// Attempt to get an existing key
	log.WithField("Name", d.KeyPairName).Debug("Checking Key Pair...")
	sshKey, _ := client.GetSshkeyByName(d.ProjectID, d.RegionName, d.KeyPairName)
	if sshKey != nil {
		d.KeyPairID = sshKey.Id
		log.Debug("Found key id ", d.KeyPairID)
		return nil
	}

	// Generate key and parent dir if needed
	log.WithField("Name", d.KeyPairName).Debug("Creating Key Pair...")
	keyfile := d.GetSSHKeyPath()
	keypath := filepath.Dir(keyfile)
	err := os.MkdirAll(keypath, 0700)
	if err != nil {
		return err
	}

	err = ssh.GenerateSSHKey(d.GetSSHKeyPath())
	if err != nil {
		return err
	}
	publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
	if err != nil {
		return err
	}

	// Upload key
	sshKey, err = client.CreateSshkey(d.ProjectID, d.KeyPairName, string(publicKey))
	if err != nil {
		return err
	}
	d.KeyPairID = sshKey.Id

	log.Debug("Created key id ", d.KeyPairID)
	return nil
}
开发者ID:thbkrkr,项目名称:docker-machine-driver-ovh,代码行数:41,代码来源:driver.go

示例12: createSSHKey

func (d *Driver) createSSHKey() error {
	log.WithField("Name", d.KeyPairName).Debug("Creating Key Pair...")
	if err := ssh.GenerateSSHKey(d.GetSSHKeyPath()); err != nil {
		return err
	}
	publicKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
	if err != nil {
		return err
	}

	if err := d.initCompute(); err != nil {
		return err
	}
	if err := d.client.CreateKeyPair(d, d.KeyPairName, string(publicKey)); err != nil {
		return err
	}
	return nil
}
开发者ID:chuchengcao,项目名称:machine,代码行数:18,代码来源:openstack.go

示例13: waitForInstanceStatus

// waitForInstanceStatus waits until instance reaches status. Copied from openstack Driver
func (d *Driver) waitForInstanceStatus(status string) (instance *Instance, err error) {
	return instance, mcnutils.WaitForSpecificOrError(func() (bool, error) {
		instance, err = d.client.GetInstance(d.ProjectID, d.InstanceID)
		if err != nil {
			return true, err
		}
		log.WithField("MachineId", d.InstanceID).Debugf("Machine state: %s", instance.Status)

		if instance.Status == "ERROR" {
			return true, fmt.Errorf("Instance creation failed. Instance is in ERROR state")
		}

		if instance.Status == status {
			return true, nil
		}

		return false, nil
	}, (statusTimeout / 4), 4*time.Second)
}
开发者ID:thbkrkr,项目名称:docker-machine-driver-ovh,代码行数:20,代码来源:driver.go


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