本文整理汇总了Golang中github.com/docker/machine/log.WithField函数的典型用法代码示例。如果您正苦于以下问题:Golang WithField函数的具体用法?Golang WithField怎么用?Golang WithField使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WithField函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}
示例4: 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 {
return a.Address, nil
}
}
time.Sleep(2 * time.Second)
}
return "", fmt.Errorf("No IP found for the machine")
}
示例5: assignFloatingIp
func (d *Driver) assignFloatingIp() error {
if err := d.initNetwork(); err != nil {
return err
}
portId, err := d.client.GetInstancePortId(d)
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, portId); err != nil {
return err
}
d.IPAddress = floatingIp.Ip
return nil
}
示例6: 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
}
示例7: 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
}