VMware: How to install RVC with RVM
For most of my life, I have preferred the command line to a GUI. I tend to type faster than trying to interpret and click through an interface. I love VMware ESX, but I hate not being able to interfact with it as easily as something like docker. I managed to find something that had a bit more functionality out of box than trying to use the VMX API. That thing turned out to be Ruby vSphere Client(RVC).
To install RVC, first we need Ruby. But… something about building Ruby from source and dumping it on my OS feels… dirty. So lets get some organization by using Ruby Version Manager(RVM). Once we get that installed, we can install RVC.
Install Ruby Version Manager(RVM)
[root@0a11a42bdeb9 /]# yum -y install which curl ... [root@0a11a42bdeb9 /]# curl -sSL https://get.rvm.io | bash Downloading https://github.com/rvm/rvm/archive/master.tar.gz Creating group 'rvm' Installing RVM to /usr/local/rvm/ cat: /usr/local/rvm/config/alias: No such file or directory Installation of RVM in /usr/local/rvm/ is almost complete: * First you need to add all users that will be using rvm to 'rvm' group, and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`. * To start using RVM you need to run `source /etc/profile.d/rvm.sh` in all your open shell windows, in rare cases you need to reopen all shell windows. [root@0a11a42bdeb9 /]# source /etc/profile.d/rvm.sh [root@0a11a42bdeb9 /]#
We installed “which”, and “curl” since the script depends on them. Then once it was installed, we sourced the rvm.sh file to load whatever functions it may add to our profile(so we dont have to log out and log back in).
Now we need to install/select a version to use:
[root@0a11a42bdeb9 /]# rvm install 2.4.0 Searching for binary rubies, this might take some time. Found remote file https://rvm_io.global.ssl.fastly.net/binaries/centos/7/x86_64/ruby-2.4.0.tar.bz2 Checking requirements for centos. Installing requirements for centos. ... ruby-2.4.0 - #adjusting #shebangs for (gem irb erb ri rdoc testrb rake). Install of ruby-2.4.0 - #complete Please be aware that you just installed a ruby that requires 2 patches just to be compiled on an up to date linux system. This may have known and unaccounted for security vulnerabilities. Please consider upgrading to ruby-2.5.0 which will have all of the latest security patches. Ruby was built without documentation, to build it run: rvm docs generate-ri [root@0a11a42bdeb9 /]# rvm use 2.4.0 Using /usr/local/rvm/gems/ruby-2.4.0 [root@0a11a42bdeb9 /]# ruby --version ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux] [root@0a11a42bdeb9 /]#
The install part only needs to be done once. Then you simply tell RVM which one you want to use(eg: rvm use $version).
Install Ruby vSphere Client(RVC):
[root@0a11a42bdeb9 /]# gem install rvc Fetching: unicode-display_width-1.3.0.gem (100%) Successfully installed unicode-display_width-1.3.0 Fetching: terminal-table-1.8.0.gem (100%) Successfully installed terminal-table-1.8.0 Fetching: zip-2.0.2.gem (100%) Successfully installed zip-2.0.2 Fetching: highline-1.7.10.gem (100%) ... Installing ri documentation for rbvmomi-1.11.6 Parsing documentation for rvc-1.8.0 Installing ri documentation for rvc-1.8.0 Done installing documentation for unicode-display_width, terminal-table, zip, highline, backports, trollop, builder, mini_portile2, nokogiri, rbvmomi, rvc after 21 seconds 11 gems installed [root@0a11a42bdeb9 /]#
Since we selected which version of Ruby to use earlier in our session, it will also select the associated version of Gem. This allowed us to use Gem to get RVC installed.
[root@0a11a42bdeb9 /]# rvc firstname.lastname@example.org Install the "ffi" gem for better tab completion. The authenticity of host '220.127.116.11' can't be established. Public key fingerprint is 9f8d9flolea522bblol50e72a53e01242247alol1127c4becaelol5ae0702612. Are you sure you want to continue connecting (y/n)? y Warning: Permanently added '18.104.22.168' (vim) to the list of known hosts password: Welcome to RVC. Try the 'help' command. 0 / 1 22.214.171.124/ >
Now, we are logged in. The interesting thing here, is that RVC treats the options like a directory structure. We will need to cd into our datacenter, and then we can mess with specific VMs. Use the index id to the left as the directory name.
(continued from above) > cd 1 /126.96.36.199> ls 0 ha-datacenter (datacenter) /188.8.131.52> cd 0 /184.108.40.206/ha-datacenter> ls 0 storage/ 1 datastores [datastore]/ 2 computers [host]/ 3 networks [network]/ 4 vms [vm]/ /220.127.116.11/ha-datacenter> cd 4 /18.104.22.168/ha-datacenter/vms> ls 0 httpd: poweredOff 1 mail: poweredOn 2 dns: poweredOn /22.214.171.124/ha-datacenter/vms> vm. vm.annotate vm.clone vm.find vm.layout vm.modify_memory vm.ping vm.register vm.screenshot vm.ssh vm.unregister vm.answer vm.create vm.ip vm.migrate vm.off vm.rdp vm.reset vm.set_extra_config vm.standby_guest vm.wait_for_shutdown vm.bootconfig vm.extra_config vm.kill vm.modify_cpu vm.on vm.reboot_guest vm.rvc vm.shutdown_guest vm.suspend /126.96.36.199/ha-datacenter/vms> vm.on 0 PowerOnVM httpd: success /188.8.131.52/ha-datacenter/vms> vm.off 0 PowerOffVM httpd: success /184.108.40.206/ha-datacenter/vms>
As you can see above, we can use this for everything from basic power management, to cloning/creating new VMs. This is just the tip of the iceberg. You can actually do quite a bit more.
/220.127.116.11/ha-datacenter/vms> device. device.add_cdrom device.add_net device.add_serial device.connect_serial_uri device.insert_cdrom device.remove device.add_disk device.add_scsi_controller device.connect device.disconnect device.reconfig_net /18.104.22.168/ha-datacenter/vms> device.
/22.214.171.124/ha-datacenter/vms> role. role.add_privilege role.create role.delete role.get role.list role.permissions role.remove_privilege role.rename /126.96.36.199/ha-datacenter/vms> role.
/188.8.131.52/ha-datacenter/vms> host. host.add_iscsi_target host.deselect_vmknic_for_service host.enter_maintenance_mode host.exit_maintenance_mode host.reconnect host.restart_services host.add_nfs_datastore host.disconnect host.evacuate host.reboot host.rescan_storage host.select_vmknic_for_service /184.108.40.206/ha-datacenter/vms>
The rabit hole does go deeper. If you hate dealing with the vSphere GUI, I recommend giving RVC a try.