deltacloud-core 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (242) hide show
  1. data/LICENSE +145 -0
  2. data/NOTICE +10 -1
  3. data/Rakefile +50 -2
  4. data/bin/deltacloudd +111 -14
  5. data/config/addresses.xml +14 -0
  6. data/config/condor.yaml +30 -0
  7. data/config/drivers/azure.yaml +3 -0
  8. data/config/drivers/condor.yaml +3 -0
  9. data/config/{drivers.yaml → drivers/ec2.yaml} +5 -34
  10. data/config/drivers/eucalyptus.yaml +8 -0
  11. data/config/drivers/gogrid.yaml +3 -0
  12. data/config/drivers/mock.yaml +3 -0
  13. data/config/drivers/opennebula.yaml +4 -0
  14. data/config/drivers/rackspace.yaml +3 -0
  15. data/config/drivers/rhevm.yaml +3 -0
  16. data/config/drivers/rimuhosting.yaml +3 -0
  17. data/config/drivers/sbc.yaml +2 -0
  18. data/config/drivers/terremark.yaml +3 -0
  19. data/config/drivers/vsphere.yaml +8 -0
  20. data/deltacloud-core.gemspec +13 -5
  21. data/deltacloud.rb +4 -2
  22. data/lib/deltacloud/backend_capability.rb +2 -2
  23. data/lib/deltacloud/base_driver/base_driver.rb +23 -52
  24. data/lib/deltacloud/base_driver/exceptions.rb +168 -0
  25. data/lib/deltacloud/base_driver/features.rb +31 -12
  26. data/lib/deltacloud/base_driver/mock_driver.rb +2 -1
  27. data/lib/deltacloud/core_ext/string.rb +2 -0
  28. data/lib/deltacloud/drivers/azure/azure_driver.rb +5 -5
  29. data/lib/deltacloud/drivers/condor/condor_client.rb +273 -0
  30. data/lib/deltacloud/drivers/condor/condor_driver.rb +236 -0
  31. data/lib/deltacloud/drivers/condor/ip_agents/confserver.rb +75 -0
  32. data/lib/deltacloud/drivers/condor/ip_agents/default.rb +84 -0
  33. data/lib/deltacloud/drivers/ec2/ec2_driver.rb +326 -95
  34. data/lib/deltacloud/drivers/ec2/ec2_mock_driver.rb +3 -3
  35. data/lib/deltacloud/drivers/eucalyptus/eucalyptus_driver.rb +40 -8
  36. data/lib/deltacloud/drivers/gogrid/gogrid_client.rb +7 -7
  37. data/lib/deltacloud/drivers/gogrid/gogrid_driver.rb +42 -25
  38. data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob1.yml +6 -4
  39. data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob2.yml +7 -5
  40. data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob3.yml +6 -4
  41. data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob4.yml +6 -4
  42. data/lib/deltacloud/drivers/mock/data/{buckets/blobs → blobs}/blob5.yml +6 -4
  43. data/lib/deltacloud/drivers/mock/data/buckets/bucket1.yml +7 -1
  44. data/lib/deltacloud/drivers/mock/data/buckets/bucket2.yml +6 -1
  45. data/lib/deltacloud/drivers/mock/data/images/img1.yml +6 -2
  46. data/lib/deltacloud/drivers/mock/data/images/img2.yml +6 -2
  47. data/lib/deltacloud/drivers/mock/data/images/img3.yml +6 -2
  48. data/lib/deltacloud/drivers/mock/data/instances/inst0.yml +11 -10
  49. data/lib/deltacloud/drivers/mock/data/instances/inst1.yml +14 -7
  50. data/lib/deltacloud/drivers/mock/data/instances/inst2.yml +14 -7
  51. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap1.yml +3 -2
  52. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap2.yml +3 -2
  53. data/lib/deltacloud/drivers/mock/data/storage_snapshots/snap3.yml +3 -2
  54. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol1.yml +4 -3
  55. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol2.yml +4 -3
  56. data/lib/deltacloud/drivers/mock/data/storage_volumes/vol3.yml +4 -3
  57. data/lib/deltacloud/drivers/mock/mock_client.rb +101 -0
  58. data/lib/deltacloud/drivers/mock/mock_driver.rb +367 -429
  59. data/lib/deltacloud/drivers/opennebula/opennebula_driver.rb +6 -0
  60. data/lib/deltacloud/drivers/rackspace/rackspace_driver.rb +59 -9
  61. data/lib/deltacloud/drivers/rhevm/rhevm_client.rb +62 -8
  62. data/lib/deltacloud/drivers/rhevm/rhevm_driver.rb +100 -45
  63. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_client.rb +3 -2
  64. data/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb +8 -11
  65. data/lib/deltacloud/drivers/sbc/sbc_client.rb +6 -6
  66. data/lib/deltacloud/drivers/sbc/sbc_driver.rb +16 -0
  67. data/lib/deltacloud/drivers/terremark/terremark_driver.rb +17 -12
  68. data/lib/deltacloud/drivers/vsphere/vsphere_client.rb +140 -0
  69. data/lib/deltacloud/drivers/vsphere/vsphere_driver.rb +405 -0
  70. data/lib/deltacloud/drivers/vsphere/vsphere_filemanager.rb +182 -0
  71. data/lib/deltacloud/hardware_profile.rb +1 -1
  72. data/lib/deltacloud/helpers.rb +2 -1
  73. data/lib/deltacloud/helpers/application_helper.rb +92 -20
  74. data/lib/deltacloud/helpers/blob_stream.rb +160 -12
  75. data/lib/deltacloud/helpers/conversion_helper.rb +6 -2
  76. data/lib/deltacloud/helpers/json_helper.rb +31 -0
  77. data/lib/deltacloud/models/address.rb +28 -0
  78. data/lib/deltacloud/models/base_model.rb +5 -1
  79. data/lib/deltacloud/models/blob.rb +1 -1
  80. data/lib/deltacloud/models/bucket.rb +10 -0
  81. data/lib/deltacloud/models/firewall.rb +22 -0
  82. data/lib/deltacloud/models/firewall_rule.rb +23 -0
  83. data/lib/deltacloud/models/image.rb +12 -0
  84. data/lib/deltacloud/models/instance.rb +20 -2
  85. data/lib/deltacloud/models/key.rb +1 -1
  86. data/lib/deltacloud/runner.rb +3 -3
  87. data/lib/deltacloud/validation.rb +3 -7
  88. data/lib/drivers.rb +7 -1
  89. data/lib/sinatra/body_proxy.rb +34 -0
  90. data/lib/sinatra/lazy_auth.rb +5 -0
  91. data/lib/sinatra/rabbit.rb +54 -31
  92. data/lib/sinatra/rack_accept.rb +157 -0
  93. data/lib/sinatra/rack_date.rb +38 -0
  94. data/lib/sinatra/rack_etag.rb +2 -3
  95. data/lib/sinatra/rack_matrix_params.rb +51 -29
  96. data/lib/sinatra/rack_runtime.rb +1 -1
  97. data/lib/sinatra/rack_syslog.rb +86 -0
  98. data/lib/sinatra/url_for.rb +14 -1
  99. data/public/images/address.png +0 -0
  100. data/public/images/balancer.png +0 -0
  101. data/public/images/blob.png +0 -0
  102. data/public/images/bucket.png +0 -0
  103. data/public/images/cloud.png +0 -0
  104. data/public/images/firewall.png +0 -0
  105. data/public/images/image.png +0 -0
  106. data/public/images/key.png +0 -0
  107. data/public/images/machine.png +0 -0
  108. data/public/images/profile.png +0 -0
  109. data/public/images/realm.png +0 -0
  110. data/public/images/snapshot.png +0 -0
  111. data/public/images/volume.png +0 -0
  112. data/public/javascripts/application.js +119 -16
  113. data/public/javascripts/jquery.min.js +18 -0
  114. data/public/javascripts/jquery.mobile-1.0b1.min.js +146 -0
  115. data/public/stylesheets/compiled/application.css +8 -0
  116. data/public/stylesheets/images/ajax-loader.png +0 -0
  117. data/public/{images → stylesheets/images}/bread-bg.png +0 -0
  118. data/public/{images → stylesheets/images}/error.png +0 -0
  119. data/public/{images → stylesheets/images}/grid.png +0 -0
  120. data/public/stylesheets/images/icon-search-black.png +0 -0
  121. data/public/stylesheets/images/icons-18-black.png +0 -0
  122. data/public/stylesheets/images/icons-18-white.png +0 -0
  123. data/public/stylesheets/images/icons-36-black.png +0 -0
  124. data/public/stylesheets/images/icons-36-white.png +0 -0
  125. data/public/{images → stylesheets/images}/logo-wide.png +0 -0
  126. data/public/{images → stylesheets/images}/pending.png +0 -0
  127. data/public/{images → stylesheets/images}/rails.png +0 -0
  128. data/public/{images → stylesheets/images}/running.png +0 -0
  129. data/public/{images → stylesheets/images}/stopped.png +0 -0
  130. data/public/{images → stylesheets/images}/topbar-bg.png +0 -0
  131. data/public/stylesheets/jquery.mobile-1.0b1.min.css +8 -0
  132. data/public/stylesheets/new.css +53 -0
  133. data/server.rb +487 -175
  134. data/support/condor/bash/cached_images.sh +8 -0
  135. data/support/condor/bash/cloud_exit_hook.sh +17 -0
  136. data/support/condor/bash/cloud_functions +175 -0
  137. data/support/condor/bash/cloud_prepare_hook.sh +20 -0
  138. data/support/condor/bash/libvirt_cloud_script.sh +13 -0
  139. data/support/condor/config/50condor_cloud.config +37 -0
  140. data/support/condor/config/50condor_cloud_node.config +37 -0
  141. data/support/condor/config/condor-cloud +2 -0
  142. data/support/condor/config/condor_config.local +44 -0
  143. data/support/fedora/deltacloud-core +48 -26
  144. data/support/fedora/deltacloud-core-config +26 -0
  145. data/support/fedora/deltacloud-core.spec +314 -68
  146. data/support/fedora/deltacloudd-fedora +5 -0
  147. data/tests/common.rb +34 -4
  148. data/tests/drivers/mock/api_test.rb +3 -3
  149. data/tests/drivers/mock/images_test.rb +12 -0
  150. data/tests/drivers/mock/instances_test.rb +2 -0
  151. data/tests/rabbit_test.rb +2 -2
  152. data/views/addresses/_address.html.haml +6 -0
  153. data/views/addresses/associate.html.haml +12 -0
  154. data/views/addresses/index.html.haml +9 -0
  155. data/views/addresses/index.xml.haml +4 -0
  156. data/views/addresses/show.html.haml +21 -0
  157. data/views/addresses/show.xml.haml +14 -0
  158. data/views/api/show.html.haml +6 -11
  159. data/views/api/show.xml.haml +2 -0
  160. data/views/blobs/new.html.haml +24 -23
  161. data/views/blobs/show.html.haml +30 -31
  162. data/views/buckets/index.html.haml +9 -21
  163. data/views/buckets/index.xml.haml +3 -7
  164. data/views/buckets/new.html.haml +13 -12
  165. data/views/buckets/show.html.haml +22 -22
  166. data/views/buckets/show.xml.haml +5 -3
  167. data/views/docs/collection.html.haml +23 -34
  168. data/views/docs/collection.xml.haml +2 -2
  169. data/views/docs/index.html.haml +9 -13
  170. data/views/docs/index.xml.haml +1 -1
  171. data/views/docs/operation.html.haml +28 -38
  172. data/views/docs/operation.xml.haml +1 -1
  173. data/views/drivers/index.html.haml +8 -13
  174. data/views/drivers/show.html.haml +18 -18
  175. data/views/error.html.haml +32 -27
  176. data/views/errors/400.html.haml +41 -0
  177. data/views/errors/{validation_failure.xml.haml → 400.xml.haml} +0 -4
  178. data/views/errors/401.html.haml +41 -0
  179. data/views/errors/{auth_exception.xml.haml → 401.xml.haml} +0 -0
  180. data/views/errors/403.html.haml +42 -0
  181. data/views/errors/{not_allowed.xml.haml → 403.xml.haml} +0 -0
  182. data/views/errors/404.html.haml +29 -0
  183. data/views/errors/{not_found.xml.haml → 404.xml.haml} +1 -1
  184. data/views/errors/405.html.haml +29 -0
  185. data/views/errors/405.xml.haml +5 -0
  186. data/views/errors/500.html.haml +43 -0
  187. data/views/errors/500.xml.haml +5 -0
  188. data/views/errors/502.html.haml +43 -0
  189. data/views/errors/{backend_error.xml.haml → 502.xml.haml} +1 -2
  190. data/views/errors/backend_capability_failure.html.haml +27 -9
  191. data/views/firewalls/index.html.haml +15 -0
  192. data/views/firewalls/index.xml.haml +28 -0
  193. data/views/firewalls/new.html.haml +11 -0
  194. data/views/firewalls/new_rule.html.haml +20 -0
  195. data/views/firewalls/show.html.haml +42 -0
  196. data/views/firewalls/show.xml.haml +26 -0
  197. data/views/hardware_profiles/index.html.haml +15 -23
  198. data/views/hardware_profiles/show.html.haml +22 -18
  199. data/views/images/index.html.haml +11 -23
  200. data/views/images/index.xml.haml +4 -13
  201. data/views/images/new.html.haml +12 -13
  202. data/views/images/show.html.haml +26 -20
  203. data/views/images/show.xml.haml +2 -1
  204. data/views/instance_states/show.html.haml +21 -25
  205. data/views/instances/index.html.haml +13 -30
  206. data/views/instances/index.xml.haml +2 -23
  207. data/views/instances/new.html.haml +83 -88
  208. data/views/instances/show.html.haml +53 -55
  209. data/views/instances/show.xml.haml +12 -10
  210. data/views/keys/index.html.haml +13 -24
  211. data/views/keys/new.html.haml +7 -7
  212. data/views/keys/show.html.haml +26 -21
  213. data/views/layout.html.haml +28 -27
  214. data/views/load_balancers/index.html.haml +11 -31
  215. data/views/load_balancers/index.xml.haml +0 -1
  216. data/views/load_balancers/new.html.haml +1 -1
  217. data/views/load_balancers/show.html.haml +33 -34
  218. data/views/load_balancers/show.xml.haml +2 -2
  219. data/views/realms/index.html.haml +11 -24
  220. data/views/realms/index.xml.haml +2 -8
  221. data/views/realms/show.html.haml +17 -15
  222. data/views/realms/show.xml.haml +2 -1
  223. data/views/storage_snapshots/index.html.haml +11 -21
  224. data/views/storage_snapshots/index.xml.haml +2 -5
  225. data/views/storage_snapshots/new.html.haml +1 -1
  226. data/views/storage_snapshots/show.html.haml +21 -13
  227. data/views/storage_snapshots/show.xml.haml +2 -1
  228. data/views/storage_volumes/index.html.haml +11 -34
  229. data/views/storage_volumes/new.html.haml +1 -1
  230. data/views/storage_volumes/show.html.haml +33 -27
  231. data/views/storage_volumes/show.xml.haml +2 -1
  232. metadata +266 -178
  233. data/lib/sinatra/respond_to.rb +0 -248
  234. data/support/fedora/deltacloudd +0 -128
  235. data/support/fedora/rubygem-deltacloud-core.spec +0 -127
  236. data/views/accounts/index.html.haml +0 -11
  237. data/views/accounts/show.html.haml +0 -30
  238. data/views/errors/auth_exception.html.haml +0 -8
  239. data/views/errors/backend_error.html.haml +0 -22
  240. data/views/errors/not_allowed.html.haml +0 -6
  241. data/views/errors/not_found.html.haml +0 -6
  242. data/views/errors/validation_failure.html.haml +0 -11
@@ -16,7 +16,7 @@
16
16
 
17
17
  module RightAws
18
18
  class MockEc2
19
-
19
+
20
20
  def initialize(opts={})
21
21
  end
22
22
 
@@ -161,7 +161,7 @@ module RightAws
161
161
  instance[:aws_launch_time] = instance_time_format
162
162
  instances = load_fixtures_for(:instances)
163
163
  instances.each_with_index do |inst, i|
164
- instances[i] = instance if inst[:aws_instance_id].eql?(id)
164
+ instances[i] = instance if inst[:aws_instance_id].eql?(id)
165
165
  end
166
166
  update_fixtures_for(:instances, instances)
167
167
  return instance
@@ -178,7 +178,7 @@ Deltacloud::Drivers::EC2::EC2Driver.class_eval do
178
178
 
179
179
  def new_client(credentials, opts={})
180
180
  if credentials.user != 'mockuser' and credentials.password != 'mockpassword'
181
- raise Deltacloud::AuthException.new
181
+ raise "AuthFailure"
182
182
  end
183
183
  RightAws::MockEc2.new
184
184
  end
@@ -22,12 +22,12 @@ module Deltacloud
22
22
  class EucalyptusDriver < EC2::EC2Driver
23
23
 
24
24
  def supported_collections
25
- DEFAULT_COLLECTIONS + [ :keys, :buckets ]
25
+ DEFAULT_COLLECTIONS + [ :keys, :buckets, :addresses, :firewalls ]
26
26
  end
27
27
 
28
28
  feature :instances, :user_data
29
29
  feature :instances, :authentication_key
30
- feature :instances, :security_group
30
+ feature :instances, :firewalls
31
31
  feature :instances, :instance_count
32
32
  feature :images, :owner_id
33
33
 
@@ -75,17 +75,13 @@ module Deltacloud
75
75
  end
76
76
 
77
77
  def default_image_owner
78
- "self"
78
+ nil # list all images
79
79
  end
80
80
 
81
81
  def default_image_type
82
82
  nil
83
83
  end
84
84
 
85
- def tagging?
86
- false
87
- end
88
-
89
85
  def tag_instance(credentials, instance, name)
90
86
  # dummy
91
87
  end
@@ -126,6 +122,42 @@ module Deltacloud
126
122
  "Loadbalancer not supported in Eucalyptus", "")
127
123
  end
128
124
 
125
+ # override EC2 implementation; Eucalyptus implements the older definition of EC2 security group;
126
+ # http://docs.amazonwebservices.com/AWSEC2/2009-07-15/APIReference/index.html?ApiReference-query-AuthorizeSecurityGroupIngress.html
127
+ # if the rule specifies a source group, port&protocol will be ignored. And source group and cidr range can't be mixed in a request
128
+ def create_firewall_rule(credentials, opts={})
129
+ # only either source groups or cidr IP range can be given, not both;
130
+ if !(opts['groups'].nil?) && opts['groups'].length>0
131
+ ec2 = new_client(credentials)
132
+ opts['groups'].each do |group,owner|
133
+ safely do
134
+ ec2.authorize_security_group_named_ingress(opts['id'], owner, group)
135
+ end
136
+ end
137
+ elsif !(opts['addresses'].nil?) && opts['addresses'].length>0
138
+ ec2 = new_client(credentials)
139
+ opts['addresses'].each do |ip|
140
+ ec2.authorize_security_group_IP_ingress(opts['id'], opts['port_from'], opts['port_to'], opts['protocol'], ip)
141
+ end
142
+ end
143
+ end
144
+
145
+ def delete_firewall_rule(credentials, opts={})
146
+ ec2 = new_client(credentials)
147
+ firewall = opts[:firewall]
148
+ protocol, from_port, to_port, addresses, groups = firewall_rule_params(opts[:rule_id])
149
+ unless groups.nil?
150
+ groups.each_index do |i|
151
+ ec2.revoke_security_group_named_ingress(firewall, groups[i]['owner'], groups[i]['group_name'])
152
+ end
153
+ end
154
+ unless addresses.nil?
155
+ addresses.each do |ip|
156
+ ec2.revoke_security_group_IP_ingress(firewall, from_port, to_port, protocol, ip )
157
+ end
158
+ end
159
+ end
160
+
129
161
  def new_client(credentials, type = :ec2)
130
162
  klass = case type
131
163
  when :ec2 then Aws::Ec2
@@ -147,7 +179,7 @@ module Deltacloud
147
179
 
148
180
  def endpoint_for_service(service)
149
181
  service = service.to_s
150
- endpoint = (Thread.current[:provider] || ENV['API_PROVIDER'])
182
+ endpoint = api_provider
151
183
  if endpoint && endpoint.include?(service)
152
184
  # example endpoint: 'ec2=192.168.1.1; s3=192.168.1.2'
153
185
  addr = Hash[endpoint.split(";").map { |svc| svc.strip.split("=") }][service]
@@ -42,25 +42,25 @@ class GoGridClient
42
42
 
43
43
  def initialize(server='https://api.gogrid.com/api',
44
44
  apikey='YOUR API KEY',
45
- secret='YOUR SHARED SECRET',
45
+ secret='YOUR SHARED SECRET',
46
46
  format='json',
47
47
  version='1.6')
48
48
  @server = server
49
49
  @secret = secret
50
50
  @default_params = {'format'=>format, 'v'=>version,'api_key' => apikey}
51
- end
52
-
51
+ end
52
+
53
53
  def getRequestURL(method,params)
54
54
  requestURL = @server+'/'+method+'?'
55
55
  call_params = @default_params.merge(params)
56
56
  call_params['sig']=getSignature(@default_params['api_key'],@secret)
57
57
  requestURL = requestURL+encode_params(call_params)
58
58
  end
59
-
59
+
60
60
  def getSignature(key,secret)
61
61
  Digest::MD5.hexdigest(key+secret+"%.0f"%Time.new.to_f)
62
62
  end
63
-
63
+
64
64
  def sendAPIRequest(method,params={})
65
65
  OpenURI.without_ssl_verification do
66
66
  open(getRequestURL(method,params)).read
@@ -76,9 +76,9 @@ class GoGridClient
76
76
  request = sendAPIRequest(method, params)
77
77
  JSON::parse(request)
78
78
  end
79
-
79
+
80
80
  def encode_params(params)
81
81
  params.map {|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join("&")
82
82
  end
83
-
83
+
84
84
  end
@@ -35,6 +35,11 @@ class GogridDriver < Deltacloud::BaseDriver
35
35
 
36
36
  feature :instances, :authentication_password
37
37
  feature :instances, :sandboxing
38
+ feature :instances, :user_name do
39
+ constraint :max_length, 20
40
+ end
41
+
42
+ USER_NAME_MAX = feature(:instances, :user_name).constraints[:max_length]
38
43
 
39
44
  def hardware_profiles(credentials, opts={})
40
45
  client = new_client(credentials)
@@ -43,7 +48,7 @@ class GogridDriver < Deltacloud::BaseDriver
43
48
  server_rams = client.request('common/lookup/list', { 'lookup' => 'server.ram' })
44
49
  @hardware_profiles = []
45
50
  server_types['list'].each do |type|
46
- memory_values = server_rams['list'].collect do |r|
51
+ memory_values = server_rams['list'].collect do |r|
47
52
  r['name'] =~ /MB$/ ? r['name'].gsub(/MB$/, '').to_i : (r['name'].gsub(/(\w{2})$/, '')).to_i*1024
48
53
  end
49
54
  @hardware_profiles << ::Deltacloud::HardwareProfile.new(type['name'].tr(' ', '-').downcase) do
@@ -79,11 +84,14 @@ class GogridDriver < Deltacloud::BaseDriver
79
84
  end
80
85
 
81
86
  def realms(credentials, opts=nil)
87
+ realms = []
88
+ client = new_client(credentials)
82
89
  safely do
83
- new_client(credentials).request('common/lookup/list', { 'lookup' => 'ip.datacenter' })['list'].collect do |realm|
84
- convert_realm(realm)
90
+ client.request('common/lookup/list', { 'lookup' => 'ip.datacenter' })['list'].collect do |realm|
91
+ realms << convert_realm(realm)
85
92
  end
86
93
  end
94
+ realms = filter_on(realms, :id, opts)
87
95
  end
88
96
 
89
97
  def create_instance(credentials, image_id, opts={})
@@ -94,14 +102,24 @@ class GogridDriver < Deltacloud::BaseDriver
94
102
  else
95
103
  server_ram = "512MB"
96
104
  end
105
+
106
+ name = opts[:name]
107
+ if not name
108
+ name = "Server #{Time.now.to_i.to_s.reverse[0..3]}#{rand(9)}"
109
+ end
110
+
111
+ if name.length > USER_NAME_MAX
112
+ raise "Parameter name must be #{USER_NAME_MAX} characters or less"
113
+ end
114
+
97
115
  client = new_client(credentials)
98
116
  params = {
99
- 'name' => opts[:name] || get_random_instance_name,
117
+ 'name' => name,
100
118
  'image' => image_id,
101
119
  'server.ram' => server_ram,
102
120
  'ip' => get_free_ip_from_realm(credentials, opts[:realm_id] || '1')
103
121
  }
104
- params.merge!('isSandbox' => 'true') if opts[:sandbox]
122
+ params.merge!('isSandbox' => 'true') if opts[:sandbox]
105
123
  safely do
106
124
  instance = client.request('grid/server/add', params)['list'].first
107
125
  if instance
@@ -213,7 +231,7 @@ class GogridDriver < Deltacloud::BaseDriver
213
231
  if opts['instance_id']
214
232
  l_instance = instance(credentials, :id => opts['instance_id'])
215
233
  real_ip = {
216
- 'realiplist.0.port' => opts['listener_inst_port'],
234
+ 'realiplist.0.port' => opts['listener_instance_port'].to_i,
217
235
  'realiplist.0.ip' => l_instance ? l_instance.public_addresses.first : ""
218
236
  }
219
237
  else
@@ -222,7 +240,7 @@ class GogridDriver < Deltacloud::BaseDriver
222
240
  request = {
223
241
  'name' => opts['name'],
224
242
  'virtualip.ip' => virtip,
225
- 'virtualip.port' => opts['listener_lbr_port'],
243
+ 'virtualip.port' => opts['listener_balancer_port'].to_i,
226
244
  }
227
245
  request.merge!(real_ip) if real_ip
228
246
  balancer = gogrid.request('grid/loadbalancer/add', request)['list'].first
@@ -237,9 +255,7 @@ class GogridDriver < Deltacloud::BaseDriver
237
255
  balancer = nil
238
256
  safely do
239
257
  balancer = gogrid.request('grid/loadbalancer/delete', { 'name' => id })
240
- balancer = load_balancer(credentials, :id => id) unless balancer
241
258
  end
242
- convert_load_balancer(credentials, balancer)
243
259
  end
244
260
 
245
261
  def load_balancers(credentials, opts={})
@@ -334,7 +350,7 @@ class GogridDriver < Deltacloud::BaseDriver
334
350
 
335
351
  def convert_load_balancer(credentials, loadbalancer)
336
352
  if loadbalancer['datacenter']
337
- b_realm = realm(credentials, :id => loadbalancer['datacenter']['id'])
353
+ b_realm = realm(credentials, :id => loadbalancer['datacenter']['id'].to_s)
338
354
  else
339
355
  # Report first Realm until loadbalancer become ready
340
356
  b_realm = realm(credentials, :id => 1)
@@ -347,18 +363,23 @@ class GogridDriver < Deltacloud::BaseDriver
347
363
  balancer.listeners = []
348
364
  balancer.instances = []
349
365
  instance_ips = []
350
- loadbalancer['realiplist'].each do |instance_ip|
351
- balancer.add_listener({
352
- :protocol => 'TCP',
353
- :load_balancer_port => loadbalancer['virtualip']['port'],
354
- :instance_port => instance_ip['port']
355
- })
356
- instance_ips << instance_ip['ip']['ip']
357
- end if loadbalancer['realiplist']
358
- balancer.instances = get_load_balancer_instances(instance_ips, loadbalancer['instances'])
366
+ if loadbalancer['realiplist'].size > 0
367
+ loadbalancer['realiplist'].each do |instance_ip|
368
+ balancer.add_listener({
369
+ :protocol => 'TCP',
370
+ :load_balancer_port => loadbalancer['virtualip']['port'],
371
+ :instance_port => instance_ip['port']
372
+ })
373
+ instance_ips << instance_ip['ip']['ip']
374
+ end
375
+ else
376
+ balancer.add_listener({:protocol=>'TCP', :load_balancer_port =>loadbalancer['virtualip']['port'],
377
+ :instance_port => "unassigned"})
378
+ end
379
+ balancer.instances = get_load_balancer_instances(instance_ips, loadbalancer['instances']) if loadbalancer['instances']
359
380
  return balancer
360
381
  end
361
-
382
+
362
383
  def get_load_balancer_instances(instance_ips, instances)
363
384
  instances.select { |i| instance_ips.include?(i.public_addresses.first) } if instances
364
385
  end
@@ -410,7 +431,7 @@ class GogridDriver < Deltacloud::BaseDriver
410
431
 
411
432
  def convert_realm(realm)
412
433
  Realm.new(
413
- :id => realm['id'],
434
+ :id => realm['id'].to_s,
414
435
  :name => realm['name'],
415
436
  :state => :unlimited,
416
437
  :storage => :unlimited
@@ -458,10 +479,6 @@ class GogridDriver < Deltacloud::BaseDriver
458
479
  )
459
480
  end
460
481
 
461
- def get_random_instance_name
462
- "Server #{Time.now.to_i.to_s.reverse[0..3]}#{rand(9)}"
463
- end
464
-
465
482
  def convert_server_state(state, id)
466
483
  return 'PENDING' unless id
467
484
  state.eql?('Off') ? 'STOPPED' : 'RUNNING'
@@ -1,8 +1,10 @@
1
1
  ---
2
- :content_type: text/plain
3
2
  :content_length: 17
4
- :bucket: bucket1
5
- :user_metadata:
6
- SOMENEWKEY: NEWVALUE
3
+ :content_type: text/plain
7
4
  :last_modified: 2010-09-23 16:44:54 +0100
8
5
  :content: content of blob 1
6
+ :name: blob1
7
+ :user_metadata:
8
+ SOMENEWKEY: NEWVALUE
9
+ :bucket: bucket1
10
+ :id: blob1
@@ -1,8 +1,10 @@
1
- ---
2
- :user_metadata:
3
- VERSION: "1.2"
4
- :content_type: text/html
1
+ ---
5
2
  :content_length: 56
6
- :bucket: bucket1
3
+ :content_type: text/html
7
4
  :last_modified: 2010-09-23 16:55:05 +0100
8
5
  :content: <html><head></head><body>content of blob 2</body></html>
6
+ :name: blob2
7
+ :user_metadata:
8
+ VERSION: "1.2"
9
+ :bucket: bucket1
10
+ :id: blob2
@@ -1,7 +1,9 @@
1
- :bucket: bucket1
1
+ ---
2
2
  :content_length: 17
3
3
  :content_type: text/plain
4
4
  :last_modified: 2010-08-14 02:14:31 +0100
5
- :content:
6
- content of blob 3
7
- :user_metadata: ''
5
+ :content: content of blob 3
6
+ :name: blob3
7
+ :user_metadata: ""
8
+ :bucket: bucket1
9
+ :id: blob3
@@ -1,8 +1,10 @@
1
- :bucket: bucket2
1
+ ---
2
2
  :content_length: 17
3
3
  :content_type: application/octet-stream
4
4
  :last_modified: 2010-09-21 06:17:24 +0100
5
- :content:
6
- content of blob 4
5
+ :content: content of blob 4
6
+ :name: blob4
7
7
  :user_metadata:
8
- some: "value"
8
+ some: value
9
+ :bucket: bucket2
10
+ :id: blob4
@@ -1,7 +1,9 @@
1
- :bucket: bucket2
1
+ ---
2
2
  :content_length: 17
3
3
  :content_type: application/pdf
4
4
  :last_modified: 2009-07-21 11:12:13 +0100
5
- :content:
6
- content of blob 5
7
- :user_metadata: ''
5
+ :content: content of blob 5
6
+ :name: blob5
7
+ :user_metadata: ""
8
+ :id: blob5
9
+ :bucket: bucket2
@@ -1,2 +1,8 @@
1
- :blob_list: [blob1, blob2, blob3]
1
+ ---
2
+ :blob_list:
3
+ - blob1
4
+ - blob2
5
+ - blob3
2
6
  :size: 3
7
+ :name: bucket1
8
+ :id: bucket1
@@ -1,2 +1,7 @@
1
- :blob_list: [blob4, blob5]
1
+ ---
2
+ :blob_list:
3
+ - blob4
4
+ - blob5
2
5
  :size: 2
6
+ :name: bucket2
7
+ :id: bucket2
@@ -1,3 +1,7 @@
1
- :description: Fedora 10
2
- :owner_id: fedoraproject
1
+ ---
3
2
  :architecture: x86_64
3
+ :owner_id: fedoraproject
4
+ :state: AVAILABLE
5
+ :id: img1
6
+ :name: img1
7
+ :description: Fedora 10
@@ -1,3 +1,7 @@
1
- :description: Fedora 10
2
- :owner_id: fedoraproject
1
+ ---
3
2
  :architecture: i386
3
+ :owner_id: fedoraproject
4
+ :state: AVAILABLE
5
+ :id: img2
6
+ :name: img2
7
+ :description: Fedora 10
@@ -1,3 +1,7 @@
1
- :description: JBoss
2
- :owner_id: mockuser
1
+ ---
3
2
  :architecture: i386
3
+ :owner_id: mockuser
4
+ :state: AVAILABLE
5
+ :id: img3
6
+ :name: img3
7
+ :description: JBoss
@@ -1,17 +1,18 @@
1
1
  ---
2
- :realm_id: us
3
- :public_addresses:
4
- - img1.inst0.public.com
5
- :state: RUNNING
6
- :name: "Mock Instance With Profile Change"
7
- :private_addresses:
8
- - img1.inst0.private.com
9
- :image_id: img1
10
2
  :instance_profile: !ruby/object:InstanceProfile
11
- id: m1-large
12
3
  memory: "12288"
13
- :owner_id: mockuser
4
+ id: m1-large
5
+ :realm_id: us
14
6
  :actions:
15
7
  - :reboot
16
8
  - :stop
9
+ :owner_id: mockuser
10
+ :public_addresses:
11
+ - img1.inst0.public.com
12
+ :private_addresses:
13
+ - img1.inst0.private.com
17
14
  :create_image: true
15
+ :image_id: img1
16
+ :name: Mock Instance With Profile Change
17
+ :id: inst0
18
+ :state: RUNNING