vmesh 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +37 -0
- data/bin/vmesh +6 -25
- data/lib/vmesh/commands/df.rb +21 -0
- data/lib/vmesh/datastore.rb +8 -2
- data/lib/vmesh/version.rb +1 -1
- data/lib/vmesh/vsphere.rb +11 -3
- metadata +3 -2
data/README.md
CHANGED
@@ -8,6 +8,27 @@ Vmesh is a Command Suite (think git) to make managing VMWare components easier a
|
|
8
8
|
|
9
9
|
Vmesh is currently Alpha, hence the 0-dot version; it is susceptible to methods, classes and modules being renamed, added or deleted.
|
10
10
|
|
11
|
+
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
|
12
|
+
|
13
|
+
- [Command suite for VMWare](#)
|
14
|
+
- [What is Vmesh?](#)
|
15
|
+
- [THIS IS ALPHA!](#)
|
16
|
+
- [Setup](#)
|
17
|
+
- [I don't want to type my connection config every time](#)
|
18
|
+
- [How to setup cloning servers](#)
|
19
|
+
- [AMG It complains about vtypes and stuff](#)
|
20
|
+
- [Usage](#)
|
21
|
+
- [Help](#)
|
22
|
+
- [Create or clone](#)
|
23
|
+
- [IP Handling](#)
|
24
|
+
- [How vmesh deals with datastores](#)
|
25
|
+
- [Power](#)
|
26
|
+
- [Deleting a VM can be done with the command](#)
|
27
|
+
- [List](#)
|
28
|
+
- [Disk Usage](#)
|
29
|
+
- [TODOs](#)
|
30
|
+
- [Copyright](#)
|
31
|
+
|
11
32
|
## Setup
|
12
33
|
|
13
34
|
Install the gem
|
@@ -145,6 +166,22 @@ List directories only
|
|
145
166
|
vmesh ls -d
|
146
167
|
```
|
147
168
|
|
169
|
+
### Disk Usage
|
170
|
+
|
171
|
+
_Note_ you can use `df` or `diskspace`
|
172
|
+
|
173
|
+
Display disk usage for all disks at current dc
|
174
|
+
|
175
|
+
```
|
176
|
+
vmesh df
|
177
|
+
```
|
178
|
+
|
179
|
+
Display disk usage for all disks with 'gold' in the name
|
180
|
+
|
181
|
+
```
|
182
|
+
vmesh df gold
|
183
|
+
```
|
184
|
+
|
148
185
|
## TODOs
|
149
186
|
|
150
187
|
* Sort out problem with upstream rbvmomi/nogokiri
|
data/bin/vmesh
CHANGED
@@ -17,7 +17,7 @@ include GLI::App
|
|
17
17
|
version Vmesh::VERSION
|
18
18
|
Vmesh.logger = Logger.new(STDOUT)
|
19
19
|
@logger = Vmesh.logger
|
20
|
-
|
20
|
+
@logger.level = Logger::WARN
|
21
21
|
|
22
22
|
config_filename = '.vmesh.rc'
|
23
23
|
|
@@ -71,31 +71,10 @@ desc 'VCenter Resource Pool'
|
|
71
71
|
arg_name 'vcenter resource pool'
|
72
72
|
flag [:r,:resource_pool]
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
desc 'TODO Describe destroy here'
|
77
|
-
arg_name 'Describe arguments to destroy here'
|
78
|
-
command :destroy do |c|
|
79
|
-
c.action do |global_options,options,args|
|
80
|
-
puts "destroy command ran"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
desc 'TODO Describe run here'
|
85
|
-
arg_name 'Describe arguments to run here'
|
86
|
-
command :run do |c|
|
87
|
-
c.action do |global_options,options,args|
|
88
|
-
puts "run command ran"
|
89
|
-
end
|
90
|
-
end
|
74
|
+
desc 'Run in debug mode'
|
75
|
+
switch [:debug]
|
91
76
|
|
92
|
-
|
93
|
-
arg_name 'Describe arguments to info here'
|
94
|
-
command :info do |c|
|
95
|
-
c.action do |global_options,options,args|
|
96
|
-
puts "info command ran"
|
97
|
-
end
|
98
|
-
end
|
77
|
+
commands_from 'vmesh/commands'
|
99
78
|
|
100
79
|
pre do |global,command,options,args|
|
101
80
|
# Pre logic here
|
@@ -103,6 +82,8 @@ pre do |global,command,options,args|
|
|
103
82
|
# chosen command
|
104
83
|
# Use skips_pre before a command to skip this block
|
105
84
|
# on that command only
|
85
|
+
@logger.level = Logger::DEBUG if global[:debug]
|
86
|
+
|
106
87
|
if global[:user].to_s == ''
|
107
88
|
not_so_secret_username = ask("Enter Username please:") {|q| q.echo = true}
|
108
89
|
global['u'] = global[:u] = global['user'] = global[:user] = not_so_secret_username
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
desc 'report datastore space usage'
|
3
|
+
arg_name '[name]'
|
4
|
+
|
5
|
+
command [:df,:diskspace] do |c|
|
6
|
+
|
7
|
+
c.action do |global_options,options,args|
|
8
|
+
name = ARGV.shift if ARGV.any?
|
9
|
+
vm_manager = Vmesh::VSphere.new global_options
|
10
|
+
if name.to_s == ''
|
11
|
+
all_datastores = Vmesh::Datastore.get_all(vm_manager.vim, vm_manager.get_datacenter(global_options[:datacenter]))
|
12
|
+
else
|
13
|
+
all_datastores = Vmesh::Datastore.get_all_matching(vm_manager.vim, name, vm_manager.get_datacenter(global_options[:datacenter]))
|
14
|
+
end
|
15
|
+
puts '%-30.30s%15.15s%15.15s%15.15s%8.8s' % ["Name","Size","Available","Used","Use%"]
|
16
|
+
all_datastores.each do |ds|
|
17
|
+
pc_free = (ds.free_space.to_i * 100) / ds.capacity.to_i
|
18
|
+
puts '%-30.30s%15.15s%15.15s%15.15s%8.8s' % ["#{ds.name}","#{ds.capacity}","#{ds.free_space}","#{ds.capacity}","#{pc_free}%"]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/vmesh/datastore.rb
CHANGED
@@ -8,7 +8,12 @@ module Vmesh
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def self.get(vim, name, datacenter)
|
11
|
-
Vmesh::logger.debug "Getting datastore named #{name} at datacenter #{datacenter.name}."
|
11
|
+
Vmesh::logger.debug "Getting a single datastore named #{name} at datacenter #{datacenter.name}."
|
12
|
+
get_all_matching(vim,name,datacenter).sort_by{ |ds| ds.free_space }.reverse.first
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.get_all_matching(vim, name, datacenter)
|
16
|
+
Vmesh::logger.debug "Getting datastore matching name #{name} at datacenter #{datacenter.name}."
|
12
17
|
stores = self.get_all(vim, datacenter).select{ |ds| ds.name == name }
|
13
18
|
if stores.nil? or stores.empty?
|
14
19
|
Vmesh::logger.info "No exact match found, searching for partial match"
|
@@ -16,9 +21,10 @@ module Vmesh
|
|
16
21
|
Vmesh::logger.debug "Found #{stores.count} datastores."
|
17
22
|
Vmesh::logger.debug "#{stores.map{|ds| "Name #{ds.name}, free space #{ds.free_space}"}}"
|
18
23
|
end
|
19
|
-
stores
|
24
|
+
stores
|
20
25
|
end
|
21
26
|
|
27
|
+
|
22
28
|
def self.get_all(vim, datacenter)
|
23
29
|
Vmesh::logger.debug "get_all datastores at #{datacenter.name}."
|
24
30
|
vim.serviceContent.viewManager.CreateContainerView({
|
data/lib/vmesh/version.rb
CHANGED
data/lib/vmesh/vsphere.rb
CHANGED
@@ -6,9 +6,17 @@ module Vmesh
|
|
6
6
|
class VSphere
|
7
7
|
attr_accessor :vim, :options
|
8
8
|
def initialize(connection_options)
|
9
|
-
Vmesh::logger.debug "Opening connection to #{connection_options['host']}"
|
10
|
-
|
11
|
-
|
9
|
+
Vmesh::logger.debug "Opening connection to #{connection_options['host']} #{connection_options.inspect}"
|
10
|
+
opts = {
|
11
|
+
:host => connection_options[:host],
|
12
|
+
:user => connection_options[:user],
|
13
|
+
:password => connection_options[:password],
|
14
|
+
:datacenter => connection_options[:datacenter],
|
15
|
+
:host => connection_options[:host],
|
16
|
+
:insecure => connection_options[:insecure],
|
17
|
+
}
|
18
|
+
@vim = RbVmomi::VIM.connect opts
|
19
|
+
@options = opts
|
12
20
|
end
|
13
21
|
|
14
22
|
# Can we search through the datacenters for a machine?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmesh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-11-
|
12
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- lib/vmesh.rb
|
185
185
|
- lib/vmesh/commands/create.rb
|
186
186
|
- lib/vmesh/commands/create_helpers.rb
|
187
|
+
- lib/vmesh/commands/df.rb
|
187
188
|
- lib/vmesh/commands/list.rb
|
188
189
|
- lib/vmesh/commands/power.rb
|
189
190
|
- lib/vmesh/commands/revert.rb
|