本文整理汇总了Golang中github.com/vmware/photon-controller-cli/photon/client.GetClient函数的典型用法代码示例。如果您正苦于以下问题:Golang GetClient函数的具体用法?Golang GetClient怎么用?Golang GetClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deploymentMigrationFinalizeDeprecated
// Finishes the copy state of source system into destination and makes this system the active one
func deploymentMigrationFinalizeDeprecated(c *cli.Context) error {
fmt.Printf("'%d'", len(c.Args()))
err := checkArgNum(c.Args(), 1, "system migration finalize <old_management_endpoint>")
if err != nil {
return err
}
sourceAddress := c.Args().First()
client.Esxclient, err = client.GetClient(c.GlobalIsSet("non-interactive"))
if err != nil {
return err
}
deployments, err := client.Esxclient.Deployments.GetAll()
if err != nil {
return err
}
finalizeMigrationSpec := photon.FinalizeMigrationOperation{}
finalizeMigrationSpec.SourceLoadBalancerAddress = sourceAddress
// Finalize deployment migration
for _, deployment := range deployments.Items {
finalizeMigrate, err := client.Esxclient.Deployments.FinalizeDeploymentMigration(&finalizeMigrationSpec, deployment.ID)
if err != nil {
return err
}
_, err = pollTask(finalizeMigrate.ID)
if err != nil {
return err
}
return nil
}
return nil
}
示例2: addHosts
// Add most hosts in batch mode
func addHosts(c *cli.Context) error {
err := checkArgNum(c.Args(), 1, "system addHosts <file>")
if err != nil {
return err
}
file := c.Args().First()
dcMap, err := manifest.LoadInstallation(file)
if err != nil {
return err
}
client.Esxclient, err = client.GetClient(false)
if err != nil {
return err
}
deployments, err := client.Esxclient.Deployments.GetAll()
deploymentID := deployments.Items[0].ID
// Create Hosts
err = createHostsInBatch(dcMap, deploymentID)
if err != nil {
return err
}
return nil
}
示例3: deploymentMigrationPrepareDeprecated
// Starts the recurring copy state of source system into destination
func deploymentMigrationPrepareDeprecated(c *cli.Context) error {
err := checkArgNum(c.Args(), 1, "system migration prepare <old_management_endpoint>")
if err != nil {
return err
}
sourceAddress := c.Args().First()
client.Esxclient, err = client.GetClient(c.GlobalIsSet("non-interactive"))
if err != nil {
return err
}
deployments, err := client.Esxclient.Deployments.GetAll()
if err != nil {
return err
}
initializeMigrationSpec := photon.InitializeMigrationOperation{}
initializeMigrationSpec.SourceLoadBalancerAddress = sourceAddress
// Initialize deployment migration
for _, deployment := range deployments.Items {
initializeMigrate, err := client.Esxclient.Deployments.InitializeDeploymentMigration(&initializeMigrationSpec, deployment.ID)
if err != nil {
return err
}
_, err = pollTask(initializeMigrate.ID)
if err != nil {
return err
}
fmt.Printf("Deployment '%s' migration started [source management endpoint: '%s'].\n", deployment.ID, sourceAddress)
return nil
}
return nil
}
示例4: listTasks
// Retrieves a list of tasks, returns an error if one occurred
func listTasks(c *cli.Context) error {
err := checkArgNum(c.Args(), 0, "task list <options>")
if err != nil {
return err
}
entityId := c.String("entityId")
entityKind := c.String("entityKind")
state := c.String("state")
client.Esxclient, err = client.GetClient(c.GlobalIsSet("non-interactive"))
if err != nil {
return err
}
options := &photon.TaskGetOptions{
State: state,
EntityID: entityId,
EntityKind: entityKind,
}
taskList, err := client.Esxclient.Tasks.GetAll(options)
if err != nil {
return err
}
err = printTaskList(taskList.Items, c)
if err != nil {
return err
}
return nil
}
示例5: deploy
// Deploy Photon Controller based on DC_map
func deploy(c *cli.Context) error {
err := checkArgNum(c.Args(), 1, "system deploy <file>")
if err != nil {
return err
}
file := c.Args().First()
dcMap, err := manifest.LoadInstallation(file)
if err != nil {
return err
}
client.Esxclient, err = client.GetClient(false)
if err != nil {
return err
}
deploymentID, err := createDeploymentFromDcMap(dcMap)
if err != nil {
return err
}
// Create Hosts
err = createHostsFromDcMap(dcMap, deploymentID)
if err != nil {
return err
}
// Deploy
err = doDeploy(dcMap, deploymentID)
if err != nil {
return err
}
return nil
}
示例6: monitorTask
// Track the progress of the task, returns an error if one occurred
func monitorTask(c *cli.Context) error {
err := checkArgNum(c.Args(), 1, "task monitor <task id>")
if err != nil {
return err
}
id := c.Args()[0]
client.Esxclient, err = client.GetClient(c.GlobalIsSet("non-interactive"))
if err != nil {
return err
}
if c.GlobalIsSet("non-interactive") {
task, err := client.Esxclient.Tasks.Wait(id)
if err != nil {
return err
}
fmt.Printf("%s\t%s\t%s\t%s\n", task.ID, task.State, task.Entity.ID, task.Entity.Kind)
} else {
task, err := pollTask(id)
if err != nil {
return err
}
w := new(tabwriter.Writer)
w.Init(os.Stdout, 4, 4, 2, ' ', 0)
fmt.Fprintf(w, "Task:\t%s\n", task.ID)
fmt.Fprintf(w, "Entity:\t%s %s\n", task.Entity.Kind, task.Entity.ID)
fmt.Fprintf(w, "State:\t%s\n", task.State)
err = w.Flush()
if err != nil {
return err
}
}
return nil
}
示例7: setHostAvailabilityZone
// Set host's availability zone with the specified host ID, returns an error if one occurred
func setHostAvailabilityZone(c *cli.Context, w io.Writer) error {
err := checkArgNum(c.Args(), 2, "host set-availability-zone <id> <availability-zone-id>")
if err != nil {
return err
}
id := c.Args().First()
availabilityZoneId := c.Args()[1]
client.Esxclient, err = client.GetClient(utils.IsNonInteractive(c))
if err != nil {
return err
}
setAvailabilityZoneSpec := photon.HostSetAvailabilityZoneOperation{}
setAvailabilityZoneSpec.AvailabilityZoneId = availabilityZoneId
setTask, err := client.Esxclient.Hosts.SetAvailabilityZone(id, &setAvailabilityZoneSpec)
if err != nil {
return err
}
id, err = waitOnTaskOperation(setTask.ID, c)
if err != nil {
return err
}
if utils.NeedsFormatting(c) {
host, err := client.Esxclient.Hosts.Get(id)
if err != nil {
return err
}
utils.FormatObject(host, w, c)
}
return nil
}
示例8: listHosts
// List all the hosts in the current deployment
// This uses the same back-end code as "deployments list-hosts", but we look up the
// deployment ID so that users don't have to specify it. In most or all installations,
// there will not be more than one deployment ID.
func listHosts(c *cli.Context, w io.Writer) error {
err := checkArgNum(c.Args(), 0, "host list")
if err != nil {
return err
}
client.Esxclient, err = client.GetClient(utils.IsNonInteractive(c))
if err != nil {
return err
}
// Find the current deployment
deployments, err := client.Esxclient.Deployments.GetAll()
if err != nil {
return err
}
numDeployments := len(deployments.Items)
if numDeployments == 0 {
return fmt.Errorf("There are no deployments, so the hosts cannot be listed.")
} else if numDeployments > 1 {
return fmt.Errorf("There are multiple deployments, which normally should not happen. Use deployments list-hosts.")
}
id := deployments.Items[0].ID
hosts, err := client.Esxclient.Deployments.GetHosts(id)
if err != nil {
return err
}
err = printHostList(hosts.Items, w, c)
if err != nil {
return err
}
return nil
}
示例9: showMigrationStatusDeprecated
// displays the migration status
func showMigrationStatusDeprecated(c *cli.Context) error {
err := checkArgNum(c.Args(), 0, "migration status")
if err != nil {
return err
}
client.Esxclient, err = client.GetClient(c.GlobalIsSet("non-interactive"))
if err != nil {
return err
}
deployments, err := client.Esxclient.Deployments.GetAll()
if err != nil {
return err
}
for _, deployment := range deployments.Items {
if deployment.Migration != nil {
migration := deployment.Migration
if c.GlobalIsSet("non-interactive") {
fmt.Printf("%d\t%d\t%d\t%d\t%d\n", migration.CompletedDataMigrationCycles, migration.DataMigrationCycleProgress,
migration.DataMigrationCycleSize, migration.VibsUploaded, migration.VibsUploading+migration.VibsUploaded)
} else {
fmt.Printf(" Migration status:\n")
fmt.Printf(" Completed data migration cycles: %d\n", migration.CompletedDataMigrationCycles)
fmt.Printf(" Current data migration cycles progress: %d / %d\n", migration.DataMigrationCycleProgress,
migration.DataMigrationCycleSize)
fmt.Printf(" VIB upload progress: %d / %d\n", migration.VibsUploaded, migration.VibsUploading+migration.VibsUploaded)
}
}
return nil
}
return nil
}
示例10: showNetwork
func showNetwork(c *cli.Context, w io.Writer) error {
err := checkArgNum(c.Args(), 1, "network show <id>")
if err != nil {
return err
}
id := c.Args().First()
client.Esxclient, err = client.GetClient(utils.IsNonInteractive(c))
if err != nil {
return err
}
network, err := client.Esxclient.Subnets.Get(id)
if err != nil {
return err
}
if c.GlobalIsSet("non-interactive") {
portGroups := getCommaSeparatedStringFromStringArray(network.PortGroups)
fmt.Printf("%s\t%s\t%s\t%s\t%s\t%t\n", network.ID, network.Name, network.State, portGroups,
network.Description, network.IsDefault)
} else if utils.NeedsFormatting(c) {
utils.FormatObject(network, w, c)
} else {
fmt.Printf("Network ID: %s\n", network.ID)
fmt.Printf(" Name: %s\n", network.Name)
fmt.Printf(" State: %s\n", network.State)
fmt.Printf(" Description: %s\n", network.Description)
fmt.Printf(" Port Groups: %s\n", network.PortGroups)
fmt.Printf(" Is Default: %t\n", network.IsDefault)
}
return nil
}
示例11: getFlavorTasks
// Retrieves tasks from specified flavor
func getFlavorTasks(c *cli.Context, w io.Writer) error {
err := checkArgNum(c.Args(), 1, "flavor tasks <id> [<options>]")
if err != nil {
return err
}
id := c.Args().First()
state := c.String("state")
options := &photon.TaskGetOptions{
State: state,
}
client.Esxclient, err = client.GetClient(utils.IsNonInteractive(c))
if err != nil {
return err
}
taskList, err := client.Esxclient.Flavors.GetTasks(id, options)
if err != nil {
return err
}
err = printTaskList(taskList.Items, c)
if err != nil {
return err
}
return nil
}
示例12: detachDisk
func detachDisk(c *cli.Context) error {
err := checkArgNum(c.Args(), 1, "vm detach-disk --disk <id> <vm-id>")
if err != nil {
return err
}
id := c.Args().First()
diskID := c.String("disk")
client.Esxclient, err = client.GetClient(c.GlobalIsSet("non-interactive"))
if err != nil {
return err
}
operation := &photon.VmDiskOperation{
DiskID: diskID,
}
task, err := client.Esxclient.VMs.DetachDisk(id, operation)
if err != nil {
return err
}
_, err = waitOnTaskOperation(task.ID, c)
if err != nil {
return err
}
return nil
}
示例13: showMigrationStatus
// displays the migration status
func showMigrationStatus(c *cli.Context) error {
id, err := getDeploymentId(c)
if err != nil {
return err
}
client.Esxclient, err = client.GetClient(c.GlobalIsSet("non-interactive"))
if err != nil {
return err
}
deployment, err := client.Esxclient.Deployments.Get(id)
if err != nil {
return err
}
if deployment.Migration == nil {
fmt.Print("No migration information available")
return nil
}
migration := deployment.Migration
if c.GlobalIsSet("non-interactive") {
fmt.Printf("%d\t%d\t%d\t%d\t%d\n", migration.CompletedDataMigrationCycles, migration.DataMigrationCycleProgress,
migration.DataMigrationCycleSize, migration.VibsUploaded, migration.VibsUploading+migration.VibsUploaded)
} else {
fmt.Printf(" Migration status:\n")
fmt.Printf(" Completed data migration cycles: %d\n", migration.CompletedDataMigrationCycles)
fmt.Printf(" Current data migration cycles progress: %d / %d\n", migration.DataMigrationCycleProgress,
migration.DataMigrationCycleSize)
fmt.Printf(" VIB upload progress: %d / %d\n", migration.VibsUploaded, migration.VibsUploading+migration.VibsUploaded)
}
return nil
}
示例14: getVMTasks
// Retrieves tasks for VM
func getVMTasks(c *cli.Context) error {
err := checkArgNum(c.Args(), 1, "vm tasks <id> [<options>]")
if err != nil {
return err
}
id := c.Args().First()
state := c.String("state")
client.Esxclient, err = client.GetClient(c.GlobalIsSet("non-interactive"))
if err != nil {
return err
}
options := &photon.TaskGetOptions{
State: state,
}
taskList, err := client.Esxclient.VMs.GetTasks(id, options)
if err != nil {
return err
}
err = printTaskList(taskList.Items, c)
if err != nil {
return err
}
return nil
}
示例15: restartVM
func restartVM(c *cli.Context) error {
err := checkArgNum(c.Args(), 1, "vm restart <id>")
if err != nil {
return err
}
id := c.Args().First()
client.Esxclient, err = client.GetClient(c.GlobalIsSet("non-interactive"))
if err != nil {
return err
}
opTask, err := client.Esxclient.VMs.Restart(id)
if err != nil {
return err
}
_, err = waitOnTaskOperation(opTask.ID, c)
if err != nil {
return err
}
return nil
}