Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vcentercli #1408

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Vcentercli #1408

wants to merge 3 commits into from

Conversation

sherpaurgen
Copy link

Description

A simple go client for using vcenter/vmware REST api which can help you if you need to turn on/off multiple machines + check machines power status.

You need to have the api username and password to use this tool

Sample user/pass json file

cat ~/.vmwarepass.json
{
"host":"host1.virtualdc.local",
"username":"[email protected]",
"secret":"wli#Lol-2Gbv#"
}

First clone the repo and run build

cd into /path/to/repo

go build

#Usage -help :

./vcenterapi -h   //display help
2022/03/01 14:05:36 Connection successful vsph.virtualdc.com:443
Usage of ./vcenterapi:
-list
Lists available virtual machines
-start
start vm700 vm701 #starts vms with vmid vm700 vm701
-stop
stop vm10 vm31 #stops vms with vmid vm10 vm31

List vm's & get the vmid eg.

Output order - vmid , vmName,PoweredState , Memory(MB) , Num of cpu

./vcenterapi -list | grep "192.45.9.19" 

vm-236,Normal_Windows_192.45.9.191,POWERED_OFF,mem:32768,cpu:16

vm-138,Normal_Windows_192.45.9.192,POWERED_OFF,POWERED_OFF,mem:32168,cpu:18

vm-182,Normal_Windows_192.45.9.193,POWERED_OFF,POWERED_ON,mem:4096,cpu:8

Start vm's

./vcenterapi -start vm-24949 vm-51499 vm-51500 vm-51501 vm-51502 vm-51503 vm-5646 vm-69521
2022/03/01 20:42:36 Connection was successful :vsph.virtualdc.com:443
2022/03/01 20:42:36 [vm-24949 vm-51499 vm-51500 vm-51501 vm-51502 vm-51503 vm-5646 vm-69521]
2022/03/01 20:42:39 &{0x1120700 {0xc000114ab0} 0x11d0ee0} 204
2022/03/01 20:42:39 Machine/s started successfully.
2022/03/01 20:42:39 &{0x1120700 {0xc000114ab0} 0x11d0ee0} 204
2022/03/01 20:42:39 Machine/s started successfully.
2022/03/01 20:42:39 &{0x1120700 {0xc000240f20} 0x11d0ee0} 400
2022/03/01 20:42:39 Problem starting vm-5646, already in poweredOn state.
2022/03/01 20:42:40 &{0x1120700 {0xc000114ab0} 0x11d0ee0} 204
2022/03/01 20:42:40 Machine/s started successfully.
2022/03/01 20:42:40 &{0x1120700 {0xc000114ab0} 0x11d0ee0} 204
2022/03/01 20:42:40 Machine/s started successfully.
2022/03/01 20:42:40 &{0x1120700 {0xc000114ab0} 0x11d0ee0} 204
2022/03/01 20:42:40 Machine/s started successfully.
2022/03/01 20:42:40 &{0x1120700 {0xc000114ab0} 0x11d0ee0} 204
2022/03/01 20:42:40 Machine/s started successfully.
2022/03/01 20:42:40 &{0x1120700 {0xc000114ab0} 0x11d0ee0} 204
2022/03/01 20:42:40 Machine/s started successfully.

Shutting down one or more vm's

./vcenterapi -stop vm-51502 vm-5646 vm-69521
2022/03/01 01:34:45 [vm-51502 vm-5646 vm-69521]
2022/03/01 01:34:47 &{0x1120700 {0xc000100ab0} 0x11d0e00} 204
2022/03/01 01:34:47 &{0x1120700 {0xc000100ab0} 0x11d0e00} 204
2022/03/01 01:34:47 Machine/s stopped successfully.
2022/03/01 01:34:47 Machine/s stopped successfully.
2022/03/01 01:34:47 &{0x1120700 {0xc000100ab0} 0x11d0e00} 204
2022/03/01 01:34:47 Machine/s stopped successfully.

if machines are already in powered off the o/p is likely to be eg.:

2022/03/01 01:36:46 &{0x1120700 {0xc0001f6c60} 0x11d0e00} 400
2022/03/01 01:36:46 Problem stopping vm-5646, already in off state.

Terms and its meaning:

* ESXi is a product which provides virtualization.
* Vsphere is the name givne to the bundle of all features in the new version (ESXi, vcenter and its features so on).So ESXi is one of the product in vsphere.

@github-actions
Copy link

PR is not linked to any issue, please make the corresponding changes in the body. The issue should look like this. For help follow this link

@ghost
Copy link

ghost commented Oct 20, 2022

👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant