本文整理匯總了Golang中github.com/docker/machine/libmachine/log.Infof函數的典型用法代碼示例。如果您正苦於以下問題:Golang Infof函數的具體用法?Golang Infof怎麽用?Golang Infof使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Infof函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Create
func (d *Driver) Create() error {
client, err := d.getClient()
if err != nil {
return err
}
log.Infof("Creating SSH key...")
err = d.createSSHkey()
if err != nil {
return err
}
userdata, err := d.getCloudInit()
if err != nil {
return err
}
encoded := base64.StdEncoding.EncodeToString(userdata)
d.UserData = &encoded
log.Infof("Creating Brightbox Server...")
log.Debugf("with the following Userdata")
log.Debugf("%s", string(userdata))
log.Debugf("Brightbox API Call: Create Server using image %s", d.Image)
server, err := client.CreateServer(&d.ServerOptions)
if err != nil {
return err
}
d.MachineID = server.Id
return nil
}
示例2: Remove
func (d *Driver) Remove() error {
s, err := d.GetState()
if err != nil {
if err == ErrMachineNotExist {
log.Infof("machine does not exist, assuming it has been removed already")
return nil
}
return err
}
if s == state.Running {
if err := d.Stop(); err != nil {
return err
}
}
if err := d.removeDiskImage(); err != nil {
return err
}
if d.NFSShare {
log.Infof("Remove NFS share folder must be root. Please insert root password.")
if _, err := nfsexports.Remove("", d.nfsExportIdentifier()); err != nil {
log.Errorf("failed removing nfs share: %s", err.Error())
}
if err := nfsexports.ReloadDaemon(); err != nil {
log.Errorf("failed reload nfs daemon: %s", err.Error())
}
}
return nil
}
示例3: SubmitPowerState
// Submit desired power state
func (pt *PowerTask) SubmitPowerState(s PowerState) {
if err := pt.GetCurrentPowerState(); err != nil {
pt.TaskIsDone = true
log.Errorf("Error getting current power state: %s", err)
return
}
if s != pt.State {
log.Infof("Powering %s server %s for %s.", s, pt.Blade.Name, pt.Blade.SerialNumber)
var (
body = PowerRequest{PowerState: s.String(), PowerControl: P_PRESSANDHOLD.String()}
uri = strings.Join([]string{pt.Blade.URI.String(),
"/powerState"}, "")
)
log.Debugf("REST : %s \n %+v\n", uri, body)
log.Debugf("pt -> %+v", pt)
data, err := pt.Blade.Client.RestAPICall(rest.PUT, uri, body)
if err != nil {
pt.TaskIsDone = true
log.Errorf("Error with power state request: %s", err)
return
}
log.Debugf("SubmitPowerState %s", data)
if err := json.Unmarshal([]byte(data), &pt); err != nil {
pt.TaskIsDone = true
log.Errorf("Error with power state un-marshal: %s", err)
return
}
} else {
log.Infof("Desired Power State already set -> %s", pt.State)
pt.TaskIsDone = true
}
return
}
示例4: PowerExecutor
// Submit desired power state and wait
// Most of our concurrency will happen in PowerExecutor
func (pt *PowerTask) PowerExecutor(s PowerState) error {
currenttime := 0
pt.State = P_UKNOWN
pt.ResetTask()
go pt.SubmitPowerState(s)
for !pt.TaskIsDone && (currenttime < pt.Timeout) {
if err := pt.GetCurrentTaskStatus(); err != nil {
return err
}
if pt.URI != "" && T_COMPLETED.Equal(pt.TaskState) {
pt.TaskIsDone = true
}
if pt.URI != "" {
log.Debugf("Waiting to set power state %s for blade %s, %s", s, pt.Blade.Name)
log.Infof("Working on power state,%d%%, %s.", pt.ComputedPercentComplete, pt.TaskStatus)
} else {
log.Info("Working on power state.")
}
// wait time before next check
time.Sleep(time.Millisecond * (1000 * pt.WaitTime)) // wait 10sec before checking the status again
currenttime++
}
if !(currenttime < pt.Timeout) {
log.Warnf("Power %s state timed out for %s.", s, pt.Blade.Name)
}
log.Infof("Power Task Execution Completed")
return nil
}
示例5: mountShareFolder
func (d *Driver) mountShareFolder(shareName string, mountPoint string) error {
// Check the host path is available
if _, err := os.Stat(mountPoint); err != nil {
if os.IsNotExist(err) {
log.Infof("Host path '%s' does not exist. Skipping mount to VM...", mountPoint)
return nil
}
return err
}
// Ensure that share is available on the guest side
checkCmd := "sudo modprobe prl_fs && grep -w " + shareName + " /proc/fs/prl_fs/sf_list"
if _, err := drivers.RunSSHCommandFromDriver(d, checkCmd); err != nil {
log.Infof("Shared folder '%s' is unavailable. Skipping mount to VM...", shareName)
return nil
}
// Mount shared folder
mountCmd := "sudo mkdir -p " + mountPoint + " && sudo mount -t prl_fs " + shareName + " " + mountPoint
if _, err := drivers.RunSSHCommandFromDriver(d, mountCmd); err != nil {
return fmt.Errorf("Error mounting shared folder: %s", err)
}
return nil
}
示例6: PreCreateCheck
// PreCreateCheck is called to enforce pre-creation steps
func (d *Driver) PreCreateCheck() error {
c, err := newComputeUtil(d)
if err != nil {
return err
}
// Check that the project exists. It will also check the credentials
// at the same time.
log.Infof("Check that the project exists")
if _, err = c.service.Projects.Get(d.Project).Do(); err != nil {
return fmt.Errorf("Project with ID %q not found. %v", d.Project, err)
}
// Check if the instance already exists. There will be an error if the instance
// doesn't exist, so just check instance for nil.
log.Infof("Check if the instance already exists")
instance, _ := c.instance()
if d.UseExisting {
if instance == nil {
return fmt.Errorf("Unable to find instance %q in zone %q.", d.MachineName, d.Zone)
}
} else {
if instance != nil {
return fmt.Errorf("Instance %q already exists in zone %q.", d.MachineName, d.Zone)
}
}
return nil
}
示例7: Remove
func (d *Driver) Remove() error {
client := d.getClient()
log.Debugf("removing %s", d.MachineName)
if err := client.DeleteServer(d.MachineID); err != nil {
if strings.Contains(err.Error(), "Invalid server") {
log.Infof("VPS doesn't exist, assuming it is already deleted")
} else {
return err
}
}
if err := client.DeleteSSHKey(d.SSHKeyID); err != nil {
if strings.Contains(err.Error(), "Invalid SSH Key") {
log.Infof("SSH key doesn't exist, assuming it is already deleted")
} else {
return err
}
}
if d.ScriptID != 0 && !d.HasCustomScript {
if err := client.DeleteStartupScript(strconv.Itoa(d.ScriptID)); err != nil {
if strings.Contains(err.Error(), "Check SCRIPTID") {
log.Infof("PXE boot script doesn't exist, assuming it is already deleted")
} else {
return err
}
}
}
return nil
}
示例8: 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
}
示例9: Stop
func (d *Driver) Stop() error {
currentState, err := d.GetState()
if err != nil {
return err
}
if currentState == state.Paused {
if err := d.vbm("controlvm", d.MachineName, "resume"); err != nil { // , "--type", "headless"
return err
}
log.Infof("Resuming VM ...")
}
if err := d.vbm("controlvm", d.MachineName, "acpipowerbutton"); err != nil {
return err
}
for {
s, err := d.GetState()
if err != nil {
return err
}
if s == state.Running {
time.Sleep(1 * time.Second)
} else {
break
}
}
log.Infof("Stopping VM...")
d.IPAddress = ""
return nil
}
示例10: CopyIsoToMachineDir
func (b *B2dUtils) CopyIsoToMachineDir(isoURL, machineName string) error {
// TODO: This is a bit off-color.
machineDir := filepath.Join(b.storePath, "machines", machineName)
machineIsoPath := filepath.Join(machineDir, 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 {
//if ISO is specified, check if it matches a github releases url or fallback
//to a direct download
if downloadUrl, err := b.GetLatestBoot2DockerReleaseURL(isoURL); err == nil {
log.Infof("Downloading %s from %s...", b.isoFilename, downloadUrl)
if err := b.DownloadISO(machineDir, b.isoFilename, downloadUrl); err != nil {
return err
}
} else {
return err
}
}
return nil
}
示例11: Start
func (h *Host) Start() error {
log.Infof("Starting %q...", h.Name)
if err := h.runActionForState(h.Driver.Start, state.Running); err != nil {
return err
}
log.Infof("Machine %q was started.", h.Name)
return nil
}
示例12: Stop
func (h *Host) Stop() error {
log.Infof("Stopping %q...", h.Name)
if err := h.runActionForState(h.Driver.Stop, state.Stopped); err != nil {
return err
}
log.Infof("Machine %q was stopped.", h.Name)
return nil
}
示例13: Kill
func (h *Host) Kill() error {
log.Infof("Killing %q...", h.Name)
if err := h.runActionForState(h.Driver.Kill, state.Stopped); err != nil {
return err
}
log.Infof("Machine %q was killed.", h.Name)
return nil
}
示例14: 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
log.Info("Waiting for IP address to be assigned to the Droplet...")
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
}
示例15: 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)
}