vcloud-core 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ ---
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.3
5
+ branches:
6
+ except:
7
+ - master
8
+ notifications:
9
+ email: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.3.0 (2014-05-13)
2
+
3
+ Features:
4
+
5
+ - Switch from deprecated Fog get_network request to get_network_complete
6
+ - Breaking change to OrgVdcNetwork#vcloud_attributes due to Fog deprecation fix
7
+ - Updated vm/vApp logging levels to make use of quiet/normal/verbose operation
8
+
1
9
  ## 0.2.0 (2014-05-06)
2
10
 
3
11
  Features:
data/README.md CHANGED
@@ -145,12 +145,13 @@ If you want to be sure you are pinning to 5.1, or use 5.5, you can set the API v
145
145
 
146
146
  ## Testing
147
147
 
148
- Default target: `bundle exec rake`
149
- Runs the unit tests and feature tests.
148
+ Run the default suite of tests (e.g. lint, unit, features):
150
149
 
151
- * Unit tests only: `bundle exec rake spec`
152
- * Feature tests only: `bundle exec rake features`
153
- * Integration tests: `bundle exec rake integration`
150
+ bundle exec rake
151
+
152
+ Run the integration tests (slower and requires a real environment):
153
+
154
+ bundle exec rake integration
154
155
 
155
156
  ### setting up and describing your environment for test runs
156
157
 
data/Rakefile CHANGED
@@ -22,7 +22,12 @@ RSpec::Core::RakeTask.new('integration') do |t|
22
22
  end
23
23
 
24
24
  require "gem_publisher"
25
- task :publish_gem do |t|
25
+ task :publish_gem do
26
26
  gem = GemPublisher.publish_if_updated("vcloud-core.gemspec", :rubygems)
27
27
  puts "Published #{gem}" if gem
28
28
  end
29
+
30
+ require 'rubocop/rake_task'
31
+ Rubocop::RakeTask.new(:rubocop) do |task|
32
+ task.options = ['--lint']
33
+ end
@@ -3,11 +3,11 @@ require 'ipaddr'
3
3
  module Vcloud
4
4
  module Core
5
5
  class ConfigValidator
6
-
6
+
7
7
  attr_reader :key, :data, :schema, :type, :errors
8
-
8
+
9
9
  VALID_ALPHABETICAL_VALUES_FOR_IP_RANGE = %w(Any external internal)
10
-
10
+
11
11
  def initialize(key, data, schema)
12
12
  raise "Nil schema" unless schema
13
13
  raise "Invalid schema" unless schema.key?(:type)
@@ -18,21 +18,21 @@ module Vcloud
18
18
  @key = key
19
19
  validate
20
20
  end
21
-
21
+
22
22
  def valid?
23
23
  @errors.empty?
24
24
  end
25
-
25
+
26
26
  def self.validate(key, data, schema)
27
27
  new(key, data, schema)
28
28
  end
29
-
29
+
30
30
  private
31
-
31
+
32
32
  def validate
33
33
  self.send("validate_#{type}".to_sym)
34
34
  end
35
-
35
+
36
36
  def validate_string
37
37
  unless @data.is_a? String
38
38
  errors << "#{key}: #{@data} is not a string"
@@ -41,14 +41,14 @@ module Vcloud
41
41
  return unless check_emptyness_ok
42
42
  return unless check_matcher_matches
43
43
  end
44
-
44
+
45
45
  def validate_string_or_number
46
46
  unless data.is_a?(String) || data.is_a?(Numeric)
47
47
  @errors << "#{key}: #{@data} is not a string_or_number"
48
48
  return
49
49
  end
50
50
  end
51
-
51
+
52
52
  def validate_ip_address
53
53
  unless data.is_a?(String)
54
54
  @errors << "#{key}: #{@data} is not a valid ip_address"
@@ -56,7 +56,7 @@ module Vcloud
56
56
  end
57
57
  @errors << "#{key}: #{@data} is not a valid ip_address" unless valid_ip_address?(data)
58
58
  end
59
-
59
+
60
60
  def validate_ip_address_range
61
61
  unless data.is_a?(String)
62
62
  @errors << "#{key}: #{@data} is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."
@@ -65,7 +65,7 @@ module Vcloud
65
65
  valid = valid_cidr_or_ip_address? || valid_alphabetical_ip_range? || valid_ip_range?
66
66
  @errors << "#{key}: #{@data} is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'." unless valid
67
67
  end
68
-
68
+
69
69
  def valid_cidr_or_ip_address?
70
70
  begin
71
71
  ip = IPAddr.new(data)
@@ -74,11 +74,11 @@ module Vcloud
74
74
  false
75
75
  end
76
76
  end
77
-
77
+
78
78
  def valid_alphabetical_ip_range?
79
79
  VALID_ALPHABETICAL_VALUES_FOR_IP_RANGE.include?(data)
80
80
  end
81
-
81
+
82
82
  def valid_ip_address? ip_address
83
83
  begin
84
84
  #valid formats recognized by IPAddr are : “address”, “address/prefixlen” and “address/mask”.
@@ -90,7 +90,7 @@ module Vcloud
90
90
  false
91
91
  end
92
92
  end
93
-
93
+
94
94
  def valid_ip_range?
95
95
  range_parts = data.split('-')
96
96
  return false if range_parts.size != 2
@@ -99,11 +99,11 @@ module Vcloud
99
99
  valid_ip_address?(start_address) && valid_ip_address?(end_address) &&
100
100
  valid_start_and_end_address_combination?(end_address, start_address)
101
101
  end
102
-
102
+
103
103
  def valid_start_and_end_address_combination?(end_address, start_address)
104
104
  IPAddr.new(start_address) < IPAddr.new(end_address)
105
105
  end
106
-
106
+
107
107
  def validate_hash
108
108
  unless data.is_a? Hash
109
109
  @errors << "#{key}: is not a hash"
@@ -118,7 +118,7 @@ module Vcloud
118
118
  end
119
119
  end
120
120
  end
121
-
121
+
122
122
  def validate_array
123
123
  unless data.is_a? Array
124
124
  @errors << "#{key} is not an array"
@@ -135,23 +135,22 @@ module Vcloud
135
135
  end
136
136
  end
137
137
  end
138
-
138
+
139
139
  def validate_enum
140
- unless (acceptable_values = schema[:acceptable_values]) && acceptable_values.is_a?(Array)
141
- raise "Must set :acceptable_values for type 'enum'"
142
- end
140
+ acceptable_values = schema[:acceptable_values]
141
+ raise "Must set :acceptable_values for type 'enum'" unless acceptable_values.is_a?(Array)
143
142
  unless acceptable_values.include?(data)
144
143
  acceptable_values_string = acceptable_values.collect {|v| "'#{v}'" }.join(', ')
145
144
  @errors << "#{key}: #{@data} is not a valid value. Acceptable values are #{acceptable_values_string}."
146
145
  end
147
146
  end
148
-
147
+
149
148
  def validate_boolean
150
149
  unless [true, false].include?(data)
151
150
  @errors << "#{key}: #{data} is not a valid boolean value."
152
151
  end
153
152
  end
154
-
153
+
155
154
  def check_emptyness_ok
156
155
  unless schema.key?(:allowed_empty) && schema[:allowed_empty]
157
156
  if data.empty?
@@ -161,9 +160,10 @@ module Vcloud
161
160
  end
162
161
  true
163
162
  end
164
-
163
+
165
164
  def check_matcher_matches
166
- return unless regex = schema[:matcher]
165
+ regex = schema[:matcher]
166
+ return unless regex
167
167
  raise "#{key}: #{regex} is not a Regexp" unless regex.is_a? Regexp
168
168
  unless data =~ regex
169
169
  @errors << "#{key}: #{data} does not match"
@@ -171,7 +171,7 @@ module Vcloud
171
171
  end
172
172
  true
173
173
  end
174
-
174
+
175
175
  def check_hash_parameter(sub_key, sub_schema)
176
176
  if sub_schema.key?(:required) && sub_schema[:required] == false
177
177
  # short circuit out if we do not have the key, but it's not required.
@@ -190,15 +190,12 @@ module Vcloud
190
190
  @errors = errors + sub_validator.errors
191
191
  end
192
192
  end
193
-
193
+
194
194
  def check_for_unknown_parameters
195
- unless internals = schema[:internals]
196
- # if there are no parameters specified, then assume all are ok.
197
- return true
198
- end
199
- if schema[:permit_unknown_parameters]
200
- return true
201
- end
195
+ internals = schema[:internals]
196
+ # if there are no parameters specified, then assume all are ok.
197
+ return true unless internals
198
+ return true if schema[:permit_unknown_parameters]
202
199
  data.keys.each do |k|
203
200
  @errors << "#{key}: parameter '#{k}' is invalid" unless internals[k]
204
201
  end
@@ -13,10 +13,9 @@ module Vcloud
13
13
 
14
14
  def self.get_ids_by_name(name)
15
15
  q = Vcloud::Core::QueryRunner.new
16
- unless res = q.run('edgeGateway', :filter => "name==#{name}")
17
- raise "Error finding edgeGateway by name #{name}"
18
- end
19
- res.collect do |record|
16
+ query_results = q.run('edgeGateway', :filter => "name==#{name}")
17
+ raise "Error finding edgeGateway by name #{name}" unless query_results
18
+ query_results.collect do |record|
20
19
  record[:href].split('/').last if record.key?(:href)
21
20
  end
22
21
  end
@@ -58,7 +57,8 @@ module Vcloud
58
57
  def interfaces
59
58
  gateway_config = vcloud_attributes[:Configuration]
60
59
  return [] unless gateway_config[:GatewayInterfaces]
61
- return [] unless gateway_interfaces = gateway_config[:GatewayInterfaces][:GatewayInterface]
60
+ gateway_interfaces = gateway_config[:GatewayInterfaces][:GatewayInterface]
61
+ return [] unless gateway_interfaces
62
62
  gateway_interfaces.map do |vcloud_gateway_interface_hash|
63
63
  EdgeGatewayInterface.new(vcloud_gateway_interface_hash)
64
64
  end
@@ -5,20 +5,16 @@ module Vcloud
5
5
  attr_accessor :name, :network_href, :network_name
6
6
 
7
7
  def initialize(gateway_interface_hash)
8
- raise "Argument error: nil not allowed" if gateway_interface_hash.nil?
9
- @vcloud_gateway_interface = gateway_interface_hash
10
- unless @name = gateway_interface_hash[:Name]
11
- raise "Argument error: must have a :Name"
12
- end
13
- unless network_section = gateway_interface_hash[:Network]
14
- raise "Argument error: must have a :Network section"
8
+ if gateway_interface_hash.nil?
9
+ raise "EdgeGatewayInterface: gateway_interface_hash cannot be nil"
15
10
  end
16
- unless @network_href = network_section[:href]
17
- raise "Argument error: must have a :Network[:href]"
18
- end
19
- unless @network_name = network_section[:name]
20
- raise "Argument error: must have a :Network[:name]"
11
+ unless gateway_interface_hash[:Name] && gateway_interface_hash[:Network]
12
+ raise "EdgeGatewayInterface: bad input: #{gateway_interface_hash}"
21
13
  end
14
+ @vcloud_gateway_interface = gateway_interface_hash
15
+ @name = gateway_interface_hash[:Name]
16
+ @network_href = gateway_interface_hash[:Network][:href]
17
+ @network_name = gateway_interface_hash[:Network][:name]
22
18
  end
23
19
 
24
20
  def network_id
@@ -12,13 +12,15 @@ module Vcloud
12
12
  end
13
13
 
14
14
  def self.provision(config)
15
- raise "Must specify a name" unless name = config[:name]
16
- raise "Must specify a vdc_name" unless vdc_name = config[:vdc_name]
17
-
15
+ raise "Must specify a name" unless config[:name]
16
+ raise "Must specify a vdc_name" unless config[:vdc_name]
18
17
  unless config[:fence_mode] == 'isolated' || config[:fence_mode] == 'natRouted'
19
18
  raise "fence_mode #{config[:fence_mode]} not supported. Must be 'isolated' or 'natRouted'"
20
19
  end
21
20
 
21
+ name = config[:name]
22
+ vdc_name = config[:vdc_name]
23
+
22
24
  config[:is_shared] = false unless config[:is_shared]
23
25
 
24
26
  if config[:fence_mode] == 'natRouted'
@@ -44,7 +46,7 @@ module Vcloud
44
46
  end
45
47
 
46
48
  def vcloud_attributes
47
- Vcloud::Fog::ServiceInterface.new.get_network(id)
49
+ Vcloud::Fog::ServiceInterface.new.get_network_complete(id)
48
50
  end
49
51
 
50
52
  def name
@@ -59,8 +61,6 @@ module Vcloud
59
61
  Vcloud::Fog::ServiceInterface.new.delete_network(id)
60
62
  end
61
63
 
62
- private
63
-
64
64
  def self.construct_network_options(config)
65
65
  opts = {}
66
66
  opts[:Description] = config[:description] if config.key?(:description)
@@ -14,14 +14,13 @@ module Vcloud
14
14
 
15
15
  def self.get_by_name(name)
16
16
  q = Vcloud::Core::QueryRunner.new
17
- unless res = q.run('vApp', :filter => "name==#{name}")
18
- raise "Error finding vApp by name #{name}"
19
- end
20
- case res.size
17
+ query_results = q.run('vApp', :filter => "name==#{name}")
18
+ raise "Error finding vApp by name #{name}" unless query_results
19
+ case query_results.size
21
20
  when 0
22
21
  raise "vApp #{name} not found"
23
22
  when 1
24
- return self.new(res.first[:href].split('/').last)
23
+ return self.new(query_results.first[:href].split('/').last)
25
24
  else
26
25
  raise "found multiple vApp entities with name #{name}!"
27
26
  end
@@ -33,6 +32,7 @@ module Vcloud
33
32
 
34
33
  module STATUS
35
34
  RUNNING = 4
35
+ POWERED_OFF = 8
36
36
  end
37
37
 
38
38
  def name
@@ -26,9 +26,8 @@ module Vcloud
26
26
  def self.get_ids_by_name_and_catalog name, catalog_name
27
27
  raise "provide Catalog and vAppTemplate name" unless name && catalog_name
28
28
  q = Vcloud::Core::QueryRunner.new
29
- unless query_results = q.run('vAppTemplate', :filter => "name==#{name};catalogName==#{catalog_name}")
30
- raise "Error retreiving #{q.type} query '#{q.filter}'"
31
- end
29
+ query_results = q.run('vAppTemplate', :filter => "name==#{name};catalogName==#{catalog_name}")
30
+ raise "Error retreiving #{q.type} query '#{q.filter}'" unless query_results
32
31
  query_results.collect do |record|
33
32
  record[:href].split('/').last if record.key?(:href)
34
33
  end
@@ -13,11 +13,10 @@ module Vcloud
13
13
 
14
14
  def self.get_by_name(name)
15
15
  q = Vcloud::Core::QueryRunner.new
16
- unless res = q.run('orgVdc', :filter => "name==#{name}")
17
- raise "Error finding vDC by name #{name}"
18
- end
19
- raise "vDc #{name} not found" unless res.size == 1
20
- return self.new(res.first[:href].split('/').last)
16
+ query_results = q.run('orgVdc', :filter => "name==#{name}")
17
+ raise "Error finding vDC by name #{name}" unless query_results
18
+ raise "vDc #{name} not found" unless query_results.size == 1
19
+ return self.new(query_results.first[:href].split('/').last)
21
20
  end
22
21
 
23
22
  def vcloud_attributes
@@ -1,5 +1,5 @@
1
1
  module Vcloud
2
2
  module Core
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -73,7 +73,7 @@ module Vcloud
73
73
  vm = Vcloud::Fog::ModelInterface.new.get_vm_by_href(href)
74
74
  if extra_disks
75
75
  extra_disks.each do |extra_disk|
76
- Vcloud::Core.logger.info("adding a disk of size #{extra_disk[:size]}MB into VM #{id}")
76
+ Vcloud::Core.logger.debug("adding a disk of size #{extra_disk[:size]}MB into VM #{id}")
77
77
  vm.disks.create(extra_disk[:size])
78
78
  end
79
79
  end
@@ -113,7 +113,6 @@ module Vcloud
113
113
  end
114
114
 
115
115
  def generate_preamble(script_path, script_post_processor, vars)
116
- vapp_name = @vapp.name
117
116
  script = ERB.new(File.read(File.expand_path(script_path)), nil, '>-').result(binding)
118
117
  if script_post_processor
119
118
  script = Open3.capture2(File.expand_path(script_post_processor),
@@ -8,7 +8,7 @@ module Vcloud
8
8
  def_delegators :@fog, :get_vapp, :organizations, :org_name, :delete_vapp, :vcloud_token, :end_point,
9
9
  :get_execute_query, :get_vapp_metadata, :power_off_vapp, :shutdown_vapp, :session,
10
10
  :post_instantiate_vapp_template, :put_memory, :put_cpu, :power_on_vapp, :put_vapp_metadata_value,
11
- :put_vm, :get_edge_gateway, :get_network, :delete_network, :post_create_org_vdc_network,
11
+ :put_vm, :get_edge_gateway, :get_network_complete, :delete_network, :post_create_org_vdc_network,
12
12
  :post_configure_edge_gateway_services
13
13
 
14
14
  #########################
@@ -40,14 +40,14 @@ module Vcloud
40
40
  end
41
41
 
42
42
  def post_instantiate_vapp_template(vdc, template, name, params)
43
- Vcloud::Core.logger.info("instantiating #{name} vapp in #{vdc[:name]}")
43
+ Vcloud::Core.logger.debug("instantiating #{name} vapp in #{vdc[:name]}")
44
44
  vapp = @vcloud.post_instantiate_vapp_template(extract_id(vdc), template, name, params).body
45
45
  @vcloud.process_task(vapp[:Tasks][:Task])
46
46
  @vcloud.get_vapp(extract_id(vapp)).body
47
47
  end
48
48
 
49
49
  def put_memory(vm_id, memory)
50
- Vcloud::Core.logger.info("putting #{memory}MB memory into VM #{vm_id}")
50
+ Vcloud::Core.logger.debug("putting #{memory}MB memory into VM #{vm_id}")
51
51
  task = @vcloud.put_memory(vm_id, memory).body
52
52
  @vcloud.process_task(task)
53
53
  end
@@ -62,13 +62,13 @@ module Vcloud
62
62
  end
63
63
 
64
64
  def put_cpu(vm_id, cpu)
65
- Vcloud::Core.logger.info("putting #{cpu} CPU(s) into VM #{vm_id}")
65
+ Vcloud::Core.logger.debug("putting #{cpu} CPU(s) into VM #{vm_id}")
66
66
  task = @vcloud.put_cpu(vm_id, cpu).body
67
67
  @vcloud.process_task(task)
68
68
  end
69
69
 
70
70
  def put_vm(id, name, options={})
71
- Vcloud::Core.logger.info("updating name : #{name}, :options => #{options} in vm : #{id}")
71
+ Vcloud::Core.logger.debug("updating name : #{name}, :options => #{options} in vm : #{id}")
72
72
  task = @vcloud.put_vm(id, name, options).body
73
73
  @vcloud.process_task(task)
74
74
  end
@@ -108,8 +108,8 @@ module Vcloud
108
108
  @vcloud.process_task(task)
109
109
  end
110
110
 
111
- def get_network(id)
112
- @vcloud.get_network(id).body
111
+ def get_network_complete(id)
112
+ @vcloud.get_network_complete(id).body
113
113
  end
114
114
 
115
115
  def delete_network(id)
@@ -118,10 +118,10 @@ module Vcloud
118
118
  end
119
119
 
120
120
  def post_create_org_vdc_network(vdc_id, name, options)
121
- Vcloud::Core.logger.info("creating #{options[:fence_mode]} OrgVdcNetwork #{name} in vDC #{vdc_id}")
121
+ Vcloud::Core.logger.debug("creating #{options[:fence_mode]} OrgVdcNetwork #{name} in vDC #{vdc_id}")
122
122
  attrs = @vcloud.post_create_org_vdc_network(vdc_id, name, options).body
123
123
  @vcloud.process_task(attrs[:Tasks][:Task])
124
- get_network(extract_id(attrs))
124
+ get_network_complete(extract_id(attrs))
125
125
  end
126
126
 
127
127
  def post_configure_edge_gateway_services(edgegw_id, config)
@@ -129,7 +129,7 @@ module Vcloud
129
129
  begin
130
130
  task = @vcloud.post_configure_edge_gateway_services(edgegw_id, config).body
131
131
  @vcloud.process_task(task)
132
- rescue Exception => ex
132
+ rescue => ex
133
133
  Vcloud::Core.logger.error("Could not update EdgeGateway #{edgegw_id} : #{ex}")
134
134
  raise
135
135
  end
@@ -141,7 +141,7 @@ module Vcloud
141
141
  end
142
142
 
143
143
  def power_on_vapp(vapp_id)
144
- Vcloud::Core.logger.info("Powering on vApp #{vapp_id}")
144
+ Vcloud::Core.logger.debug("Powering on vApp #{vapp_id}")
145
145
  task = @vcloud.post_power_on_vapp(vapp_id).body
146
146
  @vcloud.process_task(task)
147
147
  end
@@ -156,7 +156,7 @@ module Vcloud
156
156
  end
157
157
 
158
158
  def put_vapp_metadata_value(id, k, v)
159
- Vcloud::Core.logger.info("putting metadata pair '#{k}'=>'#{v}' to #{id}")
159
+ Vcloud::Core.logger.debug("putting metadata pair '#{k}'=>'#{v}' to #{id}")
160
160
  # need to convert key to_s since Fog 0.17 borks on symbol key
161
161
  task = @vcloud.put_vapp_metadata_item_metadata(id, k.to_s, v).body
162
162
  @vcloud.process_task(task)
@@ -203,11 +203,11 @@ module Vcloud
203
203
 
204
204
  def put_network_connection_system_section_vapp(vm_id, section)
205
205
  begin
206
- Vcloud::Core.logger.info("adding NIC into VM #{vm_id}")
206
+ Vcloud::Core.logger.debug("adding NIC into VM #{vm_id}")
207
207
  @fog.put_network_connection_system_section_vapp(vm_id, section)
208
- rescue
209
- Vcloud::Core.logger.info("failed to put_network_connection_system_section_vapp for vm : #{vm_id} ")
210
- Vcloud::Core.logger.info("requested network section : #{section.inspect}")
208
+ rescue => ex
209
+ Vcloud::Core.logger.error("failed to put_network_connection_system_section_vapp for vm #{vm_id}: #{ex}")
210
+ Vcloud::Core.logger.debug("requested network section : #{section.inspect}")
211
211
  raise
212
212
  end
213
213
  end
@@ -222,16 +222,17 @@ module Vcloud
222
222
 
223
223
  def put_guest_customization_section(vm_id, vm_name, script)
224
224
  begin
225
- Vcloud::Core.logger.info("configuring guest customization section for vm : #{vm_id}")
225
+ Vcloud::Core.logger.debug("configuring guest customization section for vm : #{vm_id}")
226
226
  customization_req = {
227
227
  :Enabled => true,
228
228
  :CustomizationScript => script,
229
229
  :ComputerName => vm_name
230
230
  }
231
231
  @fog.put_guest_customization_section_vapp(vm_id, customization_req)
232
- rescue
233
- Vcloud::Core.logger.info("=== interpolated preamble:")
234
- Vcloud::Core.logger.info(script)
232
+ rescue => ex
233
+ Vcloud::Core.logger.error("Failed to update guest customization section: #{ex}")
234
+ Vcloud::Core.logger.debug("=== interpolated preamble:")
235
+ Vcloud::Core.logger.debug(script)
235
236
  raise
236
237
  end
237
238
  end
@@ -8,7 +8,7 @@ class StubFogInterface
8
8
 
9
9
  def vdc_object_by_name(vdc_name)
10
10
  vdc = OpenStruct.new
11
- vdc.name = 'test-vdc-1'
11
+ vdc.name = vdc_name
12
12
  vdc
13
13
  end
14
14
 
@@ -16,7 +16,7 @@ class StubFogInterface
16
16
  { :href => '/vappTemplate-12345678-90ab-cdef-0123-4567890abcde' }
17
17
  end
18
18
 
19
- def find_networks(network_names, vdc_name)
19
+ def find_networks(_network_names, _vdc_name)
20
20
  [{
21
21
  :name => 'org-vdc-1-net-1',
22
22
  :href => '/org-vdc-1-net-1-id',
@@ -24,7 +24,10 @@ class StubFogInterface
24
24
  end
25
25
 
26
26
  def get_vapp(id)
27
- { :name => 'test-vapp-1' }
27
+ {
28
+ :name => 'test-vapp-1',
29
+ :href => "/#{id}",
30
+ }
28
31
  end
29
32
 
30
33
  def get_edge_gateway(id)
@@ -34,11 +37,11 @@ class StubFogInterface
34
37
  }
35
38
  end
36
39
 
37
- def vdc(name)
40
+ def vdc(_name)
38
41
  { }
39
42
  end
40
43
 
41
- def post_instantiate_vapp_template(vdc, template, name, params)
44
+ def post_instantiate_vapp_template(_vdc, _template, _name, _params)
42
45
  {
43
46
  :href => '/test-vapp-1-id',
44
47
  :Children => {
@@ -51,7 +54,7 @@ class StubFogInterface
51
54
  { }
52
55
  end
53
56
 
54
- def template(catalog_name, name)
57
+ def template(_catalog_name, _name)
55
58
  { :href => '/vappTemplate-12345678-90ab-cdef-0123-4567890abcde' }
56
59
  end
57
60
 
@@ -4,5 +4,6 @@
4
4
 
5
5
  (
6
6
  echo "in $*"
7
+ echo "vapp_name: <%= vapp_name -%>"
7
8
  echo "message: <%= vars[:message] -%>"
8
9
  ) >> /PREAMBLE_OUTPUT
@@ -4,5 +4,6 @@
4
4
 
5
5
  (
6
6
  echo "in $*"
7
+ echo "vapp_name: test-vapp-1"
7
8
  echo "message: hello world"
8
9
  ) >> /PREAMBLE_OUTPUT
@@ -40,31 +40,18 @@ module Vcloud
40
40
  end
41
41
 
42
42
  it "should raise an error if passed a nil value" do
43
- expect { EdgeGatewayInterface.new(nil) }.to raise_error("Argument error: nil not allowed")
43
+ expect { EdgeGatewayInterface.new(nil) }.
44
+ to raise_error(StandardError, /^EdgeGatewayInterface:/)
44
45
  end
45
46
 
46
47
  it "should raise an error if a :Name is not passed" do
47
- expect { EdgeGatewayInterface.new({}) }.to raise_error("Argument error: must have a :Name")
48
+ expect { EdgeGatewayInterface.new({}) }.
49
+ to raise_error(StandardError, /^EdgeGatewayInterface:/)
48
50
  end
49
51
 
50
52
  it "should raise an error if a :Network is not passed" do
51
- expect { EdgeGatewayInterface.new({Name: 'test-interface'}) }.to raise_error("Argument error: must have a :Network section")
52
- end
53
-
54
- it "should raise an error if a :Network :href is not passed" do
55
- bad_input = {
56
- Name: 'test-interface',
57
- Network: { name: "test-network" }
58
- }
59
- expect { EdgeGatewayInterface.new(bad_input) }.to raise_error("Argument error: must have a :Network[:href]")
60
- end
61
-
62
- it "should raise an error if a :Network :name is not passed" do
63
- bad_input = {
64
- Name: 'test-interface',
65
- Network: { href: "http://example.com/1234" }
66
- }
67
- expect { EdgeGatewayInterface.new(bad_input) }.to raise_error("Argument error: must have a :Network[:name]")
53
+ expect { EdgeGatewayInterface.new({Name: 'test-interface'}) }.
54
+ to raise_error(StandardError, /^EdgeGatewayInterface:/)
68
55
  end
69
56
 
70
57
  end
@@ -32,7 +32,7 @@ module Vcloud
32
32
 
33
33
  it "should store the id specified" do
34
34
  obj = EdgeGateway.new(@edgegw_id)
35
- expect(obj.id) == @edgegw_id
35
+ expect(obj.id).to eq(@edgegw_id)
36
36
  end
37
37
 
38
38
  it "should raise error if id is not in correct format" do
@@ -63,7 +63,7 @@ module Vcloud
63
63
  Vcloud::Core::QueryRunner.should_receive(:new).and_return(mock_query)
64
64
  mock_query.should_receive(:run).with('edgeGateway', :filter => "name==edgegw-test-1").and_return(q_results)
65
65
  @obj = EdgeGateway.get_by_name('edgegw-test-1')
66
- expect(@obj.id) == @edgegw_id
66
+ expect(@obj.id).to eq(@edgegw_id)
67
67
  end
68
68
 
69
69
  it "should raise an error if no edgegw with that name exists" do
@@ -31,11 +31,11 @@ module Vcloud
31
31
  }
32
32
  ]
33
33
  metadata = MetadataHelper.extract_metadata(metadata_entries)
34
- metadata.count.should == 4
35
- metadata[:role_name].should == 'james-bond'
36
- metadata[:server_number].should == -10
37
- metadata[:created_at].should == DateTime.parse("2013-12-16T14:30:05.000Z")
38
- metadata[:daily_shutdown].should == false
34
+ expect(metadata.count).to eq(4)
35
+ expect(metadata[:role_name]).to eq('james-bond')
36
+ expect(metadata[:server_number]).to eq(-10)
37
+ expect(metadata[:created_at]).to eq(DateTime.parse("2013-12-16T14:30:05.000Z"))
38
+ expect(metadata[:daily_shutdown]).to be_false
39
39
  end
40
40
 
41
41
  it "should skip metadata entry if entry type is not application/vnd.vmware.vcloud.metadata.value+xml" do
@@ -54,7 +54,7 @@ module Vcloud
54
54
 
55
55
  ]
56
56
  metadata = MetadataHelper.extract_metadata(metadata_entries)
57
- metadata.count.should == 1
57
+ expect(metadata.count).to eq(1)
58
58
  metadata.keys.should_not include :untyped_key
59
59
  end
60
60
 
@@ -75,7 +75,7 @@ module Vcloud
75
75
 
76
76
  ]
77
77
  metadata = MetadataHelper.extract_metadata(metadata_entries)
78
- metadata.count.should == 2
78
+ expect(metadata.count).to eq(2)
79
79
  metadata.keys.should include :unrecognized_type_key
80
80
  end
81
81
 
@@ -4,7 +4,7 @@ module Vcloud
4
4
  module Core
5
5
  describe OrgVdcNetwork do
6
6
 
7
- before (:each) do
7
+ before(:each) do
8
8
  @vdc_id = '12345678-1234-1234-1234-000000111111'
9
9
  @edgegw_id = '12345678-1234-1234-1234-000000222222'
10
10
  @net_id = '12345678-1234-1234-1234-000000333333'
@@ -38,7 +38,7 @@ module Vcloud
38
38
 
39
39
  it "should store the id specified" do
40
40
  obj = OrgVdcNetwork.new(@net_id)
41
- expect(obj.id) == @net_id
41
+ expect(obj.id).to eq(@net_id)
42
42
  end
43
43
 
44
44
  it "should raise error if id is not in correct format" do
@@ -136,7 +136,7 @@ module Vcloud
136
136
  with(@vdc_id, @config[:name], expected_vcloud_attrs).
137
137
  and_return({ :href => "/#{@net_id}" })
138
138
  obj = Vcloud::Core::OrgVdcNetwork.provision(@config)
139
- expect(obj.id) == @net_id
139
+ expect(obj.id).to eq(@net_id)
140
140
  end
141
141
 
142
142
  it "should handle specification of one ip_ranges" do
@@ -165,7 +165,7 @@ module Vcloud
165
165
  @mock_fog_interface.should_receive(:post_create_org_vdc_network).
166
166
  with(@vdc_id, @config[:name], expected_vcloud_attrs).
167
167
  and_return({ :href => "/#{@net_id}" })
168
- obj = Vcloud::Core::OrgVdcNetwork.provision(@config)
168
+ Vcloud::Core::OrgVdcNetwork.provision(@config)
169
169
  end
170
170
 
171
171
  it "should handle specification of two ip_ranges" do
@@ -203,7 +203,7 @@ module Vcloud
203
203
  @mock_fog_interface.should_receive(:post_create_org_vdc_network).
204
204
  with(@vdc_id, @config[:name], expected_vcloud_attrs).
205
205
  and_return({ :href => "/#{@net_id}" })
206
- obj = Vcloud::Core::OrgVdcNetwork.provision(@config)
206
+ Vcloud::Core::OrgVdcNetwork.provision(@config)
207
207
  end
208
208
 
209
209
  end
@@ -245,7 +245,7 @@ module Vcloud
245
245
  @mock_fog_interface.should_receive(:post_create_org_vdc_network).
246
246
  with(@vdc_id, @config[:name], expected_vcloud_attrs).
247
247
  and_return({ :href => "/#{@net_id}" })
248
- obj = Vcloud::Core::OrgVdcNetwork.provision(@config)
248
+ Vcloud::Core::OrgVdcNetwork.provision(@config)
249
249
  end
250
250
 
251
251
  end
@@ -12,7 +12,7 @@ describe Vcloud::Core::QueryRunner do
12
12
  it 'should return empty array if no query type links are returned from API' do
13
13
  @mock_fog_interface.stub(:get_execute_query).and_return({:Link => {}})
14
14
  result = @query_runner.available_query_types
15
- result.size.should == 0
15
+ expect(result.size).to eq(0)
16
16
  end
17
17
 
18
18
  it 'returns queriable entity types provided by the API via :href link elements' do
@@ -52,10 +52,7 @@ describe Vcloud::Core::QueryRunner do
52
52
 
53
53
  it 'should return no results when fog returns no results' do
54
54
  @mock_fog_interface.stub(:get_execute_query).and_return({})
55
-
56
- result = @query_runner.run()
57
-
58
- result.should == []
55
+ expect(@query_runner.run()).to eq([])
59
56
  end
60
57
 
61
58
  it 'return no results when fog results do not include a "Record" or a "Reference"' do
@@ -64,10 +61,7 @@ describe Vcloud::Core::QueryRunner do
64
61
  :WibbleBlob => {:field1 => 'Stuff 1'}
65
62
  }
66
63
  )
67
-
68
- result = @query_runner.run()
69
-
70
- result.size.should == 0
64
+ expect(@query_runner.run().size).to eq(0)
71
65
  end
72
66
 
73
67
  it 'should return a single result when fog returns a single record' do
@@ -77,11 +71,9 @@ describe Vcloud::Core::QueryRunner do
77
71
  :WibbleRecord => [fields]
78
72
  }
79
73
  )
80
-
81
74
  result = @query_runner.run()
82
-
83
- result.size.should == 1
84
- result[0].should == fields
75
+ expect(result.size).to eq(1)
76
+ expect(result.first).to eq(fields)
85
77
  end
86
78
 
87
79
  it 'should return a single result when fog returns a single reference' do
@@ -91,11 +83,9 @@ describe Vcloud::Core::QueryRunner do
91
83
  :WibbleReference => [fields]
92
84
  }
93
85
  )
94
-
95
86
  result = @query_runner.run()
96
-
97
- result.size.should == 1
98
- result[0].should == fields
87
+ expect(result.size).to eq(1)
88
+ expect(result.first).to eq(fields)
99
89
  end
100
90
 
101
91
  it 'should wrap single result from fog in list' do
@@ -105,11 +95,9 @@ describe Vcloud::Core::QueryRunner do
105
95
  :WibbleRecord => fields
106
96
  }
107
97
  )
108
-
109
98
  result = @query_runner.run()
110
-
111
- result.size.should == 1
112
- result[0].should == fields
99
+ expect(result.size).to eq(1)
100
+ expect(result.first).to eq(fields)
113
101
  end
114
102
 
115
103
  it 'should return all results in a record returned by fog' do
@@ -120,12 +108,10 @@ describe Vcloud::Core::QueryRunner do
120
108
  :WibbleRecord => [fields, more_fields]
121
109
  }
122
110
  )
123
-
124
111
  result = @query_runner.run()
125
-
126
- result.size.should == 2
127
- result[0].should == fields
128
- result[1].should == more_fields
112
+ expect(result.size).to eq(2)
113
+ expect(result[0]).to eq(fields)
114
+ expect(result[1]).to eq(more_fields)
129
115
  end
130
116
 
131
117
  it 'should return the first item if more than one records provided' do
@@ -137,11 +123,9 @@ describe Vcloud::Core::QueryRunner do
137
123
  :WobbleRecord => [fields2]
138
124
  }
139
125
  )
140
-
141
126
  result = @query_runner.run()
142
-
143
- result.size.should == 1
144
- result[0].should == fields1
127
+ expect(result.size).to eq(1)
128
+ expect(result.first).to eq(fields1)
145
129
  end
146
130
 
147
131
  it 'should raise error if lastPage is not an integer' do
@@ -162,13 +146,12 @@ describe Vcloud::Core::QueryRunner do
162
146
  :lastPage => 2,
163
147
  :WibbleRecord => [fields]
164
148
  }
165
-
166
149
  )
167
150
  result = @query_runner.run()
168
-
169
- result.size.should == 2
170
- result[0].should == fields
171
- result[1].should == fields
151
+ expect(result.size).to eq(2)
152
+ expect(result[0]).to eq(fields)
153
+ expect(result[1]).to eq(fields)
172
154
  end
155
+
173
156
  end
174
157
  end
@@ -36,7 +36,7 @@ module Vcloud
36
36
 
37
37
  it "should store the id specified" do
38
38
  obj = Vapp.new(@vapp_id)
39
- expect(obj.id) == @vapp_id
39
+ expect(obj.id).to eq(@vapp_id)
40
40
  end
41
41
 
42
42
  it "should raise error if id is not in correct format" do
@@ -99,13 +99,13 @@ module Vcloud
99
99
 
100
100
  context "id" do
101
101
  it "should extract id correctly" do
102
- @vapp.id.should == @vapp_id
102
+ expect(@vapp.id).to eq(@vapp_id)
103
103
  end
104
104
  end
105
105
 
106
106
  context "vapp should have parent vdc" do
107
107
  it "should load parent vdc id from fog attributes" do
108
- @vapp.vdc_id.should == '074aea1e-a5e9-4dd1-a028-40db8c98d237'
108
+ expect(@vapp.vdc_id).to eq('074aea1e-a5e9-4dd1-a028-40db8c98d237')
109
109
  end
110
110
 
111
111
  it "should raise error if vapp without parent vdc found" do
@@ -115,8 +115,8 @@ module Vcloud
115
115
  end
116
116
 
117
117
  it "should return vms" do
118
- @vapp.fog_vms.count.should == 1
119
- @vapp.fog_vms.first[:href].should == '/vm-123aea1e-a5e9-4dd1-a028-40db8c98d237'
118
+ expect(@vapp.fog_vms.count).to eq(1)
119
+ expect(@vapp.fog_vms.first[:href]).to eq('/vm-123aea1e-a5e9-4dd1-a028-40db8c98d237')
120
120
  end
121
121
  end
122
122
 
@@ -136,18 +136,23 @@ module Vcloud
136
136
 
137
137
  it "should power on a vapp that is not powered on" do
138
138
  vapp = Vapp.new(@vapp_id)
139
- @mock_fog_interface.should_receive(:get_vapp).twice().and_return({:status => 8})
139
+ @mock_fog_interface.should_receive(:get_vapp).twice().and_return(
140
+ {:status => Vcloud::Core::Vapp::STATUS::POWERED_OFF},
141
+ {:status => Vcloud::Core::Vapp::STATUS::RUNNING}
142
+ )
140
143
  @mock_fog_interface.should_receive(:power_on_vapp).with(vapp.id)
141
144
  state = vapp.power_on
142
- expect(state) == true
145
+ expect(state).to be_true
143
146
  end
144
147
 
145
148
  it "should not power on a vapp that is already powered on, but should return true" do
146
149
  vapp = Vapp.new(@vapp_id)
147
- @mock_fog_interface.should_receive(:get_vapp).and_return({:status => 4})
150
+ @mock_fog_interface.should_receive(:get_vapp).and_return(
151
+ {:status => Vcloud::Core::Vapp::STATUS::RUNNING}
152
+ )
148
153
  @mock_fog_interface.should_not_receive(:power_on_vapp)
149
154
  state = vapp.power_on
150
- expect(state) == true
155
+ expect(state).to be_true
151
156
  end
152
157
  end
153
158
 
@@ -158,14 +163,14 @@ module Vcloud
158
163
  it "should return nil if fog returns nil" do
159
164
  StubFogInterface.any_instance.stub(:get_vapp_by_name_and_vdc_name)
160
165
  .with('vapp_name', 'vdc_name').and_return(nil)
161
- Vapp.get_by_name_and_vdc_name('vapp_name', 'vdc_name').should == nil
166
+ expect(Vapp.get_by_name_and_vdc_name('vapp_name', 'vdc_name')).to be_nil
162
167
  end
163
168
 
164
169
  it "should return vapp instance if found" do
165
170
  vcloud_attr_vapp = { :href => "/#{@vapp_id}" }
166
171
  StubFogInterface.any_instance.stub(:get_vapp_by_name_and_vdc_name)
167
172
  .with('vapp_name', 'vdc_name').and_return(vcloud_attr_vapp)
168
- Vapp.get_by_name_and_vdc_name('vapp_name', 'vdc_name').class.should == Core::Vapp
173
+ expect(Vapp.get_by_name_and_vdc_name('vapp_name', 'vdc_name').class).to eq(Core::Vapp)
169
174
  end
170
175
 
171
176
  end
@@ -35,7 +35,7 @@ module Vcloud
35
35
 
36
36
  it "should store the id specified" do
37
37
  obj = VappTemplate.new(@id)
38
- expect(obj.id) == @id
38
+ expect(obj.id).to eq(@id)
39
39
  end
40
40
 
41
41
  it "should raise error if id is not in correct format" do
@@ -30,7 +30,7 @@ module Vcloud
30
30
 
31
31
  it "should store the id specified" do
32
32
  obj = Vdc.new(@vdc_id)
33
- expect(obj.id) == @vdc_id
33
+ expect(obj.id).to eq(@vdc_id)
34
34
  end
35
35
 
36
36
  it "should raise error if id is not in correct format" do
@@ -70,7 +70,7 @@ module Vcloud
70
70
 
71
71
  it "should store the id specified" do
72
72
  obj = Vm.new(@vm_id, @mock_vapp)
73
- expect(obj.id) == @vm_id
73
+ expect(obj.id).to eq(@vm_id)
74
74
  end
75
75
 
76
76
  it "should raise error if id is not in correct format" do
@@ -181,7 +181,7 @@ module Vcloud
181
181
  end
182
182
 
183
183
  context '#generate_preamble' do
184
- it "should interpolate vars hash into template" do
184
+ it "should interpolate vars hash and vapp_name into template" do
185
185
  vars = {:message => 'hello world'}
186
186
  erbfile = "#{@data_dir}/basic_preamble_test.erb"
187
187
  expected_output = File.read("#{erbfile}.OUT")
data/vcloud-core.gemspec CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  s.add_development_dependency 'cucumber', '~> 1.3.10'
30
30
  s.add_development_dependency 'rake'
31
31
  s.add_development_dependency 'rspec', '~> 2.14.1'
32
+ s.add_development_dependency 'rubocop'
32
33
  s.add_development_dependency 'simplecov', '~> 0.8.2'
33
34
  s.add_development_dependency 'gem_publisher', '1.2.0'
34
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcloud-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-06 00:00:00.000000000 Z
12
+ date: 2014-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -123,6 +123,22 @@ dependencies:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
125
  version: 2.14.1
126
+ - !ruby/object:Gem::Dependency
127
+ name: rubocop
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
126
142
  - !ruby/object:Gem::Dependency
127
143
  name: simplecov
128
144
  requirement: !ruby/object:Gem::Requirement
@@ -165,6 +181,7 @@ extensions: []
165
181
  extra_rdoc_files: []
166
182
  files:
167
183
  - .gitignore
184
+ - .travis.yml
168
185
  - CHANGELOG.md
169
186
  - Gemfile
170
187
  - LICENSE.txt
@@ -245,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
262
  version: '0'
246
263
  segments:
247
264
  - 0
248
- hash: -1619325784245789607
265
+ hash: 2968796492213479520
249
266
  requirements: []
250
267
  rubyforge_project:
251
268
  rubygems_version: 1.8.23