ssvm_cli 0.0.2 → 0.0.3
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/bin/ssvm +22 -3
- data/lib/request_helper.rb +37 -0
- data/ssvm_cli.gemspec +1 -1
- metadata +4 -4
data/bin/ssvm
CHANGED
|
@@ -17,7 +17,7 @@ class Ssvm < Thor
|
|
|
17
17
|
method_option :owners, :aliases => '-o', :desc => "Owners of the VM", :type => :array
|
|
18
18
|
method_option :env, :aliases => '-e', :required => true, :desc => "Environment for the VM (e.g. prod or np)"
|
|
19
19
|
method_option :datacenter, :aliases => '-d', :required => true, :desc => "Datacenter for the VM (e.g. dc1 or dc2)"
|
|
20
|
-
method_option :build_spec, :required => true, :desc => "Default or customized VM request"
|
|
20
|
+
method_option :build_spec, :aliases => '-b', :required => true, :desc => "Default or customized VM request"
|
|
21
21
|
method_option :os, :desc => "What OS to use for the VM (e.g. Scientific Linux (Carbon) 6.0 x86_64)"
|
|
22
22
|
method_option :instances, :desc => "How many instances to make"
|
|
23
23
|
method_option :start_at, :desc => "What number to start at for multi instances request", :default => 1
|
|
@@ -26,14 +26,33 @@ class Ssvm < Thor
|
|
|
26
26
|
method_option :memory, :aliases => '-m', :desc => "How much memory for the VM"
|
|
27
27
|
method_option :cpu, :aliases => '-c', :desc => "How CPU for the VM"
|
|
28
28
|
method_option :disk, :desc => "How much disk space for the VM"
|
|
29
|
-
method_option :
|
|
29
|
+
method_option :no_expiration, :type => :boolean, :desc => "No expiration for the VM"
|
|
30
30
|
method_option :justifications, :aliases => '-j', :desc => "Justification for any special request"
|
|
31
|
+
method_option :location_specs, :aliases => '-l',
|
|
32
|
+
:desc => "Specificiations for where to create the VM (format [include|exclude]:[rack|chassis|node]:location1,location2)",
|
|
33
|
+
:type => :array
|
|
31
34
|
def create_vm
|
|
32
35
|
conf = load_conf(options[:conf_file] || CONFIG_FILE)
|
|
33
36
|
rhelper = RequestHelper.new(conf)
|
|
34
37
|
rhelper.create_vm(options)
|
|
35
38
|
end
|
|
36
39
|
|
|
40
|
+
desc 'perform_action', 'perform the action on the specified VMs'
|
|
41
|
+
method_option :hosts, :aliases => '-h', :required => true, :desc => "List of VMs to perform the action on", :type => :array
|
|
42
|
+
method_option :action, :aliases => '-a', :required => true, :desc => "What action to perform. Available actions are rebuild, reboot and delete"
|
|
43
|
+
method_option :silent, :type => :boolean, :desc => "Don't prompt"
|
|
44
|
+
def perform_action
|
|
45
|
+
conf = load_conf(options[:conf_file] || CONFIG_FILE)
|
|
46
|
+
rhelper = RequestHelper.new(conf)
|
|
47
|
+
puts "You're about to #{options['action']} the following VM(s): #{options['hosts'].inspect}"
|
|
48
|
+
if options['silent']
|
|
49
|
+
continue = true
|
|
50
|
+
else
|
|
51
|
+
continue = ask("Are you sure you want to do that? (y/N)? ") == 'y'
|
|
52
|
+
end
|
|
53
|
+
rhelper.perform_action(options) if continue
|
|
54
|
+
end
|
|
55
|
+
|
|
37
56
|
desc "config", "configuration setup"
|
|
38
57
|
method_option :conf_file, :aliases => "-c", :desc => "Where to write config to"
|
|
39
58
|
def config
|
|
@@ -42,7 +61,7 @@ class Ssvm < Thor
|
|
|
42
61
|
conf = {}
|
|
43
62
|
conf[:username] = ask("Username: ")
|
|
44
63
|
conf[:password] = ask("Password: ", true)
|
|
45
|
-
conf[:server] = ask("
|
|
64
|
+
conf[:server] = ask("SSVM server: ")
|
|
46
65
|
File.open(config_file, 'w') do |f|
|
|
47
66
|
YAML.dump(conf, f)
|
|
48
67
|
end
|
data/lib/request_helper.rb
CHANGED
|
@@ -18,6 +18,7 @@ class RequestHelper
|
|
|
18
18
|
update_owner_field(options)
|
|
19
19
|
handle_multi_instances(options)
|
|
20
20
|
handle_custom_request(options)
|
|
21
|
+
handle_location_specs(options)
|
|
21
22
|
|
|
22
23
|
begin
|
|
23
24
|
response = RestClient.post("http://#{@server}/vm",
|
|
@@ -34,6 +35,24 @@ class RequestHelper
|
|
|
34
35
|
end
|
|
35
36
|
end
|
|
36
37
|
|
|
38
|
+
def perform_action(options)
|
|
39
|
+
action = options['action']
|
|
40
|
+
hosts = options['hosts']
|
|
41
|
+
begin
|
|
42
|
+
response = RestClient.post("http://#{@server}/vm/#{action}",
|
|
43
|
+
{:id => hosts.first},
|
|
44
|
+
{:cookies => @cookies, :content_type => 'application/json', :accept => :json})
|
|
45
|
+
result = JSON.parse(response)
|
|
46
|
+
if options[:json]
|
|
47
|
+
puts JSON.pretty_generate(result)
|
|
48
|
+
else
|
|
49
|
+
puts result['message']
|
|
50
|
+
end
|
|
51
|
+
rescue => e
|
|
52
|
+
puts e.inspect
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
37
56
|
private
|
|
38
57
|
def update_owner_field(options)
|
|
39
58
|
if options['owners']
|
|
@@ -63,4 +82,22 @@ class RequestHelper
|
|
|
63
82
|
def handle_custom_request(options)
|
|
64
83
|
options['processor_count'] = options.delete('cpu')
|
|
65
84
|
end
|
|
85
|
+
|
|
86
|
+
def handle_location_specs(options)
|
|
87
|
+
location_specs = options.delete('location_specs')
|
|
88
|
+
return unless location_specs
|
|
89
|
+
|
|
90
|
+
location_specs.each_with_index do |location_spec, index|
|
|
91
|
+
tokens = location_spec.split(':')
|
|
92
|
+
raise "Invalid location specs" if tokens.size != 3
|
|
93
|
+
if tokens[0] != "include" and tokens[0] != "exclude"
|
|
94
|
+
raise "Invalid location specs - modifier must be #{include} or #{exclude} but it's #{tokens[0]} instead"
|
|
95
|
+
end
|
|
96
|
+
raise "Invalid location specs" unless ['node', 'chassis', 'rack'].include? tokens[1]
|
|
97
|
+
|
|
98
|
+
options["location_specs_attributes[#{index}][modifier]"] = tokens[0]
|
|
99
|
+
options["location_specs_attributes[#{index}][loc_type]"] = tokens[1]
|
|
100
|
+
options["location_specs_attributes[#{index}][value]"] = tokens[2]
|
|
101
|
+
end
|
|
102
|
+
end
|
|
66
103
|
end
|
data/ssvm_cli.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ssvm_cli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 25
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 0.0.
|
|
9
|
+
- 3
|
|
10
|
+
version: 0.0.3
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Darren Dao
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2012-
|
|
18
|
+
date: 2012-06-06 00:00:00 Z
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
21
21
|
name: thor
|