本文整理汇总了Golang中github.com/vmware/govcloudair.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Kill
func (d *Driver) Kill() 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
}
task, err := vapp.PowerOff()
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
if err = p.Disconnect(); err != nil {
return err
}
d.IPAddress = ""
return nil
}
示例2: GetState
func (d *Driver) GetState() (state.State, error) {
p, err := govcloudair.NewClient()
if err != nil {
return state.Error, err
}
log.Debug("Connecting to vCloud Air to fetch vApp Status...")
// Authenticate to vCloud Air
v, err := p.Authenticate(d.UserName, d.UserPassword, d.ComputeID, d.VDCID)
if err != nil {
return state.Error, err
}
vapp, err := v.FindVAppByID(d.VAppID)
if err != nil {
return state.Error, err
}
status, err := vapp.GetStatus()
if err != nil {
return state.Error, err
}
if err = p.Disconnect(); err != nil {
return state.Error, err
}
switch status {
case "POWERED_ON":
return state.Running, nil
case "POWERED_OFF":
return state.Stopped, nil
}
return state.None, nil
}
示例3: 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
}
示例4: Stop
func (d *Driver) Stop() 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" {
log.Infof("Shutting down %s...", d.MachineName)
task, err := vapp.Shutdown()
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
}
if err = p.Disconnect(); err != nil {
return err
}
d.IPAddress = ""
return nil
}
示例5: Remove
func (d *Driver) Remove() 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
}
// Find our Edge Gateway
edge, err := v.FindEdgeGateway(d.EdgeGateway)
if err != nil {
return err
}
vapp, err := v.FindVAppByID(d.VAppID)
if err != nil {
log.Infof("Can't find the vApp, assuming it was deleted already...")
return nil
}
status, err := vapp.GetStatus()
if err != nil {
return err
}
log.Infof("Removing NAT and Firewall Rules on %s...", d.EdgeGateway)
task, err := edge.Remove1to1Mapping(vapp.VApp.Children.VM[0].NetworkConnectionSection.NetworkConnection.IPAddress, d.PublicIP)
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
if status == "POWERED_ON" {
// If it's powered on, power it off before deleting
log.Infof("Powering Off %s...", d.MachineName)
task, err = vapp.PowerOff()
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
}
log.Debugf("Undeploying %s...", d.MachineName)
task, err = vapp.Undeploy()
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
log.Infof("Deleting %s...", d.MachineName)
task, err = vapp.Delete()
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
if err = p.Disconnect(); err != nil {
return err
}
return nil
}
示例6: Create
func (d *Driver) Create() error {
key, err := d.createSSHKey()
if err != nil {
return err
}
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
}
// Find VDC Network
net, err := v.FindVDCNetwork(d.OrgVDCNet)
if err != nil {
return err
}
// Find our Edge Gateway
edge, err := v.FindEdgeGateway(d.EdgeGateway)
if err != nil {
return err
}
// Get the Org our VDC belongs to
org, err := v.GetVDCOrg()
if err != nil {
return err
}
// Find our Catalog
cat, err := org.FindCatalog(d.Catalog)
if err != nil {
return err
}
// Find our Catalog Item
cati, err := cat.FindCatalogItem(d.CatalogItem)
if err != nil {
return err
}
// Fetch the vApp Template in the Catalog Item
vapptemplate, err := cati.GetVAppTemplate()
if err != nil {
return err
}
// Create a new empty vApp
vapp := govcloudair.NewVApp(p)
log.Infof("Creating a new vApp: %s...", d.MachineName)
// Compose the vApp with ComposeVApp
task, err := vapp.ComposeVApp(net, vapptemplate, d.MachineName, "Container Host created with Docker Host")
if err != nil {
return err
}
// Wait for the creation to be completed
if err = task.WaitTaskCompletion(); err != nil {
return err
}
task, err = vapp.ChangeCPUcount(d.CPUCount)
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
task, err = vapp.ChangeMemorySize(d.MemorySize)
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
sshCustomScript := "echo \"" + strings.TrimSpace(key) + "\" > /root/.ssh/authorized_keys"
task, err = vapp.RunCustomizationScript(d.MachineName, sshCustomScript)
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
task, err = vapp.PowerOn()
//.........这里部分代码省略.........
示例7: Create
func (d *Driver) Create() error {
key, err := d.createSSHKey()
if err != nil {
return err
}
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
}
// Find VDC Network
net, err := v.FindVDCNetwork(d.OrgVDCNet)
if err != nil {
return err
}
// Find our Edge Gateway
edge, err := v.FindEdgeGateway(d.EdgeGateway)
if err != nil {
return err
}
// Get the Org our VDC belongs to
org, err := v.GetVDCOrg()
if err != nil {
return err
}
// Find our Catalog
cat, err := org.FindCatalog(d.Catalog)
if err != nil {
return err
}
// Find our Catalog Item
cati, err := cat.FindCatalogItem(d.CatalogItem)
if err != nil {
return err
}
// Fetch the vApp Template in the Catalog Item
vapptemplate, err := cati.GetVAppTemplate()
if err != nil {
return err
}
// Create a new empty vApp
vapp := govcloudair.NewVApp(p)
log.Infof("Creating a new vApp: %s...", d.MachineName)
// Compose the vApp with ComposeVApp
task, err := vapp.ComposeVApp(net, vapptemplate, d.MachineName, "Container Host created with Docker Host")
if err != nil {
return err
}
// Wait for the creation to be completed
if err = task.WaitTaskCompletion(); err != nil {
return err
}
task, err = vapp.ChangeCPUcount(d.CPUCount)
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
task, err = vapp.ChangeMemorySize(d.MemorySize)
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
sshCustomScript := "echo \"" + strings.TrimSpace(key) + "\" > /root/.ssh/authorized_keys"
task, err = vapp.RunCustomizationScript(d.MachineName, sshCustomScript)
if err != nil {
return err
}
if err = task.WaitTaskCompletion(); err != nil {
return err
}
task, err = vapp.PowerOn()
//.........这里部分代码省略.........