Version: 1.1.0 | File Size: 54.5 KB | Upload Date: 04/8/2011
This fling is covered under the MIT License.
| 32,273 views | | | | |
|
| |
|
| |
Ruby vSphere Console (RVC) is a Linux console UI for vSphere, built on the RbVmomi bindings to the vSphere API. RVC is a console UI for VMware ESX and VirtualCenter. The vSphere object graph is presented as a virtual filesystem, allowing you to navigate and run commands against managed entities using familiar shell syntax. RVC doesn’t (yet) have every feature vSphere Client does, but for common tasks it can be much more efficient than clicking through a GUI.
Features
- Tab Completion
Commands and paths can be tab completed in the usual fashion. Whitespace must be escaped with a backslash.
- Marks
192.168.1.105:/> mark a dc/vm/foo192.168.1.105:/> on ~aPowerOnVM foo: success192.168.1.105:/> off ~aPowerOffVM foo: successMarks allow you to save a path for later use. Refer to a mark by prefixing its name with a tilde. The "ls" command automatically creates numeric marks for each object listed; these are the numbers in the first column. As a special case, you don’t need to use a tilde with numeric marks. The "cd" command automatically creates the mark "~~" pointing to the previous directory. If a mark reference is input instead of a command then RVC will cd to the marked object. Thus, "~~" is a convenient way to toggle between two directories.
When the working directory is a descendant of a Datacenter object, the mark "~" refers to the Datacenter. For example "~/datastore" is a convenient way to get the datastore folder of the current datacenter.
- Ruby Mode
Beginning an input line with "/" causes RVC to treat it as Ruby code and eval it. This gives you direct access to the underlying RbVmomi library. If the line "//" is input then RVC will toggle between shell and Ruby mode. Marks can be easily used in Ruby mode since there are magic variables with the same names. Since some marks, like numeric ones, aren’t valid variable names, they also exist with a "_" prefix.
The methods "this", "conn", and "dc" are provided in Ruby mode, returning the current object, connection, and datacenter respectively. The connection object is an instance of RbVmomi::VIM.
- VMODL Introspection
The "type" command can be used to display the properties and methods of a VMODL class. For example: "type Datacenter".
In Ruby mode, a ’#’ at the end of the input line will display the output of the "type" command for the resulting object’s class. This is very useful for exploring the vSphere API.
- Multiple Connections
RVC can connect to more than one ESX or VC server at the same time. Simply add more hosts to the command line, or use the command "connect". Each connection is represented by a top-level node in the virtual filesystem. If more than one host is given on the command line, RVC will start in the root of the filesystem instead of automatically cd’ing to a connection.
- Extensibility
RVC is designed to let users easily add commands they need. You can create a command module, or add to an existing one, by adding a Ruby file to ~/.rvc or any directory on the RVC_MODULE_PATH environment variable. The syntax of a user command module is the same as those built-in to RVC, so see the "lib/rvc/modules" directory for examples.
If you create a generically useful RVC command, please consider sending in a patch so everyone can use it.
Ruby 1.8.7+, preferred version is 1.9.2.
gem install rvc
Usage
% rvc 192.168.1.105
username: Administrator
password:
0 dc (datacenter)
192.168.1.105:/> cd dc/host/192.168.1.100/
192.168.1.105:/dc/host/192.168.1.100/> ls
0 host [192.168.1.100] (host): cpu 2*2*2.81 GHz, memory 2.00 GB
1 resourcePool [Resources]: cpu 4.35/4.35/normal, mem
0.48/0.48/normal
192.168.1.105:/dc/host/192.168.1.100/> ls host/vms/
0 foo: poweredOn
192.168.1.105:/dc/host/192.168.1.100/> i host/vms/foo
name: foo
host: dc/host/192.168.1.100/192.168.1.100
tools: guestToolsNotRunning
VC UUID: 5259d5d2-b767-43c9-db6d-fbf5cc4b6f02
power: poweredOn
cpus: 1
memory: 128 MB
nics:
Network adapter 1: "VM Network" connected 00:0c:29:c6:5d:2a
192.168.1.105:/dc/host/192.168.1.100/> off host/vms/foo
PowerOffVM foo: success
192.168.1.105:/dc/host/192.168.1.100/> quit
Enter "help" to see a list of all available commands.
All RVC commands exist in modules, and may optionally have aliases. For example, the command to power off a VM is actually "vm.off", since it exists in the "vm" module, but since it is a common operation it has been aliased to "off".


(17 votes)


vSphere 5 support?
Sean Clark says:from C:/Ruby192/bin/rvc:19:in `load'
C:\ruby>rvc a... Show more
The new RVC 1.6 works great in ESX/ESXi 4.x and 5.x for me.
Wow I really like 1.6!
(Er, vSphere 4.x / 5.x....)
VDS fails for cisco 1000V?
Cere Davis says:10.42.101.181/DC_3X2/networks/VSJ3X2N1KVSM01> vds.summarize VSJ3X2N1KVSM01
NoMeth... Show more
ruby within rvc
Tim says:are there any examples available of this? i'd like to be able to power off then unregister all of the vm's in a datastore, and then register them in a new cluster. Is this something that could be done that way?
Reverting snapshots
Dominic says:Hello,
I am trying to use rvc to revert a vm to a specific snapshots. I have no problem restoring VM to its current running snapshot; however, it seems that I can not revert to other snapshots for a given VM. Is is possible to do somethings like:
ha-datacenter/vm> snapshot.revert vm_name snapshot_name
Thanks!
Specify a snapshot for revert?
Dominic says:ha-datacenter/vm> snapshot.revert vm-na... Show more
fault.RestrictedVersion
Lucas says:Thanks for a cool utility!
I'm trying to use this against ESXi host to view a VM, but I get this error:
/172.24.x.x/ha-datacenter/vm> v 1
RestrictedVersion: fault.RestrictedVersion.summary
After looking around, it seems like this error has something to do with licensing of ESX vs ESXi.
Is it not possible to use this utility to view consoles of ESXi hosts?
AFAIK only vSphere Client can be used with the free ESXi. The non-free ESXi works fine.
Editing VMX files on ESX
Mike says:We have ESX where I work and I'm using datastore.edit ("edit") to alter the values of a .VMX file.
The guest is powered off, of course.
Sometimes, datastore.edit will handle the (un)registration, while other times, it will not.
Can anybody help me with the entire process?
Example:
vm.off
datastore.edit
vm.unregister
vm.register
vm.on
Thanks, in advance!
Example of vm.register in RVC?
Mike says:Hi!
Does anybody have an example of using the register command in RVC? I assume you have to connect through a host, not a datacenter.
I always seem to get something like:
/myhost> vm.register /my/path/to/myguest/myguest.vmx
Expected Folder but got RbVmomi::VIM at "."
Thanks!
Specify the --folder option to pick which VM folder to add the VM to. You don't need to connect directly to the host.
I have been having a real hard time editing VMX... Show more
Custom port?
Alex says:Tried: rvc 10.100.1.3:13443
I get:
/usr/lib/ruby/1.8/net/http.rb:586:in `connect': SSL_connect returned=1 errno=0 state=SSLv2/v3 read server... Show more
Replying to my own message. On github there is an update that supposedly enables custom ports. I have not tested yet.
For all that can't install vmrc (vmrc.install), here is a little patch to appli:
--- /tmp/vmrc.rb 2011-05-11 15:02:34.614969088 +0200
+++ ./rvc-1.3.6/lib/rvc/modules/vmrc.rb 2011-04-27 11:07:... Show more
sauron:~ garfield$ rvc x.x.x.x
Install the "ffi" gem for better tab completion.
No VMRC available for OS darwin10.0
/Library/Ruby/Gems/1.8/gems/rvc-1.3.6/... Show more
just adding the later used constants with empty values fixes the crash. unified diff below.
This doesn't seem to work in Mac OS X 10.6.7
SFL supports these Rubies:
(On MacOS) MRI 1.8.6, 1.8.7, 1.9.1, 1.9.2-rc2
(On UNIX) MRI 1.8.6, 1.8.7, 1.9.1, 1.9.2pre
(On Windows) MRI 1.9.1, 1.9.2pre
Unfort... Show more
Oh, and Process.spawn() should already work for MacRuby, if I am reading this correctly:
http://www.macruby.org/trac/ticket/590
I do notice one issue, though. :-(
On Ruby 1.8.7, the datastore.* commands, such as edit, download, and upload do not work, since spawn() is not implemented. ... Show more
I suppose it works on ESXi just like CML vClient
I noticed you only referenced ESX and vCenter. Will this work equally well for ESXi hosts?
Thank you
Yes, RVC supports ESXi.
Cool stuff
Is there a way to use this with the vDR appliance, to check if jobs where runnung and so forth?