本文整理匯總了Golang中github.com/docker/machine/libmachine/log.Debug函數的典型用法代碼示例。如果您正苦於以下問題:Golang Debug函數的具體用法?Golang Debug怎麽用?Golang Debug使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Debug函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: execServer
func (lbp *LocalBinaryPlugin) execServer() error {
outScanner, errScanner, err := lbp.Executor.Start()
if err != nil {
return err
}
// Scan just one line to get the address, then send it to the relevant
// channel.
outScanner.Scan()
addr := outScanner.Text()
if err := outScanner.Err(); err != nil {
return fmt.Errorf("Reading plugin address failed: %s", err)
}
lbp.addrCh <- strings.TrimSpace(addr)
stdOutCh, stopStdoutCh := lbp.AttachStream(outScanner)
stdErrCh, stopStderrCh := lbp.AttachStream(errScanner)
for {
select {
case out := <-stdOutCh:
log.Debug(fmt.Sprintf(pluginOutPrefix, lbp.MachineName), out)
case err := <-stdErrCh:
log.Debug(fmt.Sprintf(pluginErrPrefix, lbp.MachineName), err)
case _ = <-lbp.stopCh:
stopStdoutCh <- true
stopStderrCh <- true
if err := lbp.Executor.Close(); err != nil {
return fmt.Errorf("Error closing local plugin binary: %s", err)
}
return nil
}
}
}
示例2: findStorageAccount
func (a AzureClient) findStorageAccount(resourceGroup, location, prefix string, storageType storage.AccountType) (*storage.AccountProperties, error) {
f := logutil.Fields{
"type": storageType,
"prefix": prefix,
"location": location}
log.Debug("Querying existing storage accounts.", f)
l, err := a.storageAccountsClient().ListByResourceGroup(resourceGroup)
if err != nil {
return nil, err
}
if l.Value != nil {
for _, v := range *l.Value {
log.Debug("Iterating...", logutil.Fields{
"name": to.String(v.Name),
"type": storageType,
"location": to.String(v.Location),
})
if to.String(v.Location) == location && v.Properties.AccountType == storageType && strings.HasPrefix(to.String(v.Name), prefix) {
log.Debug("Found eligible storage account.", logutil.Fields{"name": to.String(v.Name)})
return v.Properties, nil
}
}
}
log.Debug("No account matching the pattern is found.", f)
return nil, err
}
示例3: enableBasicAuthForWinRM
func (provisioner *WindowsProvisioner) enableBasicAuthForWinRM() bool {
log.Debug("Enabling basic auth for WinRM")
ip, err := provisioner.Driver.GetIP()
if err != nil {
return false
}
d := provisioner.Driver
stdout, stderr, exit, err := drivers.WinRMRunCmdWithNTLM(ip,
d.GetSSHUsername(),
d.GetSSHPassword(),
enableBasicAuthCmd)
if (err != nil) || (exit != 0) {
log.Warn("Error getting WinRM command to enable basic auth:", err)
log.Debug("Enable basic auth output:", stdout, ", err:", stderr, ", exit:", exit)
return false
}
stdout, stderr, exit, err = drivers.WinRMRunCmdWithNTLM(ip,
d.GetSSHUsername(),
d.GetSSHPassword(),
enableUnencryptedCmd)
if (err != nil) || (exit != 0) {
log.Warn("Error getting WinRM command to enable unencrypted comm:", err)
log.Debug("Enable unencrypted comm output:", stdout, ", err:", stderr, ", exit:", exit)
return false
}
// The daemon is up if the command worked. Carry on.
log.Debug("Successfully enabled basic auth for WinRM")
return true
}
示例4: TestSaveServer
// TestSaveServer implement save server
func TestSaveServer(t *testing.T) {
var (
d *ICSPTest
c *icsp.ICSPClient
)
if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
log.Debug("implements acceptance test for TestCreateServer")
d, c = getTestDriverA()
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
// get a Server
serialNumber := d.Tc.GetTestData(d.Env, "FreeBladeSerialNumber").(string)
s, err := c.GetServerBySerialNumber(serialNumber)
assert.NoError(t, err, "GetServerBySerialNumber threw error -> %s, %+v\n", err, s)
// set a custom attribute
s.SetCustomAttribute("docker_user", "server", "docker")
// use test keys like from https://github.com/mitchellh/vagrant/tree/master/keys
// private key from https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant
s.SetCustomAttribute("public_key", "server", "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==")
// save a server
news, err := c.SaveServer(s)
assert.NoError(t, err, "SaveServer threw error -> %s, %+v\n", err, news)
assert.Equal(t, s.UUID, news.UUID, "Should return a server with the same UUID")
// verify that the server attribute was saved by getting the server again and checking the value
_, testValue2 := s.GetValueItem("docker_user", "server")
assert.Equal(t, "docker", testValue2.Value, "Should return the saved custom attribute")
} else {
log.Debug("implements unit test for TestCreateServer")
var s icsp.Server
_, c = getTestDriverU()
s, err := c.SaveServer(s)
assert.Error(t, err, "SaveServer threw error -> %s, %+v\n", err, s)
}
}
示例5: TestGetPublicIPV4
// func (s Server) GetPublicIPV4() (string, error) {
// TestGetPublicIPV4 try to test for getting interface from custom attribute
func TestGetPublicIPV4(t *testing.T) {
var (
d *ICSPTest
c *icsp.ICSPClient
serialNumber string
)
if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
log.Debug("implements acceptance test for TestGetPublicIPV4")
d, c = getTestDriverA()
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
if os.Getenv("ONEVIEW_TEST_PROVISION") == "true" {
serialNumber = d.Tc.GetTestData(d.Env, "FreeICSPSerialNumber").(string)
} else {
serialNumber = d.Tc.GetTestData(d.Env, "SerialNumber").(string)
}
s, err := c.GetServerBySerialNumber(serialNumber)
testIP, err := s.GetPublicIPV4()
assert.NoError(t, err, "Should GetPublicIPV4 without error -> %s, %+v\n", err, s)
log.Debugf(" testIP -> %s", testIP)
assert.True(t, (len(testIP) > 0), "Should return an ip address string")
} else {
// TODO: implement a test
// need to simplate createing public_interface custom attribute object
// need to read custom attribute object, see server_customattribute_test.go
log.Debug("implements unit test for TestGetPublicIPV4")
}
}
示例6: stackAvailable
func (d *Driver) stackAvailable() (bool, error) {
log.Debug("Checking if the stack is available......")
svc := cloudformation.New(session.New())
params := &cloudformation.DescribeStacksInput{
StackName: aws.String(d.MachineName),
}
resp, err := svc.DescribeStacks(params)
log.Debug(resp)
if err != nil {
return false, err
}
if *resp.Stacks[0].StackStatus == cloudformation.StackStatusRollbackInProgress || *resp.Stacks[0].StackStatus == cloudformation.StackStatusRollbackComplete {
return false, errors.New("Stack Rollback Occured")
}
if *resp.Stacks[0].StackStatus == cloudformation.StackStatusCreateComplete {
return true, nil
} else {
log.Debug("Stack Not Available Yet")
return false, nil
}
}
示例7: GetState
func (d *Driver) GetState() (state.State, error) {
log.Debug("Get status for OpenStack instance...", map[string]string{"MachineId": d.MachineId})
if err := d.initCompute(); err != nil {
return state.None, err
}
s, err := d.client.GetInstanceState(d)
if err != nil {
return state.None, err
}
log.Debug("State for OpenStack instance", map[string]string{
"MachineId": d.MachineId,
"State": s,
})
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
}
示例8: Create
func (d *Driver) Create() error {
if err := d.setUserSubscription(); err != nil {
return err
}
log.Info("Creating Azure machine...")
vmConfig, err := vmClient.CreateAzureVMConfiguration(d.MachineName, d.Size, d.Image, d.Location)
if err != nil {
return err
}
log.Debug("Generating certificate for Azure...")
if err := d.generateCertForAzure(); err != nil {
return err
}
log.Debug("Adding Linux provisioning...")
vmConfig, err = vmClient.AddAzureLinuxProvisioningConfig(vmConfig, d.GetSSHUsername(), d.UserPassword, d.azureCertPath(), d.SSHPort)
if err != nil {
return err
}
log.Debug("Authorizing ports...")
if err := d.addDockerEndpoints(vmConfig); err != nil {
return err
}
log.Debug("Creating VM...")
if err := vmClient.CreateAzureVM(vmConfig, d.MachineName, d.Location); err != nil {
return err
}
return nil
}
示例9: MakeDiskImage
// MakeDiskImage makes a boot2docker VM disk image.
// See https://github.com/boot2docker/boot2docker/blob/master/rootfs/rootfs/etc/rc.d/automount
func MakeDiskImage(publicSSHKeyPath string) (*bytes.Buffer, error) {
magicString := "boot2docker, please format-me"
buf := new(bytes.Buffer)
tw := tar.NewWriter(buf)
// magicString first so the automount script knows to format the disk
file := &tar.Header{Name: magicString, Size: int64(len(magicString))}
log.Debug("Writing magic tar header")
if err := tw.WriteHeader(file); err != nil {
return nil, err
}
if _, err := tw.Write([]byte(magicString)); err != nil {
return nil, err
}
// .ssh/key.pub => authorized_keys
file = &tar.Header{Name: ".ssh", Typeflag: tar.TypeDir, Mode: 0700}
if err := tw.WriteHeader(file); err != nil {
return nil, err
}
log.Debug("Writing SSH key tar header")
pubKey, err := ioutil.ReadFile(publicSSHKeyPath)
if err != nil {
return nil, err
}
file = &tar.Header{Name: ".ssh/authorized_keys", Size: int64(len(pubKey)), Mode: 0644}
if err := tw.WriteHeader(file); err != nil {
return nil, err
}
if _, err := tw.Write([]byte(pubKey)); err != nil {
return nil, err
}
file = &tar.Header{Name: ".ssh/authorized_keys2", Size: int64(len(pubKey)), Mode: 0644}
if err := tw.WriteHeader(file); err != nil {
return nil, err
}
if _, err := tw.Write([]byte(pubKey)); err != nil {
return nil, err
}
if err := tw.Close(); err != nil {
return nil, err
}
return buf, nil
}
示例10: TestApplyDeploymentJobs
// integrated acceptance test
// TestSaveServer implement save server
//TODO: a workaround to figuring out how to bubble up public ip address information from the os to icsp after os build plan provisioning
// @[email protected] "@[email protected]" @[email protected] "@[email protected]" "@[email protected]" "@[email protected]"
func TestApplyDeploymentJobs(t *testing.T) {
var (
d *ICSPTest
c *ICSPClient
serialNumber string
)
if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
log.Debug("implements acceptance test for ApplyDeploymentJobs")
d, c = getTestDriverA()
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
// get a Server
osBuildPlans := make([]string, 1)
osBuildPlans[0] = d.Tc.GetTestData(d.Env, "OSBuildPlan").(string)
if os.Getenv("ONEVIEW_TEST_PROVISION") != "true" {
serialNumber = d.Tc.GetTestData(d.Env, "SerialNumber").(string)
} else {
serialNumber = d.Tc.GetTestData(d.Env, "FreeICSPSerialNumber").(string)
}
s, err := c.GetServerBySerialNumber(serialNumber)
assert.NoError(t, err, "GetServerBySerialNumber threw error -> %s, %+v\n", err, s)
// set a custom attribute
s.SetCustomAttribute("docker_user", "server", "docker")
s.SetCustomAttribute("docker_hostname", "server", d.Tc.GetTestData(d.Env, "HostName").(string))
// use test keys like from https://github.com/mitchellh/vagrant/tree/master/keys
// private key from https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant
s.SetCustomAttribute("public_key", "server", "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ==")
// save a server
news, err := c.SaveServer(s)
assert.NoError(t, err, "SaveServer threw error -> %s, %+v\n", err, news)
assert.Equal(t, s.UUID, news.UUID, "Should return a server with the same UUID")
// verify that the server attribute was saved by getting the server again and checking the value
_, testValue2 := s.GetValueItem("docker_user", "server")
assert.Equal(t, "docker", testValue2.Value, "Should return the saved custom attribute")
if os.Getenv("ONEVIEW_TEST_PROVISION") != "true" {
log.Info("env ONEVIEW_TEST_PROVISION != ture for ApplyDeploymentJobs")
log.Infof("Skipping OS build for : %s, %s", osBuildPlans, serialNumber)
return
}
_, err = c.ApplyDeploymentJobs(osBuildPlans, nil, s)
assert.NoError(t, err, "ApplyDeploymentJobs threw error -> %s, %+v\n", err, news)
} else {
var s Server
_, c = getTestDriverU()
log.Debug("implements unit test for ApplyDeploymentJobs")
testPlans := make([]string, 1)
testPlans[0] = "testbuildplan"
_, err := c.ApplyDeploymentJobs(testPlans, nil, s)
assert.Error(t, err, "ApplyDeploymentJobs threw error -> %s, %+v\n", err, s)
}
}
示例11: instanceIsRunning
func (d *Driver) instanceIsRunning() bool {
st, err := d.GetState()
if err != nil {
log.Debug(err)
}
if st == state.Running {
return true
}
log.Debug("VPS not yet started")
return false
}
示例12: Close
func (c *RpcClientDriver) Close() error {
log.Debug("Making call to close driver server")
if err := c.Client.Call("RpcServerDriver.Close", struct{}{}, nil); err != nil {
return err
}
log.Debug("Successfully made call to close driver server")
return nil
}
示例13: generateDiskImage
// Make a boot2docker VM disk image.
func (d *Driver) generateDiskImage(size int) error {
log.Debugf("Creating %d MB hard disk image...", size)
magicString := "boot2docker, please format-me"
buf := new(bytes.Buffer)
tw := tar.NewWriter(buf)
// magicString first so the automount script knows to format the disk
file := &tar.Header{Name: magicString, Size: int64(len(magicString))}
log.Debug("Writing magic tar header")
if err := tw.WriteHeader(file); err != nil {
return err
}
if _, err := tw.Write([]byte(magicString)); err != nil {
return err
}
// .ssh/key.pub => authorized_keys
file = &tar.Header{Name: ".ssh", Typeflag: tar.TypeDir, Mode: 0700}
if err := tw.WriteHeader(file); err != nil {
return err
}
log.Debug("Writing SSH key tar header")
pubKey, err := ioutil.ReadFile(d.publicSSHKeyPath())
if err != nil {
return err
}
file = &tar.Header{Name: ".ssh/authorized_keys", Size: int64(len(pubKey)), Mode: 0644}
if err := tw.WriteHeader(file); err != nil {
return err
}
if _, err := tw.Write([]byte(pubKey)); err != nil {
return err
}
file = &tar.Header{Name: ".ssh/authorized_keys2", Size: int64(len(pubKey)), Mode: 0644}
if err := tw.WriteHeader(file); err != nil {
return err
}
if _, err := tw.Write([]byte(pubKey)); err != nil {
return err
}
if err := tw.Close(); err != nil {
return err
}
raw := bytes.NewReader(buf.Bytes())
log.Debug("Calling inner createDiskImage")
return createDiskImage(d.diskPath(), size, raw)
}
示例14: getIPfromDHCPLease
func (d *Driver) getIPfromDHCPLease() (string, error) {
var dhcpfh *os.File
var dhcpcontent []byte
// var macaddr string
var err error
var lastipmatch string
var currentip string
// DHCP lease table for NAT vmnet interface
var dhcpfile = "/var/db/dhcpd_leases"
if dhcpfh, err = os.Open(dhcpfile); err != nil {
return "", err
}
defer dhcpfh.Close()
if dhcpcontent, err = ioutil.ReadAll(dhcpfh); err != nil {
return "", err
}
// Get the IP from the lease table.
leaseip := regexp.MustCompile(`^\s*ip_address=(.+?)$`)
log.Debug(leaseip) // TODO
// Get the MAC address associated.
// leasemac := regexp.MustCompile(`^\s*hw_address=1,(.+?)$`)
// log.Debug(leasemac) // TODO
for _, line := range strings.Split(string(dhcpcontent), "\n") {
// if matches := leasemac.FindStringSubmatch(line); matches != nil {
// currentip = lastipmatch
// // macaddr = matches[1]
// log.Debug(macaddr)
// break
// }
if matches := leaseip.FindStringSubmatch(line); matches != nil {
lastipmatch = matches[1]
log.Debug(lastipmatch)
break
}
}
//
// if currentip == "" {
// return "", fmt.Errorf("IP not found for MAC %s in DHCP leases", leaseip)
// }
//
// if macaddr == "" {
// return "", fmt.Errorf("couldn't find MAC address in DHCP leases file %s", dhcpfile)
// }
log.Debugf("IP found in DHCP lease table: %s", currentip)
return currentip, nil
}
示例15: TestGetInterfaces
// TestGetInterfaces verify that interfaces works
func TestGetInterfaces(t *testing.T) {
var (
d *ICSPTest
c *icsp.ICSPClient
s icsp.Server
serialNumber string
err error
)
if os.Getenv("ICSP_TEST_ACCEPTANCE") == "true" {
log.Debug("implements acceptance test for TestGetInterfaces")
d, c = getTestDriverA()
if c == nil {
t.Fatalf("Failed to execute getTestDriver() ")
}
if os.Getenv("ONEVIEW_TEST_PROVISION") == "true" {
serialNumber = d.Tc.GetTestData(d.Env, "FreeBladeSerialNumber").(string)
s, err = c.GetServerBySerialNumber(serialNumber)
} else {
serialNumber = d.Tc.GetTestData(d.Env, "SerialNumber").(string)
s, err = c.GetServerBySerialNumber(serialNumber)
}
data := s.GetInterfaces()
assert.NoError(t, err, "GetInterfaces threw error -> %s, %+v\n", err, data)
assert.True(t, len(data) > 0, "Failed to get a valid list of interfaces -> %+v", data)
for _, inet := range data {
log.Infof("inet -> %+v", inet)
log.Infof("inet ip -> %+v", inet.IPV4Addr)
log.Infof("inet ip -> %+v", inet.Slot)
log.Infof("inet ip -> %+v", inet.MACAddr)
}
} else {
log.Debug("implements unit test for TestGetInterfaces")
d, c = getTestDriverU()
jsonServerData := d.Tc.GetTestData(d.Env, "ServerJSONString").(string)
log.Debugf("jsonServerData => %s", jsonServerData)
err := json.Unmarshal([]byte(jsonServerData), &s)
assert.NoError(t, err, "Unmarshal Server threw error -> %s, %+v\n", err, jsonServerData)
log.Debugf("server -> %v", s)
data := s.GetInterfaces()
log.Debugf("Interfaces -> %+v", data)
assert.True(t, len(data) > 0, "Failed to get a valid list of interfaces -> %+v", data)
for _, inet := range data {
log.Debugf("inet -> %+v", inet)
log.Debugf("inet ip -> %+v", inet.IPV4Addr)
log.Debugf("inet ip -> %+v", inet.Slot)
log.Debugf("inet ip -> %+v", inet.MACAddr)
}
}
}