fog-profitbricks 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -3
  3. data/Rakefile +1 -1
  4. data/examples/pb_demo.rb +2 -8
  5. data/lib/fog/profitbricks/compute.rb +249 -105
  6. data/lib/fog/profitbricks/models/compute/datacenter.rb +63 -9
  7. data/lib/fog/profitbricks/models/compute/firewall_rule.rb +3 -1
  8. data/lib/fog/profitbricks/models/compute/group.rb +7 -4
  9. data/lib/fog/profitbricks/models/compute/image.rb +3 -0
  10. data/lib/fog/profitbricks/models/compute/ip_block.rb +2 -0
  11. data/lib/fog/profitbricks/models/compute/lan.rb +2 -1
  12. data/lib/fog/profitbricks/models/compute/load_balancer.rb +2 -0
  13. data/lib/fog/profitbricks/models/compute/location.rb +1 -0
  14. data/lib/fog/profitbricks/models/compute/nic.rb +2 -0
  15. data/lib/fog/profitbricks/models/compute/request.rb +1 -0
  16. data/lib/fog/profitbricks/models/compute/resource.rb +1 -0
  17. data/lib/fog/profitbricks/models/compute/server.rb +5 -1
  18. data/lib/fog/profitbricks/models/compute/share.rb +4 -2
  19. data/lib/fog/profitbricks/models/compute/snapshot.rb +2 -0
  20. data/lib/fog/profitbricks/models/compute/user.rb +4 -1
  21. data/lib/fog/profitbricks/requests/compute/add_share.rb +2 -2
  22. data/lib/fog/profitbricks/requests/compute/add_user_to_group.rb +4 -4
  23. data/lib/fog/profitbricks/requests/compute/associate_nic_to_load_balancer.rb +1 -3
  24. data/lib/fog/profitbricks/requests/compute/attach_cdrom.rb +18 -17
  25. data/lib/fog/profitbricks/requests/compute/attach_volume.rb +9 -2
  26. data/lib/fog/profitbricks/requests/compute/create_datacenter.rb +71 -25
  27. data/lib/fog/profitbricks/requests/compute/create_firewall_rule.rb +11 -4
  28. data/lib/fog/profitbricks/requests/compute/create_group.rb +22 -4
  29. data/lib/fog/profitbricks/requests/compute/create_ip_block.rb +1 -1
  30. data/lib/fog/profitbricks/requests/compute/create_lan.rb +1 -1
  31. data/lib/fog/profitbricks/requests/compute/create_load_balancer.rb +4 -43
  32. data/lib/fog/profitbricks/requests/compute/create_nic.rb +4 -0
  33. data/lib/fog/profitbricks/requests/compute/create_server.rb +6 -1
  34. data/lib/fog/profitbricks/requests/compute/create_user.rb +20 -1
  35. data/lib/fog/profitbricks/requests/compute/create_volume.rb +5 -1
  36. data/lib/fog/profitbricks/requests/compute/create_volume_snapshot.rb +1 -1
  37. data/lib/fog/profitbricks/requests/compute/delete_group.rb +1 -1
  38. data/lib/fog/profitbricks/requests/compute/delete_share.rb +1 -1
  39. data/lib/fog/profitbricks/requests/compute/delete_user.rb +1 -1
  40. data/lib/fog/profitbricks/requests/compute/detach_cdrom.rb +3 -3
  41. data/lib/fog/profitbricks/requests/compute/get_attached_cdrom.rb +3 -3
  42. data/lib/fog/profitbricks/requests/compute/get_datacenter.rb +1 -1
  43. data/lib/fog/profitbricks/requests/compute/get_firewall_rule.rb +1 -1
  44. data/lib/fog/profitbricks/requests/compute/get_group.rb +1 -1
  45. data/lib/fog/profitbricks/requests/compute/get_image.rb +1 -1
  46. data/lib/fog/profitbricks/requests/compute/get_ip_block.rb +1 -1
  47. data/lib/fog/profitbricks/requests/compute/get_lan.rb +1 -1
  48. data/lib/fog/profitbricks/requests/compute/get_load_balanced_nic.rb +7 -1
  49. data/lib/fog/profitbricks/requests/compute/get_load_balancer.rb +1 -1
  50. data/lib/fog/profitbricks/requests/compute/get_location.rb +1 -1
  51. data/lib/fog/profitbricks/requests/compute/get_nic.rb +2 -2
  52. data/lib/fog/profitbricks/requests/compute/get_request.rb +8 -1
  53. data/lib/fog/profitbricks/requests/compute/get_resource_by_type.rb +8 -1
  54. data/lib/fog/profitbricks/requests/compute/get_resources_by_type.rb +9 -3
  55. data/lib/fog/profitbricks/requests/compute/get_server.rb +1 -1
  56. data/lib/fog/profitbricks/requests/compute/get_share.rb +1 -1
  57. data/lib/fog/profitbricks/requests/compute/get_snapshot.rb +1 -1
  58. data/lib/fog/profitbricks/requests/compute/get_user.rb +1 -1
  59. data/lib/fog/profitbricks/requests/compute/get_volume.rb +1 -1
  60. data/lib/fog/profitbricks/requests/compute/list_attached_cdroms.rb +3 -1
  61. data/lib/fog/profitbricks/requests/compute/list_attached_volumes.rb +3 -3
  62. data/lib/fog/profitbricks/requests/compute/remove_user_from_group.rb +2 -2
  63. data/lib/fog/profitbricks/requests/compute/update_datacenter.rb +3 -8
  64. data/lib/fog/profitbricks/requests/compute/update_firewall_rule.rb +1 -1
  65. data/lib/fog/profitbricks/requests/compute/update_group.rb +5 -5
  66. data/lib/fog/profitbricks/requests/compute/update_nic.rb +2 -4
  67. data/lib/fog/profitbricks/requests/compute/update_server.rb +3 -4
  68. data/lib/fog/profitbricks/requests/compute/update_share.rb +3 -3
  69. data/lib/fog/profitbricks/requests/compute/update_user.rb +2 -2
  70. data/lib/fog/profitbricks/version.rb +1 -1
  71. data/tests/profitbricks/models/compute/compute_tests.rb +1071 -267
  72. metadata +26 -33
  73. data/gemfiles/Gemfile.1.8.7 +0 -6
  74. data/tests/profitbricks/requests/compute/composite_create_tests.rb +0 -174
  75. data/tests/profitbricks/requests/compute/flavor_tests.rb +0 -40
  76. data/tests/profitbricks/requests/compute/location_tests.rb +0 -42
  77. data/tests/profitbricks/requests/compute/nic_tests.rb +0 -268
  78. data/tests/profitbricks/requests/compute/request_tests.rb +0 -50
  79. data/tests/profitbricks/requests/compute/server_tests.rb +0 -462
@@ -6,7 +6,9 @@ module Fog
6
6
  class Datacenter < Fog::Models::ProfitBricks::Base
7
7
  include Fog::Helpers::ProfitBricks::DataHelper
8
8
 
9
- identity :id
9
+ identity :id
10
+
11
+ attribute :type
10
12
 
11
13
  # properties
12
14
  attribute :name
@@ -16,13 +18,19 @@ module Fog
16
18
  attribute :features
17
19
 
18
20
  # metadata
19
- attribute :created_date, :aliases => 'createdDate', :type => :time
20
- attribute :created_by, :aliases => 'createdBy'
21
- attribute :last_modified_date, :aliases => 'lastModifiedDate', :type => :time
22
- attribute :last_modified_by, :aliases => 'lastModifiedBy'
23
- attribute :request_id, :aliases => 'requestId'
21
+ attribute :created_date, :aliases => 'createdDate', :type => :time
22
+ attribute :created_by, :aliases => 'createdBy'
23
+ attribute :last_modified_date, :aliases => 'lastModifiedDate', :type => :time
24
+ attribute :last_modified_by, :aliases => 'lastModifiedBy'
25
+ attribute :request_id, :aliases => 'requestId'
24
26
  attribute :state
25
27
 
28
+ #entities
29
+ attribute :servers
30
+ attribute :volumes
31
+ attribute :loadbalancers
32
+ attribute :lans
33
+
26
34
  attr_accessor :options
27
35
 
28
36
  def initialize(attributes = {})
@@ -33,11 +41,37 @@ module Fog
33
41
  requires :name, :location
34
42
 
35
43
  options = {}
36
- options[:name] = name
37
- options[:location] = location
44
+ options[:name] = name
45
+ options[:location] = location
38
46
  options[:description] = description if description
47
+ options[:servers] = servers if servers
48
+ options[:volumes] = volumes if volumes
49
+ options[:loadbalancers] = loadbalancers if loadbalancers
50
+ options[:lans] = lans if lans
51
+
52
+ entities = {}
53
+
54
+ # Retrieve servers collection if present and generate appropriate JSON.
55
+ if options.key?(:servers)
56
+ entities[:servers] = collect_entities(options.delete(:servers))
57
+ end
58
+
59
+ # Retrieve volumes collection if present and generate appropriate JSON.
60
+ if options.key?(:volumes)
61
+ entities[:volumes] = collect_entities(options.delete(:volumes))
62
+ end
39
63
 
40
- data = service.create_datacenter(options)
64
+ # Retrieve volumes collection if present and generate appropriate JSON.
65
+ if options.key?(:loadbalancers)
66
+ entities[:loadbalancers] = collect_entities(options.delete(:loadbalancers))
67
+ end
68
+
69
+ # Retrieve volumes collection if present and generate appropriate JSON.
70
+ if options.key?(:lans)
71
+ entities[:lans] = collect_entities(options.delete(:lans))
72
+ end
73
+
74
+ data = service.create_datacenter(options, entities)
41
75
  merge_attributes(flatten(data.body))
42
76
  true
43
77
  end
@@ -58,6 +92,26 @@ module Fog
58
92
  data = service.delete_datacenter(id)
59
93
  true
60
94
  end
95
+
96
+ private
97
+
98
+ def collect_entities(entities)
99
+ if entities.is_a?(Array) && entities.length > 0
100
+ items = []
101
+ entities.each do |entity|
102
+ if entity.key?(:volumes)
103
+ subentities = collect_entities(entity.delete(:volumes))
104
+ items << {
105
+ properties: entity,
106
+ entities: {volumes: subentities}
107
+ }
108
+ else
109
+ items << {properties: entity}
110
+ end
111
+ end
112
+ {items: items}
113
+ end
114
+ end
61
115
  end
62
116
  end
63
117
  end
@@ -8,10 +8,12 @@ module Fog
8
8
 
9
9
  identity :id
10
10
 
11
+ attribute :type
12
+
11
13
  # properties
12
14
  attribute :name
13
15
  attribute :protocol
14
- attribute :source_mac, :aliases => 'sourceMac'
16
+ attribute :source_mac, :aliases => 'sourceMac'
15
17
  attribute :source_ip, :aliases => 'sourceIp'
16
18
  attribute :target_ip, :aliases => 'targetIp'
17
19
  attribute :icmp_code, :aliases => 'icmpCode'
@@ -8,6 +8,9 @@ module Fog
8
8
 
9
9
  identity :id
10
10
 
11
+ attribute :type
12
+ attribute :request_id
13
+
11
14
  # properties
12
15
  attribute :name
13
16
  attribute :create_datacenter, :aliases => 'createDataCenter'
@@ -45,10 +48,10 @@ module Fog
45
48
 
46
49
  options = {}
47
50
  options[:name] = name
48
- options[:createDataCenter] = create_datacenter if create_datacenter
49
- options[:createSnapshot] = create_snapshot if create_snapshot
50
- options[:reserveIp] = reserve_ip if reserve_ip
51
- options[:accessActivityLog] = access_activity_log if access_activity_log
51
+ options[:createDataCenter] = create_datacenter if [true, false].include?(create_datacenter)
52
+ options[:createSnapshot] = create_snapshot if [true, false].include?(create_snapshot)
53
+ options[:reserveIp] = reserve_ip if [true, false].include?(reserve_ip)
54
+ options[:accessActivityLog] = access_activity_log if [true, false].include?(access_activity_log)
52
55
 
53
56
  data = service.update_group(id, options)
54
57
  merge_attributes(flatten(data.body))
@@ -8,6 +8,8 @@ module Fog
8
8
 
9
9
  identity :id
10
10
 
11
+ attribute :type
12
+
11
13
  # properties
12
14
  attribute :name
13
15
  attribute :description
@@ -26,6 +28,7 @@ module Fog
26
28
  attribute :licence_type, :aliases => 'licenceType'
27
29
  attribute :image_type, :aliases => 'imageType'
28
30
  attribute :public
31
+ attribute :image_aliases, :aliases => 'imageAliases'
29
32
 
30
33
  # metadata
31
34
  attribute :created_date, :aliases => 'createdDate', :type => :time
@@ -8,6 +8,8 @@ module Fog
8
8
 
9
9
  identity :id
10
10
 
11
+ attribute :type
12
+
11
13
  # properties
12
14
  attribute :ips
13
15
  attribute :location
@@ -7,6 +7,7 @@ module Fog
7
7
  include Fog::Helpers::ProfitBricks::DataHelper
8
8
 
9
9
  identity :id
10
+ attribute :type
10
11
 
11
12
  # properties
12
13
  attribute :name
@@ -24,7 +25,7 @@ module Fog
24
25
  # entities
25
26
  attribute :nics
26
27
 
27
- attribute :datacenter_id
28
+ attribute :datacenter_id, :aliases => 'datacenterId'
28
29
 
29
30
  attr_accessor :options
30
31
 
@@ -8,6 +8,8 @@ module Fog
8
8
 
9
9
  identity :id
10
10
 
11
+ attribute :type
12
+
11
13
  # properties
12
14
  attribute :name
13
15
  attribute :ip
@@ -6,6 +6,7 @@ module Fog
6
6
 
7
7
  attribute :name
8
8
  attribute :features
9
+ attribute :type
9
10
  attribute :image_aliases, :aliases => 'imageAliases'
10
11
 
11
12
  attr_accessor :options
@@ -8,6 +8,8 @@ module Fog
8
8
 
9
9
  identity :id
10
10
 
11
+ attribute :type
12
+
11
13
  # properties
12
14
  attribute :name
13
15
  attribute :mac
@@ -9,6 +9,7 @@ module Fog
9
9
  attribute :headers
10
10
  attribute :body
11
11
  attribute :url
12
+ attribute :type
12
13
 
13
14
  # metadata
14
15
  attribute :created_date, :aliases => 'createdDate', :type => :time
@@ -7,6 +7,7 @@ module Fog
7
7
  include Fog::Helpers::ProfitBricks::DataHelper
8
8
 
9
9
  identity :id
10
+ attribute :type
10
11
 
11
12
  # metadata
12
13
  attribute :created_date, :aliases => 'createdDate'
@@ -9,6 +9,8 @@ module Fog
9
9
 
10
10
  identity :id
11
11
 
12
+ attribute :type
13
+
12
14
  # properties
13
15
  attribute :name
14
16
  attribute :cores
@@ -29,7 +31,7 @@ module Fog
29
31
  attribute :state
30
32
 
31
33
  # entities
32
- # attribute :cdroms
34
+ attribute :cdroms
33
35
  attribute :volumes
34
36
  attribute :nics
35
37
 
@@ -203,6 +205,7 @@ module Fog
203
205
 
204
206
  def get_volumes(volumes)
205
207
  items = []
208
+
206
209
  for volume in volumes do
207
210
  item = {}
208
211
  item[:name] = volume[:name]
@@ -210,6 +213,7 @@ module Fog
210
213
  item[:type] = volume[:type]
211
214
  item[:bus] = volume[:bus] || 'VIRTIO'
212
215
  item[:image] = volume[:image]
216
+ item[:imageAlias] = volume[:image_alias]
213
217
  item[:imagePassword] = volume[:image_password]
214
218
  item[:sshKeys] = volume[:ssh_keys]
215
219
  item[:licenceType] = volume[:licence_type]
@@ -8,6 +8,8 @@ module Fog
8
8
 
9
9
  identity :id
10
10
 
11
+ attribute :type
12
+
11
13
  # properties
12
14
  attribute :edit_privilege, :aliases => 'editPrivilege'
13
15
  attribute :share_privilege, :aliases => 'sharePrivilege'
@@ -40,8 +42,8 @@ module Fog
40
42
  requires :group_id, :resource_id
41
43
 
42
44
  options = {}
43
- options[:editPrivilege] = edit_privilege if edit_privilege
44
- options[:sharePrivilege] = share_privilege if share_privilege
45
+ options[:editPrivilege] = edit_privilege if [true, false].include?(edit_privilege)
46
+ options[:sharePrivilege] = share_privilege if [true, false].include?(share_privilege)
45
47
 
46
48
  data = service.update_share(group_id, resource_id, options)
47
49
  merge_attributes(flatten(data.body))
@@ -8,6 +8,8 @@ module Fog
8
8
 
9
9
  identity :id
10
10
 
11
+ attribute :type
12
+
11
13
  # properties
12
14
  attribute :name
13
15
  attribute :description
@@ -8,6 +8,9 @@ module Fog
8
8
 
9
9
  identity :id
10
10
 
11
+ attribute :type
12
+ attribute :request_id
13
+
11
14
  # metadata
12
15
  attribute :etag
13
16
  attribute :creation_date, :aliases => 'creationDate'
@@ -22,7 +25,7 @@ module Fog
22
25
  attribute :force_sec_auth, :aliases => 'forceSecAuth'
23
26
  attribute :sec_auth_active, :aliases => 'secAuthActive'
24
27
 
25
- # metadata
28
+ # entities
26
29
  attribute :owns
27
30
  attribute :groups
28
31
 
@@ -48,8 +48,8 @@ module Fog
48
48
  'type' => 'resource',
49
49
  'href' => "https=>//api.profitbricks.com/rest/v4/um/groups/#{group_id}/shares/#{resource_id}",
50
50
  'properties' => {
51
- 'editPrivilege' => options[:edit_privilege],
52
- 'sharePrivilege' => options[:share_privilege]
51
+ 'editPrivilege' => options[:editPrivilege],
52
+ 'sharePrivilege' => options[:sharePrivilege]
53
53
  }
54
54
  }
55
55
 
@@ -67,18 +67,18 @@ module Fog
67
67
  grp["id"] == group_id
68
68
  end
69
69
  else
70
- raise Excon::Error::HTTPStatus, "The requested resource could not be found"
70
+ raise Excon::Error::HTTPStatus, "Resource does not exist"
71
71
  end
72
72
 
73
73
  if user = data[:users]['items'].find do |usr|
74
74
  usr["id"] == user_id
75
75
  end
76
76
  else
77
- raise Excon::Error::HTTPStatus, "The requested resource could not be found"
77
+ raise Excon::Error::HTTPStatus, "Resource does not exist"
78
78
  end
79
79
 
80
- group['users'] << user
81
- user['groups'] << group
80
+ group['users']['items'] << user
81
+ user['groups']['items'] << group
82
82
 
83
83
  response.body = user
84
84
  response
@@ -104,11 +104,9 @@ module Fog
104
104
  }
105
105
  end
106
106
 
107
- data = load_balancer['entities']['balancednics']['items'][0]
108
-
109
107
  response = Excon::Response.new
110
108
  response.status = 202
111
- response.body = data
109
+ response.body = nic
112
110
  response
113
111
  end
114
112
  end
@@ -48,10 +48,10 @@ module Fog
48
48
  }
49
49
 
50
50
  request(
51
- :expects => [202],
52
- :method => 'POST',
53
- :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/cdroms",
54
- :body => Fog::JSON.encode(volume)
51
+ :expects => [202],
52
+ :method => 'POST',
53
+ :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/cdroms",
54
+ :body => Fog::JSON.encode(volume)
55
55
  )
56
56
  end
57
57
  end
@@ -62,32 +62,33 @@ module Fog
62
62
  cd["id"] == cdrom_image_id
63
63
  end
64
64
  else
65
- raise Fog::Errors::NotFound, "The requested resource could not be found"
65
+ raise Excon::Error::HTTPStatus, "Resource does not exist"
66
66
  end
67
67
 
68
68
  if server = data[:servers]['items'].find do |serv|
69
69
  serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
70
70
  end
71
71
  else
72
- raise Fog::Errors::NotFound, "The server resource could not be found"
72
+ raise Excon::Error::HTTPStatus, "Resource does not exist"
73
73
  end
74
74
 
75
- if server['entities'] && server['entities']['cdroms'] && server['entities']['cdroms']['items']
76
- server['entities']['cdroms']['items'] << cdrom
75
+ cdrom['properties'] = {}
76
+ cdrom['properties']['name'] = cdrom['name']
77
+
78
+ if server['cdroms'] && server['cdroms']['items']
79
+ server['cdroms']['items'] << cdrom
77
80
  else
78
- server['entities'] = {
79
- 'cdroms' => {
80
- 'id' => "#{server['id']}/cdroms",
81
- 'type' => 'collection',
82
- 'href' => "https=>//api.profitbricks.com/rest/v2/datacenters/#{server['datacenter_id']}/servers/#{server['id']}/cdroms",
83
- 'items' => [cdrom]
84
- }
81
+ server['cdroms'] = {
82
+ 'id' => "#{server['id']}/cdroms",
83
+ 'type' => 'collection',
84
+ 'href' => "https=>//api.profitbricks.com/rest/v2/datacenters/#{server['datacenter_id']}/servers/#{server['id']}/cdroms",
85
+ 'items' => [cdrom]
85
86
  }
86
87
  end
87
88
 
88
- response = Excon::Response.new
89
+ response = Excon::Response.new
89
90
  response.status = 202
90
- response.body = cdrom
91
+ response.body = cdrom
91
92
 
92
93
  response
93
94
  end
@@ -63,16 +63,23 @@ module Fog
63
63
  vlm["id"] == storage_id && vlm["datacenter_id"] == datacenter_id
64
64
  end
65
65
  else
66
- raise Fog::Errors::NotFound, "The requested resource could not be found"
66
+ raise Excon::Error::HTTPStatus, "Resource does not exist"
67
67
  end
68
68
 
69
69
  if server = data[:servers]['items'].find do |serv|
70
70
  serv['datacenter_id'] == datacenter_id && serv['id'] == server_id
71
71
  end
72
72
  else
73
- raise Fog::Errors::NotFound, "The server resource could not be found"
73
+ raise Excon::Error::HTTPStatus, "Resource does not exist"
74
74
  end
75
75
 
76
+ volume['properties'] = {}
77
+ volume['properties']['name'] = volume['name']
78
+ volume['properties']['size'] = volume['size']
79
+ volume['properties']['bus'] = volume['bus']
80
+ volume['properties']['type'] = volume['type']
81
+ volume['properties']['licenceType'] = 'LINUX'
82
+
76
83
  if server['entities'] && server['entities']['volumes'] && server['entities']['volumes']['items']
77
84
  server['entities']['volumes']['items'] << volume
78
85
  else