split into functions

This commit is contained in:
LizaTretyakova 2017-04-12 13:51:28 +03:00
parent f70754e0e1
commit b77e77168a
1 changed files with 20 additions and 11 deletions

31
main.go
View File

@ -12,17 +12,7 @@ import (
"github.com/vmware/govmomi/vim25/mo" "github.com/vmware/govmomi/vim25/mo"
) )
func main() { func authentificate(URL, username, password string) (*govmomi.Client, context.Context) {
var URL = os.Args[1]
var username = os.Args[2]
var password = os.Args[3]
var dc_name = os.Args[6]
var vm_name = os.Args[4]
var cpus, err = strconv.Atoi(os.Args[5])
if err != nil {
panic(err)
}
// create context // create context
ctx := context.TODO() // an empty, default context (for those, who is unsure) ctx := context.TODO() // an empty, default context (for those, who is unsure)
@ -40,6 +30,10 @@ func main() {
panic(err) panic(err)
} }
return client, ctx
}
func reconfigureVM(client *govmomi.Client, ctx context.Context, dc_name, vm_name string, cpus int) {
// Create a finder to search for a vm with the specified name // Create a finder to search for a vm with the specified name
finder := find.NewFinder(client.Client, false) finder := find.NewFinder(client.Client, false)
// Need to specify the datacenter // Need to specify the datacenter
@ -81,3 +75,18 @@ func main() {
panic(err) panic(err)
} }
} }
func main() {
var URL = os.Args[1]
var username = os.Args[2]
var password = os.Args[3]
var dc_name = os.Args[6]
var vm_name = os.Args[4]
var cpus, err = strconv.Atoi(os.Args[5])
if err != nil {
panic(err)
}
client, ctx := authentificate(URL, username, password)
reconfigureVM(client, ctx, dc_name, vm_name, cpus)
}