From fc1edfa23b0f8d0aab5b6eec2f79bbdb77f14991 Mon Sep 17 00:00:00 2001 From: LizaTretyakova Date: Wed, 12 Apr 2017 19:30:45 +0300 Subject: [PATCH] cosmetics --- main.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 279cd9afb..df2132773 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( "github.com/vmware/govmomi/object" ) -func authentificate(URL, username, password string) (*govmomi.Client, context.Context) { +func createClient(URL, username, password string) (*govmomi.Client, context.Context) { // create context ctx := context.TODO() // an empty, default context (for those, who is unsure) @@ -68,9 +68,8 @@ func findVM_by_name(ctx context.Context, finder *find.Finder, vm_name string) (* return vm_o, ctx } -//func reconfigureVM(ctx context.Context, vm *object.VirtualMachine, cpus int) { -func reconfigureVM(URL, username, password, dc_name, vm_name string, cpus int) { - client, ctx := authentificate(URL, username, password) +func ReconfigureVM(URL, username, password, dc_name, vm_name string, cpus int) { + client, ctx := createClient(URL, username, password) finder, ctx := createFinder(ctx, client, dc_name) vm_o, ctx := findVM_by_name(ctx, finder, vm_name) @@ -89,9 +88,9 @@ func reconfigureVM(URL, username, password, dc_name, vm_name string, cpus int) { } } -func cloneVM(URL, username, password, dc_name, folder_name, source_name, target_name string, cpus int) { - // Prepare entities: authentification, finder, folder, virtual machine - client, ctx := authentificate(URL, username, password) +func CloneVM(URL, username, password, dc_name, folder_name, source_name, target_name string, cpus int) { + // Prepare entities: client (authentification), finder, folder, virtual machine + client, ctx := createClient(URL, username, password) finder, ctx := createFinder(ctx, client, dc_name) folder, err := finder.FolderOrDefault(ctx, "") // folder_name if err != nil { @@ -124,6 +123,7 @@ func cloneVM(URL, username, password, dc_name, folder_name, source_name, target_ panic(err) } + // Just to output something for clarity vm_new_mor := info.Result.(types.ManagedObjectReference) vm_new := object.NewVirtualMachine(client.Client, vm_new_mor) var vm_new_mo mo.VirtualMachine @@ -146,5 +146,6 @@ func main() { panic(err) } - cloneVM(URL, username, password, dc_name, "", vm_name, vm_name + "_cloned", cpus) + CloneVM(URL, username, password, dc_name, "", vm_name, vm_name + "_cloned", cpus) + // ReconfigureVM(URL, username, password, dc_name, vm_name, cpus) }