esx
所属分类:操作系统开发
开发工具:Ruby
文件大小:10195KB
下载次数:0
上传日期:2015-03-13 17:31:00
上 传 者:
sh-1993
说明: 简单的ruby RbVmomi包装器,用于管理VMWare ESX主机。
(Simple ruby RbVmomi wrapper to manage VMWare ESX hosts.)
文件列表:
.document (55, 2015-03-14)
CHANGELOG.md (1357, 2015-03-14)
Gemfile (444, 2015-03-14)
Gemfile.lock (960, 2015-03-14)
LICENSE.txt (1071, 2015-03-14)
Rakefile (1527, 2015-03-14)
bin (0, 2015-03-14)
bin\esx (15752, 2015-03-14)
esx.gemspec (2878, 2015-03-14)
examples (0, 2015-03-14)
examples\basics.rb (1011, 2015-03-14)
lib (0, 2015-03-14)
lib\esx.rb (19827, 2015-03-14)
spec (0, 2015-03-14)
spec\data (0, 2015-03-14)
spec\data\tc.vmdk (10570240, 2015-03-14)
spec\spec_helper.rb (1061, 2015-03-14)
spec\unit (0, 2015-03-14)
spec\unit\helper_spec.rb (4666, 2015-03-14)
spec\unit\host_spec.rb (6967, 2015-03-14)
spec\unit\vm_spec.rb (655, 2015-03-14)
templates (0, 2015-03-14)
templates\vmx_template.erb (964, 2015-03-14)
# ESX
Simple rbvmomi wrapper to manage VMWare ESX hosts.
The goal of the library is to keep things simple so vCenter support isn't planned.
If you want a full VMWare vSphere API ruby implementation have a look at https://github.com/rlane/rbvmomi
# Installation
## Ubuntu/Debian
apt-get install libxml2-dev libxslt-dev gcc make rubygems
gem install esx
## RHEL/Fedora
yum install libxml2-devel libxslt-devel make gcc rubygems
gem install esx
## MacOSX
gem install esx
# Usage
Usage: esx --help
## Available Commands
__esx info --user root --password foo 10.10.0.2__
Sample output:
*********
ESXHOST1
*********
Memory Size: 32756
Memory Usage: 7429
Cpu Cores: 8
Power State: poweredOn
Hosted VMs: 2
Running VMs: 1
Virtual Machines:
+-------------------------+--------+------+------+-------+------------+
| NAME | MEMORY | CPUS | NICS | DISKS | STATE |
+-------------------------+--------+------+------+-------+------------+
| foobar | 128 | 1 | 1 | 1 | poweredOn |
| foobar2 | 256 | 2 | 1 | 1 | poweredOff |
+-------------------------+--------+------+------+-------+------------+
Datastores:
+------------+--------------+--------------+-----------+------+---------------------------------------------------+
| NAME | CAPACITY | FREESPACE | ACCESIBLE | TYPE | URL |
+------------+--------------+--------------+-----------+------+---------------------------------------------------+
| datastore2 | 146565758976 | 145547591680 | VMFS | true | /vmfs/volumes/4e611c69-1***74ca5-d290-5ef3fc9a99c3 |
| datastore1 | 141465485312 | 20716716032 | VMFS | true | /vmfs/volumes/4e6117e7-35c82a3e-ba79-5cf3fc9699c2 |
+------------+--------------+--------------+-----------+------+---------------------------------------------------+
__esx create-vm --user root --password foo --name esx-maintux --disk-file /path/to/file.vmdk --datastore datastore1 --memory 2048 --poweron 10.10.0.2__
# Using the library
require 'rubygems'
require 'lib/esx.rb'
# Connect to the ESX Host
host = ESX::Host.connect 'my-esx-host', 'root', 'secret'
# Print hypervisor info
puts
name = host.name.upcase
puts "*" * name.size
puts name
puts "*" * name.size
puts "Memory Size: %s" % host.memory_size.bytes.to.megabytes.to_i
puts "Memory Usage: %s" % host.memory_usage.bytes.to.megabytes.to_i
puts "Cpu Cores: %s" % host.cpu_cores
puts "Power State: %s" % host.power_state
# Create a VM with 4GB disk, 128 MB mem, e1000 nic, 1CPU in datastore1
vm = host.create_vm :vm_name => 'foobar'
# Create a VM with 5GB disk, 256 MB mem, e1000 nic, 1CPU in datastore2
vm = host.create_vm :vm_name => 'foobar2', :disk_size => 5000, :cpus => 2, :memory => 256, :datastore => 'datastore2'
host.virtual_machines.each do |vm|
# PowerOff the VM if powered On
vm.power_off if (vm.name =~ /foobar/ and vm.power_state == 'poweredOn')
# Destroy the VM if name matches foobar
if vm.name =~ /foobar.*/
vm.destroy
end
end
# Testing
Run 'bundler install' to install required deps.
Run rspec from the base dir. By default, the tests try to connect to an ESX host named esx-test-host with user root and no password. Edit spec/spec_helper.rb to fit your needs.
# Copyright
Copyright (c) 2011 Sergio Rubio, Massimo Maino. See LICENSE.txt for
further details.
近期下载者:
相关文件:
收藏者: