lorj_cloud 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c97d1a526cc33c76ce049d26943adab2c485c976
4
- data.tar.gz: acfd3212f964e401b51dd8b03d6dabe631e6a1ac
3
+ metadata.gz: 18667a9e2559cedc572e479ea365835bc026849e
4
+ data.tar.gz: 823ba90cf29360f228c5ee561fec98f5d58e8f37
5
5
  SHA512:
6
- metadata.gz: 7f84ffe8eb4fc5d91b8148e3d7779c3416d721f3021ca691b40ef97094ddb456368992f6dd1708d4d1ad42836bd9d848f96e90b5a3962b17decc2a2290c7e0b6
7
- data.tar.gz: 9e0aecb2ca0c8c8a93b124d8ab4dbba4433b8bcc7b2647d2ffc24b1712f6b3fa2745cd2aae91c9ff884bccab832a4fbcd918d2158228fd68ca040ab7b39f9057
6
+ metadata.gz: 4c591e614887169d6badb2e8b434df750ed54f140900993b66c971499f556c3c432f9458c41ef978274e06d3eb0810fbafb9f3f9142ce7924347609a476b971a
7
+ data.tar.gz: 67dbe332d5b8719393a0c2f3af55f9a130a2e05d98da194d29b79be01ded3a3d9683c247df873940a679ff36ebc453999fd61782a6bbcc9995c2d6fe0cb82c39
@@ -1,5 +1,5 @@
1
1
  # LorjCloud module
2
2
  module LorjCloud
3
- VERSION = '0.1.1'
4
- DATE = '2015-05-20'
3
+ VERSION = '0.1.2'
4
+ DATE = '2015-06-15'
5
5
  end
@@ -40,15 +40,22 @@ class CloudProcess
40
40
  #
41
41
  def forj_get_or_create_keypair(sCloudObj, hParams)
42
42
  keypair_name = hParams['credentials#keypair_name']
43
+
43
44
  PrcLib.state("Searching for keypair '%s'", keypair_name)
44
45
 
45
46
  keypair = forj_get_keypair(sCloudObj, keypair_name, hParams)
46
- if keypair.empty?
47
+ if keypair.empty? &&
48
+ hParams.exist?(:keypair_path) && hParams.exist?(:keypair_base)
49
+
47
50
  loc_kpair = keypair_detect(keypair_name, hParams[:keypair_path],
48
51
  hParams[:keypair_base])
49
52
  keypair = keypair_import(hParams, loc_kpair)
50
53
  else
51
- keypair_display(keypair)
54
+ if keypair.empty?
55
+ PrcLib.warning("keypair '%s' was not found.", keypair_name)
56
+ else
57
+ keypair_display(keypair)
58
+ end
52
59
  end
53
60
  keypair
54
61
  end
@@ -56,16 +63,18 @@ class CloudProcess
56
63
  # Query cloud keypairs and check coherence with local files
57
64
  # of same name in forj files located by :keypair_path
58
65
  def forj_query_keypairs(sCloudObj, sQuery, hParams)
59
- keypair_path = File.expand_path(hParams[:keypair_path])
60
- keypair_base = File.expand_path(hParams[:keypair_base])
61
-
62
66
  ssl_error_obj = SSLErrorMgt.new
63
67
  begin
64
68
  keypairs = controller_query(sCloudObj, sQuery)
65
69
  rescue => e
66
70
  retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
67
71
  end
72
+ return keypairs unless hParams.exist?(:keypair_path) &&
73
+ hParams.exist?(:keypair_base)
68
74
  # Looping on keypairs to identify if they have a valid local ssh key.
75
+ keypair_path = File.expand_path(hParams[:keypair_path])
76
+ keypair_base = File.expand_path(hParams[:keypair_base])
77
+
69
78
  keypairs.each do |keypair|
70
79
  loc_kpair = keypair_detect(keypair_name, keypair_path, keypair_base)
71
80
  keypair_files_detected(keypair, loc_kpair)
@@ -83,6 +92,7 @@ class CloudProcess
83
92
  retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
84
93
  end
85
94
 
95
+ return keypair unless hParams.exist?(:keypair_path)
86
96
  keypair_path = File.expand_path(hParams[:keypair_path])
87
97
  loc_kpair = keypair_detect(keypair_name, keypair_path, keypair_name)
88
98
  keypair_files_detected(keypair, loc_kpair) unless keypair.empty?
@@ -103,11 +113,12 @@ class Lorj::BaseDefinition
103
113
 
104
114
  obj_needs :CloudObject, :compute_connection
105
115
  obj_needs :data, 'credentials#keypair_name', :for => [:create_e]
116
+
117
+ obj_needs_optional
118
+ # By default optional. But required by the ssh case if needed.
106
119
  obj_needs :data, :keypair_path
107
120
  obj_needs :data, :keypair_base
108
-
109
121
  # By default optional. But required by the import case if needed.
110
- obj_needs_optional
111
122
  obj_needs :data, :public_key, :for => [:create_e]
112
123
 
113
124
  def_attribute :public_key
@@ -120,6 +131,11 @@ class CloudProcess
120
131
  def keypair_display(keypair)
121
132
  PrcLib.info("Found keypair '%s'.", keypair[:name])
122
133
 
134
+ unless keypair.exist?(:keypair_path)
135
+ PrcLib.info('Unable to verify your keypair with your local files.'\
136
+ ' :keypair_path is missing.')
137
+ return
138
+ end
123
139
  private_key_file = File.join(keypair[:keypair_path],
124
140
  keypair[:private_key_name])
125
141
  public_key_file = File.join(keypair[:keypair_path],
@@ -71,8 +71,8 @@ end
71
71
  class Lorj::BaseDefinition
72
72
  define_obj(:public_ip,
73
73
  :create_e => :forj_get_or_assign_public_address,
74
- :query_e => :forj_query_public_address
75
- # :get_e => :forj_get_address
74
+ :query_e => :forj_query_public_address,
75
+ :get_e => :forj_get_public_address
76
76
  # :update_e => :forj_update_address
77
77
  # :delete_e => :forj_delete_address
78
78
  )
@@ -31,8 +31,21 @@ class CloudProcess
31
31
  register(security_group)
32
32
 
33
33
  PrcLib.info('Configuring Security Group \'%s\'', sg_name)
34
- ports = config.get(:ports)
34
+ if hParams.exist?('server#ports')
35
+ ports = hParams['server#ports']
36
+ else # case kept for compatibility.
37
+ ports = config[:ports]
38
+ end
39
+
40
+ return security_group unless ports.is_a?(Array)
35
41
 
42
+ forj_sg_update_ports(ports)
43
+
44
+ security_group
45
+ end
46
+
47
+ # forj get or create port on SG
48
+ def forj_sg_update_ports(ports)
36
49
  ports.each do |port|
37
50
  port = port.to_s if port.class != String
38
51
  if !(/^\d+(-\d+)?$/ =~ port)
@@ -55,7 +68,6 @@ class CloudProcess
55
68
  process_create(:rule, params)
56
69
  end
57
70
  end
58
- security_group
59
71
  end
60
72
 
61
73
  # Process Delete handler
@@ -80,8 +92,7 @@ class CloudProcess
80
92
  end
81
93
  case sgroups.length
82
94
  when 0
83
- PrcLib.info("No security group '%s' found",
84
- hParams[:security_group])
95
+ PrcLib.info("No security group '%s' found", hParams[:security_group])
85
96
  nil
86
97
  when 1
87
98
  PrcLib.info("Found security group '%s'", sgroups[0, :name])
@@ -102,6 +113,7 @@ class Lorj::BaseDefinition
102
113
  obj_needs :CloudObject, :network_connection
103
114
  obj_needs :data, :security_group, :for => [:create_e]
104
115
  obj_needs_optional
116
+ obj_needs :data, 'server#ports', :for => [:create_e]
105
117
  obj_needs :data, :sg_desc, :for => [:create_e]
106
118
  end
107
119
 
@@ -48,7 +48,7 @@ class CloudProcess
48
48
  def forj_query_server(sCloudObj, sQuery, _hParams)
49
49
  ssl_error_obj = SSLErrorMgt.new
50
50
  begin
51
- controller_query(sCloudObj, sQuery)
51
+ query_single(sCloudObj, sQuery, config[:search_for])
52
52
  rescue => e
53
53
  retry unless ssl_error_obj.error_detected(e.message, e.backtrace, e)
54
54
  end
@@ -93,7 +93,12 @@ class Lorj::BaseDefinition
93
93
  predefine_data_value :boot, :desc => 'Server is booting.'
94
94
  predefine_data_value :active, :desc => 'Server is started.'
95
95
  predefine_data_value :error, :desc => 'Server is in error.'
96
- def_attribute :private_ip_address
96
+ predefine_data_value :shutdown, :desc => 'Server is down.'
97
+ # The private addresses attribute should be composed by
98
+ # network_name:
99
+ # - IP addresses
100
+ # The controller must return at least those structured data.
101
+ def_attribute :private_ip_addresses
97
102
  def_attribute :public_ip_address
98
103
 
99
104
  def_attribute :image_id
@@ -67,6 +67,11 @@ module HPCompute
67
67
  result
68
68
  end
69
69
 
70
+ def self.get_server_assigned_address(oComputeConnect, id)
71
+ addresses = oComputeConnect.addresses.all
72
+ addresses.each { |oElem| return oElem if oElem.attributes['id'] == id }
73
+ end
74
+
70
75
  def self.server_assign_address(oComputeConnect, server)
71
76
  while server.state != 'ACTIVE'
72
77
  sleep(5)
@@ -99,11 +99,13 @@ class Hpcloud
99
99
 
100
100
  # ************************************ SERVER Object
101
101
  define_obj :server
102
+ def_attr_mapping :private_ip_addresses, [:addresses, '{key}', [:addr]]
102
103
  def_attr_mapping :status, :state
103
- attr_value_mapping :create, 'BUILD'
104
- attr_value_mapping :boot, :boot
105
- attr_value_mapping :active, 'ACTIVE'
106
- attr_value_mapping :error, 'ERROR'
104
+ attr_value_mapping :create, 'BUILD'
105
+ attr_value_mapping :boot, :boot
106
+ attr_value_mapping :active, 'ACTIVE'
107
+ attr_value_mapping :error, 'ERROR'
108
+ attr_value_mapping :shutdown, 'SHUTOFF'
107
109
 
108
110
  # ************************************ SERVER log Object
109
111
  define_obj :server_log
@@ -342,7 +344,7 @@ class HpcloudController # rubocop: disable Metrics/ClassLength
342
344
  hParams[:server])
343
345
  end
344
346
  end
345
-
347
+ # rubocop: disable CyclomaticComplexity,
346
348
  def get(sObjectType, sUniqId, hParams)
347
349
  case sObjectType
348
350
  when :server_log
@@ -361,10 +363,16 @@ class HpcloudController # rubocop: disable Metrics/ClassLength
361
363
  when :keypairs
362
364
  required?(hParams, :compute_connection)
363
365
  HPKeyPairs.get_keypair(hParams[:compute_connection], sUniqId)
366
+ when :public_ip
367
+ required?(hParams, :compute_connection)
368
+ required?(hParams, :server)
369
+ HPCompute.get_server_assigned_address(hParams[:compute_connection],
370
+ sUniqId)
364
371
  else
365
372
  forjError "'%s' is not a valid object for 'get'", sObjectType
366
373
  end
367
374
  end
375
+ # rubocop: enable CyclomaticComplexity
368
376
 
369
377
  def query_each(oFogObject)
370
378
  case oFogObject.class.to_s
@@ -209,13 +209,18 @@ class Openstack
209
209
 
210
210
  define_obj :server
211
211
  def_attr_mapping :status, :state
212
- attr_value_mapping :create, 'BUILD'
213
- attr_value_mapping :boot, :boot
214
- attr_value_mapping :active, 'ACTIVE'
215
- attr_value_mapping :error, 'ERROR'
216
-
217
- def_attr_mapping :private_ip_address, :accessIPv4
218
- def_attr_mapping :public_ip_address, :accessIPv4
212
+ attr_value_mapping :create, 'BUILD'
213
+ attr_value_mapping :boot, :boot
214
+ attr_value_mapping :active, 'ACTIVE'
215
+ attr_value_mapping :error, 'ERROR'
216
+ attr_value_mapping :shutdown, 'SHUTOFF'
217
+
218
+ def_attr_mapping :private_ip_addresses,
219
+ [:addresses, '{/.*/}',
220
+ '<%= data["OS-EXT-IPS:type"] == "fixed" %>|addr']
221
+ def_attr_mapping :public_ip_address,
222
+ [:addresses, '{/.*/}',
223
+ '<%= data["OS-EXT-IPS:type"] == "floating" %>|addr']
219
224
  def_attr_mapping :image_id, [:image, 'id']
220
225
 
221
226
  define_obj :router
@@ -32,6 +32,8 @@ class OpenstackController
32
32
 
33
33
  def_get :compute_connection, :keypairs, :key_pairs
34
34
 
35
+ def_get :compute_connection, :public_ip, :addresses
36
+
35
37
  def get_server_log(hParams, sUniqId)
36
38
  required?(hParams, :server)
37
39
  hParams[:server].console(sUniqId)
data/lorj_cloud.gemspec CHANGED
@@ -26,7 +26,8 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "bundler", "~> 1.9"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
28
 
29
- spec.add_runtime_dependency "lorj", "~> 1.0.11"
29
+ spec.add_runtime_dependency "lorj", ">= 1.0.12"
30
+ spec.add_runtime_dependency 'subhash', '>= 0.1.3'
30
31
  spec.add_runtime_dependency "fog", "~> 1.30.0"
31
32
  spec.add_development_dependency "rspec", "~> 3.1.0"
32
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lorj_cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christophe Larsonneur
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-20 00:00:00.000000000 Z
11
+ date: 2015-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,16 +42,30 @@ dependencies:
42
42
  name: lorj
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.0.11
47
+ version: 1.0.12
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.12
55
+ - !ruby/object:Gem::Dependency
56
+ name: subhash
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
53
67
  - !ruby/object:Gem::Version
54
- version: 1.0.11
68
+ version: 0.1.3
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: fog
57
71
  requirement: !ruby/object:Gem::Requirement