本文整理汇总了Golang中github.com/toliaqat/photon-controller/cli/photon/client.GetClient函数的典型用法代码示例。如果您正苦于以下问题:Golang GetClient函数的具体用法?Golang GetClient怎么用?Golang GetClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: monitorTask
// Track the progress of the task, returns an error if one occurred
func monitorTask(c *cli.Context) error {
err := checkArgCount(c, 1)
if err != nil {
return err
}
id := c.Args()[0]
client.Esxclient, err = client.GetClient(c)
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
}
示例2: detachDisk
func detachDisk(c *cli.Context, w io.Writer) error {
err := checkArgCount(c, 1)
if err != nil {
return err
}
id := c.Args().First()
diskID := c.String("disk")
client.Esxclient, err = client.GetClient(c)
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
}
err = formatHelper(c, w, client.Esxclient, id)
return err
}
示例3: triggerMaintenance
// Sends a cluster trigger_maintenance request to the API client based on the cli.Context.
// Returns an error if one occurred.
func triggerMaintenance(c *cli.Context) error {
err := checkArgCount(c, 1)
if err != nil {
return nil
}
clusterId := c.Args().First()
if len(clusterId) == 0 {
return fmt.Errorf("Please provide a valid cluster ID")
}
client.Esxclient, err = client.GetClient(c)
if err != nil {
return err
}
if !c.GlobalIsSet("non-interactive") {
fmt.Printf("Maintenance triggered for cluster %s\n", clusterId)
}
task, err := client.Esxclient.Clusters.TriggerMaintenance(clusterId)
if err != nil {
return err
}
_, err = waitOnTaskOperation(task.ID, c)
if err != nil {
return err
}
return nil
}
示例4: showPhysicalNetwork
func showPhysicalNetwork(c *cli.Context, w io.Writer) error {
err := checkArgCount(c, 1)
if err != nil {
return err
}
id := c.Args().First()
client.Esxclient, err = client.GetClient(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
}
示例5: deleteProject
// Sends a delete project task to client based on the cli.Context
// Returns an error if one occurred
func deleteProject(c *cli.Context) error {
err := checkArgCount(c, 1)
if err != nil {
return err
}
id := c.Args().First()
client.Esxclient, err = client.GetClient(c)
if err != nil {
return err
}
deleteTask, err := client.Esxclient.Projects.Delete(id)
if err != nil {
return err
}
_, err = waitOnTaskOperation(deleteTask.ID, c)
if err != nil {
return err
}
err = clearConfigProject(id)
if err != nil {
return err
}
return nil
}
示例6: deploymentMigrationPrepareDeprecated
// Starts the recurring copy state of source system into destination
func deploymentMigrationPrepareDeprecated(c *cli.Context) error {
err := checkArgCount(c, 1)
if err != nil {
return err
}
sourceAddress := c.Args().First()
client.Esxclient, err = client.GetClient(c)
if err != nil {
return err
}
deployments, err := client.Esxclient.Deployments.GetAll()
if err != nil {
return err
}
initializeMigrationSpec := photon.InitializeMigrationOperation{}
initializeMigrationSpec.SourceNodeGroupReference = 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
}
示例7: showMigrationStatusDeprecated
// displays the migration status
func showMigrationStatusDeprecated(c *cli.Context) error {
err := checkArgCount(c, 0)
if err != nil {
return err
}
client.Esxclient, err = client.GetClient(c)
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
}
示例8: detachIso
func detachIso(c *cli.Context, w io.Writer) error {
err := checkArgCount(c, 1)
if err != nil {
return err
}
id := c.Args().First()
client.Esxclient, err = client.GetClient(c)
if err != nil {
return err
}
task, err := client.Esxclient.VMs.DetachISO(id)
if err != nil {
return err
}
_, err = waitOnTaskOperation(task.ID, c)
if err != nil {
return err
}
err = formatHelper(c, w, client.Esxclient, id)
return err
}
示例9: listVMNetworks
func listVMNetworks(c *cli.Context, w io.Writer) error {
err := checkArgCount(c, 1)
if err != nil {
return err
}
id := c.Args().First()
client.Esxclient, err = client.GetClient(c)
if err != nil {
return err
}
networks, err := getVMNetworks(id, c)
if err != nil {
return err
}
if !utils.NeedsFormatting(c) {
err = printVMNetworks(networks, c.GlobalIsSet("non-interactive"))
if err != nil {
return err
}
} else {
utils.FormatObjects(networks, w, c)
}
return nil
}
示例10: pauseBackgroundTasks
// Sends a pause background task to client
func pauseBackgroundTasks(c *cli.Context) error {
id, err := getDeploymentId(c)
if err != nil {
return err
}
client.Esxclient, err = client.GetClient(c)
if err != nil {
return err
}
pauseBackgroundTask, err := client.Esxclient.Deployments.PauseBackgroundTasks(id)
if err != nil {
return err
}
_, err = waitOnTaskOperation(pauseBackgroundTask.ID, c)
if err != nil {
return err
}
err = deploymentJsonHelper(c, id, client.Esxclient)
if err != nil {
return err
}
return nil
}
示例11: resumeSystem
// Sends a resume system task to client
func resumeSystem(c *cli.Context) error {
id, err := getDeploymentId(c)
if err != nil {
return err
}
client.Esxclient, err = client.GetClient(c)
if err != nil {
return err
}
resumeSystemTask, err := client.Esxclient.Deployments.ResumeSystem(id)
if err != nil {
return err
}
_, err = waitOnTaskOperation(resumeSystemTask.ID, c)
if err != nil {
return err
}
err = deploymentJsonHelper(c, id, client.Esxclient)
if err != nil {
return err
}
return nil
}
示例12: syncHostsConfig
// Synchronizes hosts configurations
func syncHostsConfig(c *cli.Context) error {
id, err := getDeploymentId(c)
if err != nil {
return err
}
client.Esxclient, err = client.GetClient(c)
if err != nil {
return err
}
task, err := client.Esxclient.Deployments.SyncHostsConfig(id)
if err != nil {
return err
}
_, err = waitOnTaskOperation(task.ID, c)
if err != nil {
return err
}
err = deploymentJsonHelper(c, id, client.Esxclient)
if err != nil {
return err
}
return nil
}
示例13: listDeploymentVms
// Lists all the hosts associated with the deployment
func listDeploymentVms(c *cli.Context, w io.Writer) error {
id, err := getDeploymentId(c)
if err != nil {
return err
}
client.Esxclient, err = client.GetClient(c)
if err != nil {
return err
}
vms, err := client.Esxclient.Deployments.GetVms(id)
if err != nil {
return err
}
if utils.NeedsFormatting(c) {
utils.FormatObjects(vms, w, c)
} else {
err = printVMList(vms.Items, os.Stdout, c, false)
if err != nil {
return err
}
}
return nil
}
示例14: listTasks
// Retrieves a list of tasks, returns an error if one occurred
func listTasks(c *cli.Context) error {
err := checkArgCount(c, 0)
if err != nil {
return err
}
entityId := c.String("entityId")
entityKind := c.String("entityKind")
state := c.String("state")
client.Esxclient, err = client.GetClient(c)
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
}
示例15: deploy
// Deploy Photon Controller based on DC_map
func deploy(c *cli.Context) error {
err := checkArgCount(c, 1)
if err != nil {
return err
}
file := c.Args().First()
dcMap, err := manifest.LoadInstallation(file)
if err != nil {
return err
}
client.Esxclient, err = client.GetClient(c)
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
}