vmanage 1.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.
Files changed (3) hide show
  1. data/bin/vmanage +3 -0
  2. data/lib/vmanage.rb +84 -0
  3. metadata +66 -0
data/bin/vmanage ADDED
@@ -0,0 +1,3 @@
1
+
2
+ require File.join(File.dirname(__FILE__), "..", "lib", "vmanage.rb")
3
+
data/lib/vmanage.rb ADDED
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'highline'
5
+ require 'optparse'
6
+ require 'etc'
7
+
8
+ current_user = Etc.getpwuid
9
+
10
+ OPTIONS = {
11
+ :host => "localhost",
12
+ :port => 8222,
13
+ :user => current_user.name,
14
+ :password => ""
15
+ }
16
+
17
+ op = OptionParser.new do |opts|
18
+ script_name = File.basename($0)
19
+ opts.banner = "Usage: #{script_name} start|stop|list [options]"
20
+ opts.separator ""
21
+ opts.on("-h", "--host HOST", String, "Host hostname or IP", "Default: localhost"){|OPTIONS[:host]|}
22
+ opts.on("-p", "--port PORT", Integer, "Port number vmware sdk listens to", "Default: 8222"){|OPTIONS[:port]|}
23
+ opts.on("-u", "--user USER", String, "VM administrator", "Defaults to the current user"){|OPTIONS[:user]|}
24
+ opts.separator ""
25
+ opts.on_tail("-h", "--help", "Show this help message."){ puts opts; exit}
26
+ end.parse!
27
+
28
+ if ARGV.empty? || !["start","stop","list"].include?(ARGV.first)
29
+ puts op.options
30
+ exit
31
+ end
32
+
33
+ OPTIONS[:password] = HighLine.new.ask("Password: "){|q| q.echo = false }
34
+
35
+ class Command
36
+ def self.invoke(cmd)
37
+ self.new.send(cmd)
38
+ end
39
+
40
+ def start
41
+ perform("start")
42
+ end
43
+
44
+ def stop
45
+ perform("stop")
46
+ end
47
+
48
+ def list
49
+ result = get_list
50
+ puts result
51
+ end
52
+
53
+ def perform(action)
54
+ vms = action == "start" ? get_list_registered.split("\n") : get_list_running.split("\n")
55
+ vms.shift
56
+ running_vms = get_list_running.split("\n")
57
+ running_vms.shift
58
+ HighLine.new.choose do |menu|
59
+ menu.prompt = "Choose VM to #{action}: "
60
+ vms.each_with_index do |vm, i|
61
+ vm += " [running]" if running_vms.include?(vm) && action == "start"
62
+ menu.choice(vm) do
63
+ %x[vmrun -T server -h http://#{OPTIONS[:host]}:#{OPTIONS[:port]}/sdk -u #{OPTIONS[:user]} -p #{OPTIONS[:password]} #{action} '#{vm}']
64
+ end
65
+ end
66
+ menu.choice("cancel"){exit;}
67
+ end
68
+ puts get_list_running
69
+ end
70
+
71
+ def get_list(action='list')
72
+ %x[vmrun -T server -h http://#{OPTIONS[:host]}:#{OPTIONS[:port]}/sdk -u #{OPTIONS[:user]} -p #{OPTIONS[:password]} #{action}]
73
+ end
74
+
75
+ def get_list_registered
76
+ get_list("listRegisteredVM")
77
+ end
78
+
79
+ def get_list_running
80
+ get_list("list")
81
+ end
82
+ end
83
+
84
+ Command.invoke(ARGV.first)
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vmanage
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.0"
5
+ platform: ruby
6
+ authors:
7
+ - kates
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-26 00:00:00 +08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: highline
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: |
26
+ A commandline utility to quickly list, start and stop VMs.
27
+
28
+ email: katesgasis@gmail.com
29
+ executables:
30
+ - vmanage
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - lib/vmanage.rb
37
+ has_rdoc: true
38
+ homepage:
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.5
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: A simple VMWare commandline manager
65
+ test_files: []
66
+