vcautils 0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/bin/compute +3 -0
- data/bin/vca +3 -0
- data/bin/vchs +3 -0
- data/lib/compute.rb +403 -0
- data/lib/modules/compute-be.rb +108 -0
- data/lib/modules/vca-be.rb +215 -0
- data/lib/modules/vchs-be.rb +63 -0
- data/lib/vca.rb +514 -0
- data/lib/vchs.rb +298 -0
- metadata +177 -0
data/lib/vchs.rb
ADDED
@@ -0,0 +1,298 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
#################################################################################
|
4
|
+
#### Massimo Re Ferre' ####
|
5
|
+
#### www.it20.info ####
|
6
|
+
#### vcautils, a set of utilities for vCloud Air Consumers ####
|
7
|
+
#################################################################################
|
8
|
+
|
9
|
+
|
10
|
+
#################################################################################
|
11
|
+
#### vcasubscriptions.rb is the front end program for vCA Subscription ####
|
12
|
+
#### It leverages the vcautils library ####
|
13
|
+
#################################################################################
|
14
|
+
|
15
|
+
|
16
|
+
#################################################################################
|
17
|
+
#### IMPORTANT !! ####
|
18
|
+
#### The program reads a file called vcautils.yml in the working directory ####
|
19
|
+
#### If the file does not exist the program will abort ####
|
20
|
+
#### The file is used to provide the program with connectivity parameters ####
|
21
|
+
#################################################################################
|
22
|
+
|
23
|
+
# This is the format of the vcautils.yml file:
|
24
|
+
# :username: email@domain
|
25
|
+
# :password: password
|
26
|
+
# :serviceroot: https://vca.vmware.com
|
27
|
+
# :mode: admin | developer
|
28
|
+
|
29
|
+
# These are the additional modules/gems required to run the program
|
30
|
+
|
31
|
+
require 'httparty'
|
32
|
+
require 'yaml'
|
33
|
+
require 'xml-fu'
|
34
|
+
require 'pp'
|
35
|
+
require 'json'
|
36
|
+
require 'awesome_print' #optional - useful for debugging
|
37
|
+
|
38
|
+
require 'modules/vchs-be'
|
39
|
+
|
40
|
+
|
41
|
+
# We stole this piece of code (silence_warnings) from the Internet.
|
42
|
+
# We are using it to silence the warnings of the certificates settings (below)
|
43
|
+
|
44
|
+
|
45
|
+
def silence_warnings(&block)
|
46
|
+
warn_level = $VERBOSE
|
47
|
+
$VERBOSE = nil
|
48
|
+
result = block.call
|
49
|
+
$VERBOSE = warn_level
|
50
|
+
result
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
#=begin
|
58
|
+
class String
|
59
|
+
def black; "\033[30m#{self}\033[0m" end
|
60
|
+
def red; "\033[31m#{self}\033[0m" end
|
61
|
+
def green; "\033[32m#{self}\033[0m" end
|
62
|
+
def brown; "\033[33m#{self}\033[0m" end
|
63
|
+
def blue; "\033[34m#{self}\033[0m" end
|
64
|
+
def magenta; "\033[35m#{self}\033[0m" end
|
65
|
+
def cyan; "\033[36m#{self}\033[0m" end
|
66
|
+
def gray; "\033[37m#{self}\033[0m" end
|
67
|
+
def bg_black; "\033[40m#{self}\033[0m" end
|
68
|
+
def bg_red; "\033[41m#{self}\033[0m" end
|
69
|
+
def bg_green; "\033[42m#{self}\033[0m" end
|
70
|
+
def bg_brown; "\033[43m#{self}\033[0m" end
|
71
|
+
def bg_blue; "\033[44m#{self}\033[0m" end
|
72
|
+
def bg_magenta; "\033[45m#{self}\033[0m" end
|
73
|
+
def bg_cyan; "\033[46m#{self}\033[0m" end
|
74
|
+
def bg_gray; "\033[47m#{self}\033[0m" end
|
75
|
+
def bold; "\033[1m#{self}\033[22m" end
|
76
|
+
def reverse_color; "\033[7m#{self}\033[27m" end
|
77
|
+
end #String
|
78
|
+
#=end
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
# This bypass certification checks... NOT a great idea for production but ok for test / dev
|
85
|
+
|
86
|
+
silence_warnings do
|
87
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
# This is what the program accepts as input
|
92
|
+
|
93
|
+
def usage
|
94
|
+
puts "\te.g. vchs services".green
|
95
|
+
puts "\te.g. vchs service".green + " <serviceId>".magenta
|
96
|
+
puts "\te.g. vchs service".green + " <serviceId>".magenta + " <VDC name>".magenta
|
97
|
+
puts "\n"
|
98
|
+
|
99
|
+
end #usage
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
# These are the variables the program accept as inputs (see the usage section for more info)
|
104
|
+
|
105
|
+
$input0 = ARGV[0]
|
106
|
+
|
107
|
+
$input1 = ARGV[1]
|
108
|
+
|
109
|
+
$input2 = ARGV[2]
|
110
|
+
|
111
|
+
$input3 = ARGV[3]
|
112
|
+
|
113
|
+
$input4 = ARGV[4]
|
114
|
+
|
115
|
+
|
116
|
+
# The if checks if the user called an operation. If not the case, we print the text on how to use the CLI
|
117
|
+
|
118
|
+
|
119
|
+
if $input0
|
120
|
+
|
121
|
+
# We login (the login method is in vcautilscore)
|
122
|
+
|
123
|
+
file_path = "vcautils.yml"
|
124
|
+
raise "no file #{file_path}" unless File.exists? file_path
|
125
|
+
configuration = YAML.load_file(file_path)
|
126
|
+
username = configuration[:username]
|
127
|
+
password = configuration[:password]
|
128
|
+
vchsserviceroot = "https://vchs.vmware.com"
|
129
|
+
mode = configuration[:mode]
|
130
|
+
vchsloginserviceroot = "https://vchs.vmware.com"
|
131
|
+
acceptheadercompute = "application/*+xml;version=5.6"
|
132
|
+
|
133
|
+
puts
|
134
|
+
puts "Logging in ...\n\n"
|
135
|
+
|
136
|
+
vchs = Vchs.new()
|
137
|
+
|
138
|
+
token = vchs.login(username, password, vchsloginserviceroot)
|
139
|
+
|
140
|
+
|
141
|
+
case $input0.chomp
|
142
|
+
|
143
|
+
|
144
|
+
when 'token'
|
145
|
+
puts "OAuth token:\n".green + token
|
146
|
+
|
147
|
+
|
148
|
+
when 'services'
|
149
|
+
servicesarray = vchs.services(token, vchsserviceroot)
|
150
|
+
if mode == "developer" then puts JSON.pretty_generate(servicesarray) end
|
151
|
+
if servicesarray['Services']['Service'].any?
|
152
|
+
servicesarray['Services']['Service'].length.times do |i|
|
153
|
+
puts "region : ".green + servicesarray['Services']['Service'][i]["region"].blue
|
154
|
+
puts "serviceId : ".green + servicesarray['Services']['Service'][i]["serviceId"].blue
|
155
|
+
puts "serviceType : ".green + servicesarray['Services']['Service'][i]["serviceType"].blue
|
156
|
+
puts "type : ".green + servicesarray['Services']['Service'][i]["type"].blue
|
157
|
+
puts "href : ".green + servicesarray['Services']['Service'][i]["href"].blue
|
158
|
+
puts
|
159
|
+
end #servicesarray['Services']['Service'].length.times do |i|
|
160
|
+
|
161
|
+
else #if servicesarray['Services']['Service'].any?
|
162
|
+
puts
|
163
|
+
puts "Sorry, this account doesn't have any resource associated".red
|
164
|
+
puts
|
165
|
+
end #if servicesarray['Services']['Service'].any?
|
166
|
+
|
167
|
+
|
168
|
+
when 'service'
|
169
|
+
servicesarray = vchs.services(token, vchsserviceroot)
|
170
|
+
if $input1
|
171
|
+
if servicesarray['Services']['Service'].any?
|
172
|
+
serviceexists = false
|
173
|
+
servicesarray["Services"]["Service"].length.times do |i|
|
174
|
+
if servicesarray["Services"]["Service"][i]["serviceId"] == $input1
|
175
|
+
serviceexists = true
|
176
|
+
vdcssarray = vchs.vdcs(token, servicesarray["Services"]["Service"][i]["href"])
|
177
|
+
if mode == "developer" then puts JSON.pretty_generate(vdcssarray) end
|
178
|
+
puts
|
179
|
+
if $input2
|
180
|
+
vdcexists = false
|
181
|
+
vdcssarray['Compute']['VdcRef'].length.times do |i|
|
182
|
+
if vdcssarray['Compute']['VdcRef'][i]["name"] == $input2
|
183
|
+
vdcexists = true
|
184
|
+
computeattributes = vchs.computeattributes(token, vdcssarray['Compute']['VdcRef'][i]['Link']['href'])
|
185
|
+
if mode == "developer" then puts JSON.pretty_generate(computeattributes) end
|
186
|
+
puts
|
187
|
+
puts "href : ".green + computeattributes['VCloudSession']['VdcLink']["href"].blue
|
188
|
+
puts "authorizationToken : ".green + computeattributes['VCloudSession']['VdcLink']["authorizationToken"].blue
|
189
|
+
puts "authorizationHeader : ".green + computeattributes['VCloudSession']['VdcLink']["authorizationHeader"].blue
|
190
|
+
puts
|
191
|
+
puts "friendly API URL handoff : ".green + computeattributes['VCloudSession']['VdcLink']["href"][0..41].blue + 'org/'.blue + vdcssarray['Compute']['VdcRef'][i]["name"].blue
|
192
|
+
puts "friendly <vCD Org name> is : ".green + vdcssarray['Compute']['VdcRef'][i]["name"].blue
|
193
|
+
puts
|
194
|
+
end # if vdcssarray['Compute']['VdcRef'][i]["name"] == $input2
|
195
|
+
end #vdcssarray['Compute']['VdcRef'].length.times do |i|
|
196
|
+
|
197
|
+
if vdcexists == false
|
198
|
+
puts
|
199
|
+
puts "The VDC ".red + $input2.blue + " does not exist".red
|
200
|
+
puts
|
201
|
+
end #if vdcexists exists
|
202
|
+
|
203
|
+
else #if $input2
|
204
|
+
vdcssarray['Compute']['VdcRef'].length.times do |i|
|
205
|
+
puts "name : ".green + vdcssarray['Compute']['VdcRef'][i]["name"].blue
|
206
|
+
puts "status : ".green + vdcssarray['Compute']['VdcRef'][i]["status"].blue
|
207
|
+
puts "type : ".green + vdcssarray['Compute']['VdcRef'][i]["type"].blue
|
208
|
+
puts "href : ".green + vdcssarray['Compute']['VdcRef'][i]["href"].blue
|
209
|
+
puts
|
210
|
+
end #vdcssarray['Compute']['VdcRef'].length.times do |i|
|
211
|
+
end #if $input2
|
212
|
+
end #if servicesarray["Services"]["Service"][i]["serviceId"] == $input1
|
213
|
+
end #servicesarray["Services"]["Service"].length.times do |i|
|
214
|
+
else #servicesarray['Services']['Service'].any?
|
215
|
+
puts
|
216
|
+
puts "Sorry, this account doesn't have any resource associated".red
|
217
|
+
puts
|
218
|
+
end #servicesarray['Services']['Service'].any?
|
219
|
+
|
220
|
+
else #if $input1
|
221
|
+
puts
|
222
|
+
puts "You need to specify a serviceId".red
|
223
|
+
puts
|
224
|
+
end #if $input1
|
225
|
+
|
226
|
+
if serviceexists == false
|
227
|
+
puts
|
228
|
+
puts "The serviceId ".red + $input1.blue + " does not exist".red
|
229
|
+
puts
|
230
|
+
end #if instance exists
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
else #case $input0
|
236
|
+
puts "\n"
|
237
|
+
puts "Noooooope!".red
|
238
|
+
puts "\n"
|
239
|
+
usage()
|
240
|
+
puts "\n"
|
241
|
+
|
242
|
+
end #case $input0.chomp
|
243
|
+
|
244
|
+
|
245
|
+
# If the user did not specify an operation at all we suggest how to properly use the CLI
|
246
|
+
|
247
|
+
else #if $input0
|
248
|
+
puts "\n"
|
249
|
+
puts "Use any of the following operations".red
|
250
|
+
puts "\n"
|
251
|
+
usage()
|
252
|
+
puts "\n"
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
end #main if
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vcautils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.7'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Massimo Re Ferrè
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.13.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: xml-fu
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: awesome_print
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.6.1
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '1.6'
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.6.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: gon-sinatra
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.1.2
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 0.1.2
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: json
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ~>
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.8'
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.8.2
|
85
|
+
type: :runtime
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ~>
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '1.8'
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.8.2
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: sinatra
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '1.4'
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 1.4.5
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ~>
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '1.4'
|
112
|
+
- - ! '>='
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 1.4.5
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: rack-ssl
|
117
|
+
requirement: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ~>
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '1.4'
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.4.1
|
125
|
+
type: :runtime
|
126
|
+
prerelease: false
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.4'
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 1.4.1
|
135
|
+
description: A set of tools to programmatically access VMware vCloud Air
|
136
|
+
email: massimo@it20.info
|
137
|
+
executables:
|
138
|
+
- vca
|
139
|
+
- vchs
|
140
|
+
- compute
|
141
|
+
extensions: []
|
142
|
+
extra_rdoc_files: []
|
143
|
+
files:
|
144
|
+
- bin/compute
|
145
|
+
- bin/vca
|
146
|
+
- bin/vchs
|
147
|
+
- lib/compute.rb
|
148
|
+
- lib/modules/compute-be.rb
|
149
|
+
- lib/modules/vca-be.rb
|
150
|
+
- lib/modules/vchs-be.rb
|
151
|
+
- lib/vca.rb
|
152
|
+
- lib/vchs.rb
|
153
|
+
homepage: http://it20.info
|
154
|
+
licenses:
|
155
|
+
- Apache License
|
156
|
+
metadata: {}
|
157
|
+
post_install_message:
|
158
|
+
rdoc_options: []
|
159
|
+
require_paths:
|
160
|
+
- lib
|
161
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 1.9.3
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ! '>='
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
requirements: []
|
172
|
+
rubyforge_project:
|
173
|
+
rubygems_version: 2.4.5
|
174
|
+
signing_key:
|
175
|
+
specification_version: 4
|
176
|
+
summary: VMware vCloud Air Utilities
|
177
|
+
test_files: []
|