rvc 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,6 +11,7 @@ begin
11
11
  gem.add_dependency 'trollop', '>= 1.16.2'
12
12
  gem.add_dependency 'backports', '>= 1.18.2'
13
13
  gem.add_dependency 'highline', '>= 1.6.1'
14
+ gem.add_dependency 'zip', '>= 2.0.2'
14
15
  #gem.add_dependency 'ffi', '>= 1.0.7'
15
16
  end
16
17
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.4
1
+ 1.3.5
@@ -122,7 +122,7 @@ def connect uri, opts
122
122
  Thread.new do
123
123
  while true
124
124
  sleep 600
125
- vim.serviceInstance.RetrieveServiceContent
125
+ vim.serviceInstance.CurrentTime
126
126
  end
127
127
  end
128
128
 
@@ -19,17 +19,28 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require 'tmpdir'
22
+ require 'digest/sha2'
23
+ require 'zip'
24
+ require 'rbconfig'
22
25
 
23
- VMRC_NAME = "vmware-vmrc-linux-x86-3.0.0"
24
- VMRC_PKGVER = 1
25
- VMRC_BASENAME = "#{VMRC_NAME}.#{VMRC_PKGVER}.tar.bz2"
26
- VMRC_URL = "http://cloud.github.com/downloads/vmware/rvc/#{VMRC_BASENAME}"
27
- VMRC_SHA256 = "cda9ba0b0078aee9a7b9704d720ef4c7d74ae2028efb71815d0eb91a5de75921"
26
+ case RbConfig::CONFIG['host_os']
27
+ when /mswin/, /mingw/
28
+ VMRC_NAME = "vmware-vmrc-win32-x86-3.0.0-309851"
29
+ VMRC_SHA256 = "8d8f9655121db5987bef1c2fa3a08ef2c4dd7769eb230bbd5b3ba9fd9576db56"
30
+ VMRC_BIN = "vmware-vmrc.exe"
31
+ when /linux/
32
+ VMRC_NAME = "vmware-vmrc-linux-x86-3.0.0-309851"
33
+ VMRC_SHA256 = "c86ecd9d9a1dd909a119c19d28325cb87d6e2853885d3014a7dac65175dd2ae1"
34
+ VMRC_BIN = "vmware-vmrc"
35
+ else
36
+ $stderr.puts "No VMRC available for OS #{RbConfig::CONFIG['host_os']}"
37
+ end
28
38
 
29
- CURL = ENV['CURL'] || 'curl'
39
+ VMRC_BASENAME = "#{VMRC_NAME}.xpi"
40
+ VMRC_URL = "http://cloud.github.com/downloads/vmware/rvc/#{VMRC_BASENAME}"
30
41
 
31
42
  def find_local_vmrc
32
- path = File.join(Dir.tmpdir, VMRC_NAME, 'plugins', 'vmware-vmrc')
43
+ path = File.join(Dir.tmpdir, VMRC_NAME, 'plugins', VMRC_BIN)
33
44
  File.exists?(path) && path
34
45
  end
35
46
 
@@ -54,6 +65,19 @@ def view vms
54
65
  moref = vm._ref
55
66
  ticket = vm._connection.serviceInstance.content.sessionManager.AcquireCloneTicket
56
67
  host = vm._connection._host
68
+ spawn_vmrc vmrc, moref, host, ticket
69
+ end
70
+ end
71
+
72
+ case RbConfig::CONFIG['host_os']
73
+ when /mswin/, /mingw/
74
+ def spawn_vmrc vmrc, moref, host, ticket
75
+ err "Ruby 1.9 required" unless Process.respond_to? :spawn
76
+ Process.spawn vmrc, '-h', host, '-p', ticket, '-M', moref,
77
+ :err => "#{ENV['HOME']||'.'}/.rvc-vmrc.log"
78
+ end
79
+ else
80
+ def spawn_vmrc vmrc, moref, host, ticket
57
81
  fork do
58
82
  ENV['https_proxy'] = ENV['HTTPS_PROXY'] = ''
59
83
  $stderr.reopen("#{ENV['HOME']||'.'}/.rvc-vmrc.log", "a")
@@ -61,30 +85,71 @@ def view vms
61
85
  $stderr.puts "Using VMRC #{vmrc}"
62
86
  $stderr.flush
63
87
  Process.setpgrp
64
- exec vmrc, '-M', moref,
65
- '-h', host,
66
- '-p', ticket
88
+ exec vmrc, '-M', moref, '-h', host, '-p', ticket
67
89
  end
68
90
  end
69
91
  end
70
92
 
93
+
71
94
  opts :install do
72
95
  summary "Install VMRC"
73
96
  end
74
97
 
75
98
  def install
76
- system "which #{CURL} > /dev/null" or err "curl not found"
77
- system "which sha256sum > /dev/null" or err "sha256sum not found"
99
+ zip_filename = File.join(Dir.tmpdir, VMRC_BASENAME)
100
+ download VMRC_URL, zip_filename
101
+ verify zip_filename, VMRC_SHA256
102
+ extract zip_filename, File.join(Dir.tmpdir, VMRC_NAME)
103
+ puts "VMRC was installed successfully."
104
+ end
105
+
106
+ def download url_str, dest
78
107
  puts "Downloading VMRC..."
79
- dir = Dir.mktmpdir
80
- vmrc_file = "#{dir}/#{VMRC_BASENAME}"
81
- checksum_file = "#{dir}/sha256sums"
82
- system "#{CURL} -L #{VMRC_URL} -o #{vmrc_file}" or err "download failed"
108
+
109
+ url = URI.parse(url_str)
110
+
111
+ http = if ENV['http_proxy']
112
+ proxy_uri = URI.parse(ENV['http_proxy'])
113
+ proxy_user, proxy_pass = proxy_uri.userinfo.split(/:/) if proxy_uri.userinfo
114
+ Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_user, proxy_pass)
115
+ else
116
+ Net::HTTP
117
+ end
118
+
119
+ begin
120
+ File.open(dest, 'wb') do |io|
121
+ res = http.start(url.host, url.port) do |http|
122
+ http.get(url.path) do |segment|
123
+ io.write segment
124
+ end
125
+ end
126
+ end
127
+ rescue Exception
128
+ err "Error downloading VMRC: #{$!.class}: #{$!.message}"
129
+ end
130
+ end
131
+
132
+ def verify filename, expected_hash
83
133
  puts "Checking integrity..."
84
- File.open(checksum_file, 'w') { |io| io.puts "#{VMRC_SHA256} *#{vmrc_file}" }
85
- system "sha256sum -c #{checksum_file}" or err "integrity check failed"
134
+ hexdigest = Digest::SHA256.file(filename).hexdigest
135
+ err "Hash mismatch" if hexdigest != VMRC_SHA256
136
+ end
137
+
138
+ def extract src, dst
86
139
  puts "Installing VMRC..."
87
- system "tar -xj -f #{vmrc_file} -C #{Dir.tmpdir}" or err("VMRC installation failed")
88
- puts "VMRC was installed successfully."
89
- FileUtils.rm_r dir
140
+ FileUtils.mkdir_p dst
141
+ Zip::ZipFile.open(src) do |zf|
142
+ zf.each do |e|
143
+ dst_filename = File.join(dst, e.name)
144
+ case e.ftype
145
+ when :file
146
+ zf.extract e.name, dst_filename
147
+ File.chmod(e.unix_perms, dst_filename) if e.unix_perms
148
+ when :directory
149
+ FileUtils.mkdir_p dst_filename
150
+ else
151
+ $stderr.puts "unknown file type #{e.ftype}"
152
+ end
153
+ end
154
+ end
90
155
  end
@@ -0,0 +1,27 @@
1
+ require 'test/unit'
2
+ require 'rvc'
3
+ require 'inventory_fixtures'
4
+
5
+ class CompletionTest < Test::Unit::TestCase
6
+ NodeBaz = FixtureNode.new
7
+ NodeBar = FixtureNode.new
8
+ NodeFoo = FixtureNode.new('bar' => NodeBar, 'baz' => NodeBaz)
9
+ Root = FixtureNode.new('foo' => NodeFoo)
10
+
11
+ def check word, expected
12
+ got = RVC::Completion::Completor[word]
13
+ assert_equal expected, got
14
+ end
15
+
16
+ def setup
17
+ @context = RVC::Context.new Root
18
+ end
19
+
20
+ def teardown
21
+ @context = nil
22
+ end
23
+
24
+ def test_simple
25
+ check
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ require 'test/unit'
2
+ require 'rvc'
3
+ require 'inventory_fixtures'
4
+
5
+ class OptionParserTest < Test::Unit::TestCase
6
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rvc
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.3.4
5
+ version: 1.3.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rich Lane
@@ -57,6 +57,17 @@ dependencies:
57
57
  version: 1.6.1
58
58
  type: :runtime
59
59
  version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: zip
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.2
69
+ type: :runtime
70
+ version_requirements: *id005
60
71
  description:
61
72
  email: rlane@vmware.com
62
73
  executables:
@@ -112,6 +123,8 @@ files:
112
123
  - test/inventory_fixtures.rb
113
124
  - test/test_fs.rb
114
125
  - test/test_parse_path.rb
126
+ - test/_test_completion.rb
127
+ - test/_test_option_parser.rb
115
128
  has_rdoc: true
116
129
  homepage:
117
130
  licenses: []
@@ -136,11 +149,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
149
  requirements: []
137
150
 
138
151
  rubyforge_project:
139
- rubygems_version: 1.6.2
152
+ rubygems_version: 1.5.3
140
153
  signing_key:
141
154
  specification_version: 3
142
155
  summary: vSphere console UI
143
156
  test_files:
157
+ - test/_test_completion.rb
158
+ - test/_test_option_parser.rb
144
159
  - test/inventory_fixtures.rb
145
160
  - test/test_fs.rb
146
161
  - test/test_parse_path.rb