rvc 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/rvc +46 -70
- data/devel/test-dependencies.sh +4 -0
- data/lib/rvc.rb +5 -6
- data/lib/rvc/command.rb +65 -0
- data/lib/rvc/command_slate.rb +112 -0
- data/lib/rvc/completion.rb +89 -58
- data/lib/rvc/connection.rb +48 -0
- data/lib/rvc/extensions/DistributedVirtualPortgroup.rb +1 -1
- data/lib/rvc/extensions/DistributedVirtualSwitch.rb +3 -3
- data/lib/rvc/extensions/HostSystem.rb +90 -0
- data/lib/rvc/extensions/VirtualMachine.rb +37 -7
- data/lib/rvc/field.rb +59 -12
- data/lib/rvc/fs.rb +34 -4
- data/lib/rvc/inventory.rb +5 -1
- data/lib/rvc/modules/alarm.rb +2 -0
- data/lib/rvc/modules/basic.rb +66 -61
- data/lib/rvc/modules/cluster.rb +117 -22
- data/lib/rvc/modules/connection.rb +40 -0
- data/lib/rvc/modules/core.rb +4 -16
- data/lib/rvc/modules/datacenter.rb +2 -0
- data/lib/rvc/modules/datastore.rb +11 -78
- data/lib/rvc/modules/device.rb +40 -5
- data/lib/rvc/modules/diagnostics.rb +169 -0
- data/lib/rvc/modules/esxcli.rb +9 -5
- data/lib/rvc/modules/find.rb +5 -3
- data/lib/rvc/modules/host.rb +46 -3
- data/lib/rvc/modules/issue.rb +2 -0
- data/lib/rvc/modules/mark.rb +5 -3
- data/lib/rvc/modules/perf.rb +99 -33
- data/lib/rvc/modules/permissions.rb +2 -0
- data/lib/rvc/modules/resource_pool.rb +2 -0
- data/lib/rvc/modules/role.rb +3 -1
- data/lib/rvc/modules/snapshot.rb +12 -4
- data/lib/rvc/modules/statsinterval.rb +13 -11
- data/lib/rvc/modules/vds.rb +67 -10
- data/lib/rvc/modules/vim.rb +19 -53
- data/lib/rvc/modules/vm.rb +27 -6
- data/lib/rvc/modules/vm_guest.rb +490 -0
- data/lib/rvc/modules/vmrc.rb +60 -32
- data/lib/rvc/modules/vnc.rb +2 -0
- data/lib/rvc/namespace.rb +114 -0
- data/lib/rvc/option_parser.rb +12 -15
- data/lib/rvc/readline-ffi.rb +4 -1
- data/lib/rvc/ruby_evaluator.rb +84 -0
- data/lib/rvc/shell.rb +68 -83
- data/lib/rvc/uri_parser.rb +59 -0
- data/lib/rvc/util.rb +134 -29
- data/lib/rvc/{extensions/PerfCounterInfo.rb → version.rb} +2 -4
- data/lib/rvc/{memory_session.rb → vim.rb} +10 -32
- data/test/modules/foo.rb +9 -0
- data/test/modules/foo/bar.rb +9 -0
- data/test/test_completion.rb +17 -0
- data/test/test_fs.rb +9 -11
- data/test/test_help.rb +46 -0
- data/test/test_helper.rb +12 -0
- data/test/test_metric.rb +1 -2
- data/test/test_modules.rb +38 -0
- data/test/test_parse_path.rb +1 -2
- data/test/test_shell.rb +138 -0
- data/test/test_uri.rb +34 -0
- metadata +115 -81
- data/lib/rvc/extensions/PerformanceManager.rb +0 -83
- data/lib/rvc/filesystem_session.rb +0 -101
- data/lib/rvc/modules.rb +0 -138
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'date'
|
2
|
-
|
3
|
-
class Time
|
4
|
-
def to_datetime
|
5
|
-
# Convert seconds + microseconds into a fractional number of seconds
|
6
|
-
seconds = sec + Rational(usec, 10**6)
|
7
|
-
|
8
|
-
# Convert a UTC offset measured in minutes to one measured in a
|
9
|
-
# fraction of a day.
|
10
|
-
offset = Rational(utc_offset, 60 * 60 * 24)
|
11
|
-
DateTime.new(year, month, day, hour, min, seconds, offset)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
RbVmomi::VIM::PerfCounterInfo
|
16
|
-
class RbVmomi::VIM::PerfCounterInfo
|
17
|
-
def pretty_name
|
18
|
-
@pretty_name ||= "#{self.groupInfo.key}.#{self.nameInfo.key}.#{self.rollupType}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
RbVmomi::VIM::PerformanceManager
|
23
|
-
class RbVmomi::VIM::PerformanceManager
|
24
|
-
def perfcounter_cached
|
25
|
-
@perfcounter ||= perfCounter
|
26
|
-
end
|
27
|
-
|
28
|
-
def perfcounter_hash
|
29
|
-
@perfcounter_hash ||= Hash[perfcounter_cached.map{|x| [x.pretty_name, x]}]
|
30
|
-
end
|
31
|
-
|
32
|
-
def perfcounter_idhash
|
33
|
-
@perfcounter_idhash ||= Hash[perfcounter_cached.map{|x| [x.key, x]}]
|
34
|
-
end
|
35
|
-
|
36
|
-
def provider_summary obj
|
37
|
-
@provider_summary ||= {}
|
38
|
-
@provider_summary[obj.class] ||= QueryPerfProviderSummary(:entity => obj)
|
39
|
-
end
|
40
|
-
|
41
|
-
def retrieve_stats objects, metrics, opts = {}
|
42
|
-
opts = opts.dup
|
43
|
-
max_samples = opts[:max_samples] || 1
|
44
|
-
realtime = false
|
45
|
-
if not opts[:interval]
|
46
|
-
provider = provider_summary objects.first
|
47
|
-
opts[:interval] = provider.refreshRate
|
48
|
-
realtime = true
|
49
|
-
else
|
50
|
-
provider = provider_summary objects.first
|
51
|
-
if opts[:interval] == provider.refreshRate
|
52
|
-
realtime = true
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
metric_ids = metrics.map do |x|
|
57
|
-
RbVmomi::VIM::PerfMetricId(:counterId => perfcounter_hash[x].key, :instance => '*')
|
58
|
-
end
|
59
|
-
query_specs = objects.map do |obj|
|
60
|
-
RbVmomi::VIM::PerfQuerySpec({
|
61
|
-
:maxSample => max_samples,
|
62
|
-
:entity => obj,
|
63
|
-
:metricId => metric_ids,
|
64
|
-
:intervalId => opts[:interval],
|
65
|
-
:startTime => (realtime == false ? opts[:start_time].to_datetime : nil),
|
66
|
-
})
|
67
|
-
end
|
68
|
-
stats = QueryPerf(:querySpec => query_specs)
|
69
|
-
|
70
|
-
Hash[stats.map do |res|
|
71
|
-
[
|
72
|
-
res.entity,
|
73
|
-
{
|
74
|
-
:sampleInfo => res.sampleInfo,
|
75
|
-
:metrics => Hash[res.value.map do |metric|
|
76
|
-
[perfcounter_idhash[metric.id.counterId].pretty_name, metric.value]
|
77
|
-
end]
|
78
|
-
}
|
79
|
-
]
|
80
|
-
end]
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
module RVC
|
22
|
-
|
23
|
-
class FilesystemSession
|
24
|
-
def initialize name
|
25
|
-
fail "invalid session name" unless name =~ /^[\w-]+$/
|
26
|
-
@dir = File.join(ENV['HOME'], '.rvc', 'sessions', name)
|
27
|
-
prev_umask = File.umask 077
|
28
|
-
FileUtils.mkdir_p @dir
|
29
|
-
FileUtils.mkdir_p mark_dir
|
30
|
-
FileUtils.mkdir_p connection_dir
|
31
|
-
File.umask prev_umask
|
32
|
-
@priv = {}
|
33
|
-
end
|
34
|
-
|
35
|
-
def marks
|
36
|
-
Dir.entries(mark_dir).reject { |x| x == '.' || x == '..' } + @priv.keys
|
37
|
-
end
|
38
|
-
|
39
|
-
def get_mark key
|
40
|
-
if is_private_mark? key
|
41
|
-
@priv[key]
|
42
|
-
else
|
43
|
-
return nil unless File.exists? mark_fn(key)
|
44
|
-
File.readlines(mark_fn(key)).
|
45
|
-
map { |path| RVC::Util.lookup(path.chomp) }.
|
46
|
-
inject([], &:+)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def set_mark key, objs
|
51
|
-
if is_private_mark? key
|
52
|
-
if objs == nil
|
53
|
-
@priv.delete key
|
54
|
-
else
|
55
|
-
@priv[key] = objs
|
56
|
-
end
|
57
|
-
else
|
58
|
-
if objs == nil
|
59
|
-
File.unlink mark_fn(key)
|
60
|
-
else
|
61
|
-
File.open(mark_fn(key), 'w') do |io|
|
62
|
-
objs.each { |obj| io.puts obj.rvc_path_str }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def connections
|
69
|
-
Dir.entries(connection_dir).reject { |x| x == '.' || x == '..' }
|
70
|
-
end
|
71
|
-
|
72
|
-
def get_connection key
|
73
|
-
return nil unless File.exists? connection_fn(key)
|
74
|
-
File.open(connection_fn(key)) { |io| YAML.load io }
|
75
|
-
end
|
76
|
-
|
77
|
-
def set_connection key, conn
|
78
|
-
if conn == nil
|
79
|
-
File.unlink(connection_fn(key))
|
80
|
-
else
|
81
|
-
File.open(connection_fn(key), 'w') { |io| YAML.dump conn, io }
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
def is_private_mark? key
|
88
|
-
return key == '' ||
|
89
|
-
key == '~' ||
|
90
|
-
key == '@' ||
|
91
|
-
key =~ /^\d+$/
|
92
|
-
end
|
93
|
-
|
94
|
-
def mark_dir; File.join(@dir, 'marks') end
|
95
|
-
def mark_fn(key); File.join(mark_dir, key) end
|
96
|
-
def connection_dir; File.join(@dir, 'connections') end
|
97
|
-
def connection_fn(key); File.join(connection_dir, key) end
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
data/lib/rvc/modules.rb
DELETED
@@ -1,138 +0,0 @@
|
|
1
|
-
# Copyright (c) 2011 VMware, Inc. All Rights Reserved.
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'rvc/util'
|
22
|
-
require 'shellwords'
|
23
|
-
|
24
|
-
module RVC
|
25
|
-
|
26
|
-
ALIASES = {}
|
27
|
-
MODULES = {}
|
28
|
-
|
29
|
-
class CmdModule
|
30
|
-
include RVC::Util
|
31
|
-
|
32
|
-
def initialize module_name
|
33
|
-
@module_name = module_name
|
34
|
-
@opts = {}
|
35
|
-
@completors = {}
|
36
|
-
super()
|
37
|
-
end
|
38
|
-
|
39
|
-
def commands
|
40
|
-
@opts.keys
|
41
|
-
end
|
42
|
-
|
43
|
-
def has_command? cmd
|
44
|
-
@opts.member? cmd
|
45
|
-
end
|
46
|
-
|
47
|
-
def opts cmd, &b
|
48
|
-
if cmd.to_s =~ /[A-Z]/
|
49
|
-
fail "Camel-casing is not allowed (#{cmd.to_s})"
|
50
|
-
end
|
51
|
-
|
52
|
-
@opts[cmd] = OptionParser.new cmd.to_s, &b
|
53
|
-
|
54
|
-
@opts[cmd].specs.each do |name,spec|
|
55
|
-
if name.to_s =~ /[A-Z]/
|
56
|
-
fail "Camel-casing is not allowed (#{cmd.to_s} option #{name})"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def raw_opts cmd, summary
|
62
|
-
@opts[cmd] = RawOptionParser.new cmd.to_s, summary
|
63
|
-
end
|
64
|
-
|
65
|
-
def opts_for cmd
|
66
|
-
@opts[cmd]
|
67
|
-
end
|
68
|
-
|
69
|
-
def rvc_completor cmd, &b
|
70
|
-
@completors[cmd] = b
|
71
|
-
end
|
72
|
-
|
73
|
-
def completor_for cmd
|
74
|
-
@completors[cmd]
|
75
|
-
end
|
76
|
-
|
77
|
-
def rvc_alias cmd, target=nil
|
78
|
-
target ||= cmd
|
79
|
-
RVC::ALIASES[target.to_s] = "#{@module_name}.#{cmd}"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def self.complete_for_cmd line, word
|
84
|
-
if line == nil
|
85
|
-
return []
|
86
|
-
end
|
87
|
-
mod, cmd, args = Shell.parse_input line
|
88
|
-
return [] unless mod != nil
|
89
|
-
#XXX assumes you aren't going to have any positional arguments with spaces
|
90
|
-
if(/ $/.match(line))
|
91
|
-
argnum = args.size
|
92
|
-
else
|
93
|
-
argnum = args.size - 1
|
94
|
-
end
|
95
|
-
|
96
|
-
completor = mod.completor_for(cmd.to_sym)
|
97
|
-
if completor == nil
|
98
|
-
return []
|
99
|
-
end
|
100
|
-
|
101
|
-
candidates = completor.call(line, args, word, argnum)
|
102
|
-
if candidates == nil
|
103
|
-
[]
|
104
|
-
else
|
105
|
-
prefix_regex = /^#{Regexp.escape word}/
|
106
|
-
candidates.select { |x,a| x =~ prefix_regex }
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
BULTIN_MODULE_PATH = [File.expand_path(File.join(File.dirname(__FILE__), 'modules')),
|
111
|
-
File.join(ENV['HOME'], ".rvc")]
|
112
|
-
ENV_MODULE_PATH = (ENV['RVC_MODULE_PATH'] || '').split ':'
|
113
|
-
|
114
|
-
def self.reload_modules verbose=true
|
115
|
-
RVC::MODULES.clear
|
116
|
-
RVC::ALIASES.clear
|
117
|
-
RVC::MODULES['custom'] = CmdModule.new 'custom'
|
118
|
-
module_path = (BULTIN_MODULE_PATH+ENV_MODULE_PATH).select { |d| File.directory?(d) }
|
119
|
-
globs = module_path.map { |d| File.join(d, '*.rb') }
|
120
|
-
Dir.glob(globs) do |f|
|
121
|
-
module_name = File.basename(f)[0...-3]
|
122
|
-
puts "loading #{module_name} from #{f}" if verbose
|
123
|
-
begin
|
124
|
-
code = File.read f
|
125
|
-
unless RVC::MODULES.member? module_name
|
126
|
-
m = CmdModule.new module_name
|
127
|
-
CMD.define_singleton_method(module_name.to_sym) { m }
|
128
|
-
RVC::MODULES[module_name] = m
|
129
|
-
end
|
130
|
-
RVC::MODULES[module_name].instance_eval code, f
|
131
|
-
rescue
|
132
|
-
puts "#{$!.class} while loading #{f}: #{$!.message}"
|
133
|
-
$!.backtrace.each { |x| puts x }
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|