本文整理匯總了Golang中github.com/docker/machine/log.Infof函數的典型用法代碼示例。如果您正苦於以下問題:Golang Infof函數的具體用法?Golang Infof怎麽用?Golang Infof使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Infof函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Create
func (d *Driver) Create() error {
spec := d.buildHostSpec()
log.Infof("Creating SSH key...")
key, err := d.createSSHKey()
if err != nil {
return err
}
log.Infof("SSH key %s (%d) created in SoftLayer", key.Label, key.Id)
d.SSHKeyID = key.Id
spec.SshKeys = []*SshKey{key}
id, err := d.getClient().VirtualGuest().Create(spec)
if err != nil {
return fmt.Errorf("Error creating host: %q", err)
}
d.Id = id
d.getIp()
d.waitForStart()
d.waitForSetupTransactions()
return nil
}
示例2: ClientOK
func ClientOK(endpoint string, test func() bool) error {
backoff := util.Backoff{}
defer backoff.Close()
var err error
retry := false
for ok := range backoff.Start() {
if !ok {
err = fmt.Errorf("Timeout waiting for Docker at %s", endpoint)
break
}
if test() {
break
}
retry = true
log.Infof("Waiting for Docker at %s", endpoint)
}
if err != nil {
return err
}
if retry {
log.Infof("Connected to Docker at %s", endpoint)
}
return nil
}
示例3: Create
func (d *Driver) Create() error {
log.Infof("Creating SSH key...")
key, err := d.createSSHKey()
if err != nil {
return err
}
d.SSHKeyID = key.ID
var sshKey *godo.DropletCreateSSHKey
sshKey = &godo.DropletCreateSSHKey{ID: d.SSHKeyID}
log.Infof("Creating Digital Ocean droplet...")
client := d.getClient()
createRequest := &godo.DropletCreateRequest{
Image: godo.DropletCreateImage{Slug: "digitalocean-image"},
Name: d.MachineName,
Region: d.Region,
Size: d.Size,
IPv6: d.IPv6,
PrivateNetworking: d.PrivateNetworking,
Backups: d.Backups,
SSHKeys: []godo.DropletCreateSSHKey{*sshKey},
}
newDroplet, _, err := client.Droplets.Create(createRequest)
if err != nil {
return err
}
d.DropletID = newDroplet.ID
droplets, _, err := client.Droplets.List(nil)
if err != nil {
return err
}
for _, n := range droplets {
for _, network := range n.Networks.V4 {
if network.Type == "public" {
d.IPAddress = network.IPAddress
}
}
if d.IPAddress != "" {
break
}
time.Sleep(1 * time.Second)
}
log.Debugf("Created droplet ID %d, IP address %s",
newDroplet.ID,
d.IPAddress)
return nil
}
示例4: CopyIsoToMachineDir
func (b *B2dUtils) CopyIsoToMachineDir(isoURL, machineName string) error {
machinesDir := GetMachineDir()
machineIsoPath := filepath.Join(machinesDir, machineName, b.isoFilename)
// just in case the cache dir has been manually deleted,
// check for it and recreate it if it's gone
if _, err := os.Stat(b.imgCachePath); os.IsNotExist(err) {
log.Infof("Image cache does not exist, creating it at %s...", b.imgCachePath)
if err := os.Mkdir(b.imgCachePath, 0700); err != nil {
return err
}
}
// By default just copy the existing "cached" iso to
// the machine's directory...
if isoURL == "" {
if err := b.copyDefaultIsoToMachine(machineIsoPath); err != nil {
return err
}
} else {
// But if ISO is specified go get it directly
log.Infof("Downloading %s from %s...", b.isoFilename, isoURL)
if err := b.DownloadISO(filepath.Join(machinesDir, machineName), b.isoFilename, isoURL); err != nil {
return err
}
}
return nil
}
示例5: deleteInstance
// deleteInstance deletes the instance, leaving the persistent disk.
func (c *ComputeUtil) deleteInstance() error {
log.Infof("Deleting instance.")
op, err := c.service.Instances.Delete(c.project, c.zone, c.instanceName).Do()
if err != nil {
return err
}
log.Infof("Waiting for instance to delete.")
return c.waitForRegionalOp(op.Name)
}
示例6: deleteDisk
// deleteDisk deletes the persistent disk.
func (c *ComputeUtil) deleteDisk() error {
log.Infof("Deleting disk.")
op, err := c.service.Disks.Delete(c.project, c.zone, c.diskName()).Do()
if err != nil {
return err
}
log.Infof("Waiting for disk to delete.")
return c.waitForRegionalOp(op.Name)
}
示例7: Create
func (d *Driver) Create() error {
log.Infof("Creating SSH key...")
key, err := d.createSSHKey()
if err != nil {
return err
}
d.SSHKeyID = key.ID
log.Infof("Creating Digital Ocean droplet...")
client := d.getClient()
createRequest := &godo.DropletCreateRequest{
Image: d.Image,
Name: d.MachineName,
Region: d.Region,
Size: d.Size,
IPv6: d.IPv6,
PrivateNetworking: d.PrivateNetworking,
Backups: d.Backups,
SSHKeys: []interface{}{d.SSHKeyID},
}
newDroplet, _, err := client.Droplets.Create(createRequest)
if err != nil {
return err
}
d.DropletID = newDroplet.Droplet.ID
for {
newDroplet, _, err = client.Droplets.Get(d.DropletID)
if err != nil {
return err
}
for _, network := range newDroplet.Droplet.Networks.V4 {
if network.Type == "public" {
d.IPAddress = network.IPAddress
}
}
if d.IPAddress != "" {
break
}
time.Sleep(1 * time.Second)
}
log.Debugf("Created droplet ID %d, IP address %s",
newDroplet.Droplet.ID,
d.IPAddress)
return nil
}
示例8: Restart
func (d *Driver) Restart() error {
p, err := govcloudair.NewClient()
if err != nil {
return err
}
log.Infof("Connecting to vCloud Air...")
// Authenticate to vCloud Air
v, err := p.Authenticate(d.UserName, d.UserPassword, d.ComputeID, d.VDCID)
if err != nil {
return err
}
vapp, err := v.FindVAppByID(d.VAppID)
if err != nil {
return err
}
status, err := vapp.GetStatus()
if err != nil {
return err
}
if status == "POWERED_ON" {
// If it's powered on, restart the machine
log.Infof("Restarting %s...", d.MachineName)
task, err := vapp.Reset()
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
} else {
// If it's not powered on, start it.
log.Infof("Docker host %s is powered off, powering it back on...", d.MachineName)
task, err := vapp.PowerOn()
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
}
if err = p.Disconnect(); err != nil {
return err
}
d.IPAddress, err = d.GetIP()
return err
}
示例9: saveToken
func saveToken(storePath string, token *oauth.Token) {
tokenPath := path.Join(storePath, "gce_token")
log.Infof("Saving token in %v", tokenPath)
f, err := os.Create(tokenPath)
if err != nil {
log.Infof("Warning: failed to cache oauth token: %v", err)
return
}
defer f.Close()
gob.NewEncoder(f).Encode(token)
}
示例10: setupCertificates
func setupCertificates(caCertPath, caKeyPath, clientCertPath, clientKeyPath string) error {
org := utils.GetUsername()
bits := 2048
if _, err := os.Stat(utils.GetMachineCertDir()); err != nil {
if os.IsNotExist(err) {
if err := os.MkdirAll(utils.GetMachineCertDir(), 0700); err != nil {
log.Fatalf("Error creating machine config dir: %s", err)
}
} else {
log.Fatal(err)
}
}
if _, err := os.Stat(caCertPath); os.IsNotExist(err) {
log.Infof("Creating CA: %s", caCertPath)
// check if the key path exists; if so, error
if _, err := os.Stat(caKeyPath); err == nil {
log.Fatalf("The CA key already exists. Please remove it or specify a different key/cert.")
}
if err := utils.GenerateCACertificate(caCertPath, caKeyPath, org, bits); err != nil {
log.Infof("Error generating CA certificate: %s", err)
}
}
if _, err := os.Stat(clientCertPath); os.IsNotExist(err) {
log.Infof("Creating client certificate: %s", clientCertPath)
if _, err := os.Stat(utils.GetMachineCertDir()); err != nil {
if os.IsNotExist(err) {
if err := os.Mkdir(utils.GetMachineCertDir(), 0700); err != nil {
log.Fatalf("Error creating machine client cert dir: %s", err)
}
} else {
log.Fatal(err)
}
}
// check if the key path exists; if so, error
if _, err := os.Stat(clientKeyPath); err == nil {
log.Fatalf("The client key already exists. Please remove it or specify a different key/cert.")
}
if err := utils.GenerateCert([]string{""}, clientCertPath, clientKeyPath, caCertPath, caKeyPath, org, bits); err != nil {
log.Fatalf("Error generating client certificate: %s", err)
}
}
return nil
}
示例11: Start
func (d *Driver) Start() error {
machineState, err := d.GetState()
if err != nil {
return err
}
switch machineState {
case state.Running:
log.Infof("VM %s has already been started", d.MachineName)
return nil
case state.Stopped:
// TODO add transactional or error handling in the following steps
vcConn := NewVcConn(d)
err := vcConn.VMPowerOn()
if err != nil {
return err
}
// this step waits for the vm to start and fetch its ip address;
// this guarantees that the opem-vmtools has started working...
_, err = vcConn.VMFetchIP()
if err != nil {
return err
}
d.IPAddress, err = d.GetIP()
return err
}
return errors.NewInvalidStateError(d.MachineName)
}
示例12: DatastoreMkdir
func (conn VcConn) DatastoreMkdir(dirName string) error {
_, err := conn.DatastoreLs(dirName)
if err == nil {
return nil
}
log.Infof("Creating directory %s on datastore %s of vCenter %s... ",
dirName, conn.driver.Datastore, conn.driver.IP)
args := []string{"datastore.mkdir"}
args = conn.AppendConnectionString(args)
args = append(args, fmt.Sprintf("--ds=%s", conn.driver.Datastore))
args = append(args, fmt.Sprintf("--dc=%s", conn.driver.Datacenter))
args = append(args, dirName)
_, stderr, err := govcOutErr(args...)
if stderr != "" {
return errors.NewDatastoreError(conn.driver.Datastore, "mkdir", stderr)
}
if err != nil {
return err
}
return nil
}
示例13: VMCreate
func (conn VcConn) VMCreate(isoPath string) error {
log.Infof("Creating virtual machine %s of vCenter %s... ",
conn.driver.MachineName, conn.driver.IP)
args := []string{"vm.create"}
args = conn.AppendConnectionString(args)
args = append(args, fmt.Sprintf("--net=%s", conn.driver.Network))
args = append(args, fmt.Sprintf("--dc=%s", conn.driver.Datacenter))
args = append(args, fmt.Sprintf("--ds=%s", conn.driver.Datastore))
args = append(args, fmt.Sprintf("--iso=%s", isoPath))
memory := strconv.Itoa(conn.driver.Memory)
args = append(args, fmt.Sprintf("--m=%s", memory))
cpu := strconv.Itoa(conn.driver.CPU)
args = append(args, fmt.Sprintf("--c=%s", cpu))
args = append(args, "--disk.controller=pvscsi")
args = append(args, "--net.adapter=vmxnet3")
args = append(args, "--on=false")
if conn.driver.Pool != "" {
args = append(args, fmt.Sprintf("--pool=%s", conn.driver.Pool))
}
if conn.driver.HostIP != "" {
args = append(args, fmt.Sprintf("--host.ip=%s", conn.driver.HostIP))
}
args = append(args, conn.driver.MachineName)
_, stderr, err := govcOutErr(args...)
if stderr == "" && err == nil {
return nil
}
return errors.NewVMError("create", conn.driver.MachineName, stderr)
}
示例14: Start
func (d *Driver) Start() error {
log.Infof("Starting %s...", d.MachineName)
vmrun("start", d.vmxPath(), "nogui")
// Do not execute the rest of boot2docker specific configuration, exit here
if d.ConfigDriveURL != "" {
log.Debugf("Leaving start sequence early, configdrive found")
return nil
}
log.Debugf("Mounting Shared Folders...")
var shareName, shareDir string // TODO configurable at some point
switch runtime.GOOS {
case "darwin":
shareName = "Users"
shareDir = "/Users"
// TODO "linux" and "windows"
}
if shareDir != "" {
if _, err := os.Stat(shareDir); err != nil && !os.IsNotExist(err) {
return err
} else if !os.IsNotExist(err) {
// create mountpoint and mount shared folder
vmrun("-gu", B2DUser, "-gp", B2DPass, "runScriptInGuest", d.vmxPath(), "/bin/sh", "sudo mkdir "+shareDir+" && sudo mount -t vmhgfs .host:/"+shareName+" "+shareDir)
}
}
return nil
}
示例15: waitForSetupTransactions
func (d *Driver) waitForSetupTransactions() {
log.Infof("Waiting for host setup transactions to complete")
// sometimes we'll hit a case where there's no active transaction, but if
// we check again in a few seconds, it moves to the next transaction. We
// don't want to get false-positives, so we check a few times in a row to make sure!
noActiveCount, maxNoActiveCount := 0, 3
for {
t, err := d.GetActiveTransaction()
if err != nil {
noActiveCount = 0
log.Debugf("Failed to GetActiveTransaction - %+v", err)
continue
}
if t == "" {
if noActiveCount == maxNoActiveCount {
break
}
noActiveCount++
} else {
noActiveCount = 0
log.Debugf("Still waiting - active transaction is %s...", t)
}
time.Sleep(2 * time.Second)
}
}