本文整理汇总了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
}
开发者ID:MerlinDMC,项目名称:machine,代码行数:34,代码来源:vcloudair.go
示例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
}
开发者ID:MerlinDMC,项目名称:machine,代码行数:35,代码来源:vcloudair.go
示例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
}
开发者ID:cdosso,项目名称:machine,代码行数:55,代码来源:vcloudair.go
示例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
}
开发者ID:cdosso,项目名称:machine,代码行数:44,代码来源:vcloudair.go
示例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
}
开发者ID:cdosso,项目名称:machine,代码行数:76,代码来源:vcloudair.go
示例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()
//.........这里部分代码省略.........
开发者ID:cdosso,项目名称:machine,代码行数:101,代码来源:vcloudair.go
示例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()
//.........这里部分代码省略.........
开发者ID:Aorjoa,项目名称:Machine-Aiyara,代码行数:101,代码来源:vcloudair.go
注:本文中的github.com/vmware/govcloudair.NewClient函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论