fog-profitbricks 2.0.1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.travis.yml +11 -4
  4. data/README.md +8 -5
  5. data/Rakefile +1 -1
  6. data/examples/pb_demo.rb +49 -49
  7. data/fog-profitbricks.gemspec +4 -5
  8. data/gemfiles/Gemfile.1.9.2+ +1 -0
  9. data/lib/fog/bin/profitbricks.rb +5 -5
  10. data/lib/fog/profitbricks.rb +3 -3
  11. data/lib/fog/profitbricks/compute.rb +209 -204
  12. data/lib/fog/profitbricks/helpers/compute/data_helper.rb +1 -1
  13. data/lib/fog/profitbricks/models/compute/datacenter.rb +1 -1
  14. data/lib/fog/profitbricks/models/compute/datacenters.rb +6 -7
  15. data/lib/fog/profitbricks/models/compute/firewall_rule.rb +2 -2
  16. data/lib/fog/profitbricks/models/compute/firewall_rules.rb +5 -8
  17. data/lib/fog/profitbricks/models/compute/flavors.rb +1 -4
  18. data/lib/fog/profitbricks/models/compute/image.rb +4 -0
  19. data/lib/fog/profitbricks/models/compute/images.rb +2 -5
  20. data/lib/fog/profitbricks/models/compute/ip_block.rb +1 -1
  21. data/lib/fog/profitbricks/models/compute/ip_blocks.rb +3 -8
  22. data/lib/fog/profitbricks/models/compute/lan.rb +1 -1
  23. data/lib/fog/profitbricks/models/compute/lans.rb +4 -7
  24. data/lib/fog/profitbricks/models/compute/load_balancer.rb +6 -7
  25. data/lib/fog/profitbricks/models/compute/load_balancers.rb +5 -9
  26. data/lib/fog/profitbricks/models/compute/locations.rb +2 -5
  27. data/lib/fog/profitbricks/models/compute/nic.rb +6 -3
  28. data/lib/fog/profitbricks/models/compute/nics.rb +2 -5
  29. data/lib/fog/profitbricks/models/compute/regions.rb +1 -4
  30. data/lib/fog/profitbricks/models/compute/request.rb +0 -1
  31. data/lib/fog/profitbricks/models/compute/requests.rb +2 -4
  32. data/lib/fog/profitbricks/models/compute/server.rb +10 -13
  33. data/lib/fog/profitbricks/models/compute/servers.rb +3 -6
  34. data/lib/fog/profitbricks/models/compute/snapshot.rb +2 -2
  35. data/lib/fog/profitbricks/models/compute/snapshots.rb +3 -6
  36. data/lib/fog/profitbricks/models/compute/volume.rb +11 -9
  37. data/lib/fog/profitbricks/models/compute/volumes.rb +3 -6
  38. data/lib/fog/profitbricks/requests/compute/associate_nic_to_load_balancer.rb +26 -13
  39. data/lib/fog/profitbricks/requests/compute/attach_cdrom.rb +25 -16
  40. data/lib/fog/profitbricks/requests/compute/attach_volume.rb +25 -16
  41. data/lib/fog/profitbricks/requests/compute/create_datacenter.rb +22 -23
  42. data/lib/fog/profitbricks/requests/compute/create_firewall_rule.rb +24 -26
  43. data/lib/fog/profitbricks/requests/compute/create_flavor.rb +34 -34
  44. data/lib/fog/profitbricks/requests/compute/create_ip_block.rb +18 -20
  45. data/lib/fog/profitbricks/requests/compute/create_lan.rb +151 -150
  46. data/lib/fog/profitbricks/requests/compute/create_load_balancer.rb +67 -26
  47. data/lib/fog/profitbricks/requests/compute/create_nic.rb +24 -26
  48. data/lib/fog/profitbricks/requests/compute/create_server.rb +70 -61
  49. data/lib/fog/profitbricks/requests/compute/create_volume.rb +122 -122
  50. data/lib/fog/profitbricks/requests/compute/create_volume_snapshot.rb +42 -45
  51. data/lib/fog/profitbricks/requests/compute/delete_datacenter.rb +34 -36
  52. data/lib/fog/profitbricks/requests/compute/delete_firewall_rule.rb +8 -11
  53. data/lib/fog/profitbricks/requests/compute/delete_image.rb +7 -9
  54. data/lib/fog/profitbricks/requests/compute/delete_ip_block.rb +8 -10
  55. data/lib/fog/profitbricks/requests/compute/delete_lan.rb +7 -9
  56. data/lib/fog/profitbricks/requests/compute/delete_load_balancer.rb +8 -10
  57. data/lib/fog/profitbricks/requests/compute/delete_nic.rb +7 -10
  58. data/lib/fog/profitbricks/requests/compute/delete_server.rb +6 -10
  59. data/lib/fog/profitbricks/requests/compute/delete_snapshot.rb +7 -10
  60. data/lib/fog/profitbricks/requests/compute/delete_volume.rb +36 -38
  61. data/lib/fog/profitbricks/requests/compute/detach_cdrom.rb +11 -13
  62. data/lib/fog/profitbricks/requests/compute/detach_volume.rb +16 -13
  63. data/lib/fog/profitbricks/requests/compute/get_all_datacenters.rb +1 -1
  64. data/lib/fog/profitbricks/requests/compute/get_all_firewall_rules.rb +6 -7
  65. data/lib/fog/profitbricks/requests/compute/get_all_flavors.rb +72 -72
  66. data/lib/fog/profitbricks/requests/compute/get_all_images.rb +62 -62
  67. data/lib/fog/profitbricks/requests/compute/get_all_ip_blocks.rb +5 -5
  68. data/lib/fog/profitbricks/requests/compute/get_all_lans.rb +113 -113
  69. data/lib/fog/profitbricks/requests/compute/get_all_load_balanced_nics.rb +15 -9
  70. data/lib/fog/profitbricks/requests/compute/get_all_load_balancers.rb +9 -9
  71. data/lib/fog/profitbricks/requests/compute/get_all_locations.rb +6 -6
  72. data/lib/fog/profitbricks/requests/compute/get_all_nic.rb +94 -94
  73. data/lib/fog/profitbricks/requests/compute/get_all_requests.rb +38 -38
  74. data/lib/fog/profitbricks/requests/compute/get_all_servers.rb +8 -9
  75. data/lib/fog/profitbricks/requests/compute/get_all_snapshots.rb +4 -4
  76. data/lib/fog/profitbricks/requests/compute/get_all_volumes.rb +71 -71
  77. data/lib/fog/profitbricks/requests/compute/get_attached_cdrom.rb +11 -11
  78. data/lib/fog/profitbricks/requests/compute/get_attached_volume.rb +16 -11
  79. data/lib/fog/profitbricks/requests/compute/get_datacenter.rb +4 -6
  80. data/lib/fog/profitbricks/requests/compute/get_firewall_rule.rb +8 -11
  81. data/lib/fog/profitbricks/requests/compute/get_flavor.rb +9 -9
  82. data/lib/fog/profitbricks/requests/compute/get_image.rb +7 -9
  83. data/lib/fog/profitbricks/requests/compute/get_ip_block.rb +8 -10
  84. data/lib/fog/profitbricks/requests/compute/get_lan.rb +7 -10
  85. data/lib/fog/profitbricks/requests/compute/get_load_balanced_nic.rb +16 -12
  86. data/lib/fog/profitbricks/requests/compute/get_load_balancer.rb +7 -9
  87. data/lib/fog/profitbricks/requests/compute/get_location.rb +7 -9
  88. data/lib/fog/profitbricks/requests/compute/get_nic.rb +8 -11
  89. data/lib/fog/profitbricks/requests/compute/get_request.rb +55 -57
  90. data/lib/fog/profitbricks/requests/compute/get_request_status.rb +44 -46
  91. data/lib/fog/profitbricks/requests/compute/get_server.rb +7 -10
  92. data/lib/fog/profitbricks/requests/compute/get_snapshot.rb +7 -9
  93. data/lib/fog/profitbricks/requests/compute/get_volume.rb +7 -9
  94. data/lib/fog/profitbricks/requests/compute/list_attached_cdroms.rb +8 -8
  95. data/lib/fog/profitbricks/requests/compute/list_attached_volumes.rb +18 -8
  96. data/lib/fog/profitbricks/requests/compute/reboot_server.rb +7 -11
  97. data/lib/fog/profitbricks/requests/compute/remove_nic_association.rb +9 -11
  98. data/lib/fog/profitbricks/requests/compute/restore_volume_snapshot.rb +15 -17
  99. data/lib/fog/profitbricks/requests/compute/start_server.rb +7 -11
  100. data/lib/fog/profitbricks/requests/compute/stop_server.rb +7 -11
  101. data/lib/fog/profitbricks/requests/compute/update_datacenter.rb +20 -15
  102. data/lib/fog/profitbricks/requests/compute/update_firewall_rule.rb +9 -11
  103. data/lib/fog/profitbricks/requests/compute/update_image.rb +15 -15
  104. data/lib/fog/profitbricks/requests/compute/update_lan.rb +6 -8
  105. data/lib/fog/profitbricks/requests/compute/update_load_balancer.rb +10 -12
  106. data/lib/fog/profitbricks/requests/compute/update_nic.rb +10 -12
  107. data/lib/fog/profitbricks/requests/compute/update_server.rb +10 -13
  108. data/lib/fog/profitbricks/requests/compute/update_snapshot.rb +10 -13
  109. data/lib/fog/profitbricks/requests/compute/update_volume.rb +10 -13
  110. data/lib/fog/profitbricks/version.rb +1 -1
  111. data/spec/minitest_helper.rb +1 -3
  112. data/tests/helpers/formats_helper.rb +8 -8
  113. data/tests/profitbricks/models/compute/compute_tests.rb +529 -0
  114. data/tests/profitbricks/requests/compute/composite_create_tests.rb +16 -83
  115. data/tests/profitbricks/requests/compute/flavor_tests.rb +1 -4
  116. data/tests/profitbricks/requests/compute/location_tests.rb +14 -17
  117. data/tests/profitbricks/requests/compute/nic_tests.rb +60 -70
  118. data/tests/profitbricks/requests/compute/request_tests.rb +1 -3
  119. data/tests/profitbricks/requests/compute/server_tests.rb +163 -161
  120. metadata +5 -18
@@ -52,47 +52,45 @@ module Fog
52
52
  # Leave portRangeStart and portRangeEnd null to allow all ports
53
53
  #
54
54
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#create-firewall-rule]
55
- def create_firewall_rule(datacenter_id, server_id, nic_id, options={})
55
+ def create_firewall_rule(datacenter_id, server_id, nic_id, options = {})
56
56
  firewall_rule = {
57
- :properties => options
57
+ :properties => options
58
58
  }
59
59
 
60
60
  request(
61
- :expects => [202],
62
- :method => 'POST',
63
- :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/nics/#{nic_id}/firewallrules",
64
- :body => Fog::JSON.encode(firewall_rule)
61
+ :expects => [202],
62
+ :method => 'POST',
63
+ :path => "/datacenters/#{datacenter_id}/servers/#{server_id}/nics/#{nic_id}/firewallrules",
64
+ :body => Fog::JSON.encode(firewall_rule)
65
65
  )
66
- rescue => error
67
- Fog::Errors::NotFound.new(error)
68
66
  end
69
67
  end
70
68
 
71
69
  class Mock
72
- def create_firewall_rule(datacenter_id, server_id, nic_id, options={})
70
+ def create_firewall_rule(datacenter_id, server_id, nic_id, options = {})
73
71
  response = Excon::Response.new
74
72
  response.status = 202
75
73
 
76
74
  firewall_rule_id = Fog::UUID.uuid
77
75
  firewall_rule = {
78
- 'id' => firewall_rule_id,
79
- 'type' => 'nic',
80
- 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/nics/#{nic_id}/firewallrules/#{firewall_rule_id}",
81
- 'metadata' => {
82
- 'createdDate' => '2015-03-18T19:00:51Z',
83
- 'createdBy' => 'test@stackpointcloud.com',
84
- 'etag' => 'faa67fbacb1c0e2e02cf9650657251f2',
85
- 'lastModifiedDate' => '2015-03-18T19:00:51Z',
86
- 'lastModifiedBy' => 'test@stackpointcloud.com',
87
- 'state' => 'AVAILABLE'
88
- },
89
- 'properties' => options,
90
- 'datacenter_id' => datacenter_id,
91
- 'server_id' => server_id,
92
- 'nic_id' => nic_id,
76
+ 'id' => firewall_rule_id,
77
+ 'type' => 'nic',
78
+ 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/servers/#{server_id}/nics/#{nic_id}/firewallrules/#{firewall_rule_id}",
79
+ 'metadata' => {
80
+ 'createdDate' => '2015-03-18T19:00:51Z',
81
+ 'createdBy' => 'test@stackpointcloud.com',
82
+ 'etag' => 'faa67fbacb1c0e2e02cf9650657251f2',
83
+ 'lastModifiedDate' => '2015-03-18T19:00:51Z',
84
+ 'lastModifiedBy' => 'test@stackpointcloud.com',
85
+ 'state' => 'AVAILABLE'
86
+ },
87
+ 'properties' => options,
88
+ 'datacenter_id' => datacenter_id,
89
+ 'server_id' => server_id,
90
+ 'nic_id' => nic_id
93
91
  }
94
92
 
95
- self.data[:firewall_rules]['items'] << firewall_rule
93
+ data[:firewall_rules]['items'] << firewall_rule
96
94
  response.body = firewall_rule
97
95
 
98
96
  response
@@ -100,4 +98,4 @@ module Fog
100
98
  end
101
99
  end
102
100
  end
103
- end
101
+ end
@@ -1,40 +1,40 @@
1
1
  module Fog
2
- module Compute
3
- class ProfitBricks
4
- class Real
5
- # Not a real API method; will only return flavor object.
6
- def create_flavor(flavor_name, cores, ram)
7
- response = Excon::Response.new
8
- response.status = 200
9
- response.body = {
10
- 'createFlavorResponse' => {
11
- 'id' => Fog::UUID.uuid,
12
- 'name' => flavor_name,
13
- 'cores' => cores,
14
- 'ram' => ram,
15
- }
16
- }
17
- response
18
- end
19
- end
2
+ module Compute
3
+ class ProfitBricks
4
+ class Real
5
+ # Not a real API method; will only return flavor object.
6
+ def create_flavor(flavor_name, cores, ram)
7
+ response = Excon::Response.new
8
+ response.status = 200
9
+ response.body = {
10
+ 'createFlavorResponse' => {
11
+ 'id' => Fog::UUID.uuid,
12
+ 'name' => flavor_name,
13
+ 'cores' => cores,
14
+ 'ram' => ram
15
+ }
16
+ }
17
+ response
18
+ end
19
+ end
20
20
 
21
- class Mock
22
- def create_flavor(flavor_name, ram, cores)
23
- response = Excon::Response.new
24
- response.status = 200
21
+ class Mock
22
+ def create_flavor(flavor_name, ram, cores)
23
+ response = Excon::Response.new
24
+ response.status = 200
25
25
 
26
- flavor = {
27
- 'id' => Fog::UUID.uuid,
28
- 'name' => flavor_name,
29
- 'ram' => ram,
30
- 'cores' => cores
31
- }
26
+ flavor = {
27
+ 'id' => Fog::UUID.uuid,
28
+ 'name' => flavor_name,
29
+ 'ram' => ram,
30
+ 'cores' => cores
31
+ }
32
32
 
33
- self.data[:flavors] << flavor
34
- response.body = { 'createFlavorResponse' => flavor }
35
- response
36
- end
37
- end
33
+ data[:flavors] << flavor
34
+ response.body = { 'createFlavorResponse' => flavor }
35
+ response
38
36
  end
37
+ end
39
38
  end
40
- end
39
+ end
40
+ end
@@ -32,17 +32,15 @@ module Fog
32
32
  # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#create-ip-block]
33
33
  def create_ip_block(options = {})
34
34
  ip_block = {
35
- :properties => options
35
+ :properties => options
36
36
  }
37
37
 
38
38
  request(
39
- :expects => [202],
40
- :method => 'POST',
41
- :path => "/ipblocks",
42
- :body => Fog::JSON.encode(ip_block)
39
+ :expects => [202],
40
+ :method => 'POST',
41
+ :path => "/ipblocks",
42
+ :body => Fog::JSON.encode(ip_block)
43
43
  )
44
- rescue => error
45
- Fog::Errors::NotFound.new(error)
46
44
  end
47
45
  end
48
46
 
@@ -53,23 +51,23 @@ module Fog
53
51
  'id' => ipb_3_id,
54
52
  'type' => 'ipblock',
55
53
  'href' => "https://api.profitbricks.com/rest/v2/ipblocks/#{ipb_3_id}",
56
- 'metadata' => {
57
- 'createdDate' => '2016-07-31T15:41:27Z',
58
- 'createdBy' => 'test@stackpointcloud.com',
59
- 'etag' => '5b91832ee85a758568d4523a86bd8702',
60
- 'lastModifiedDate' => '2016-07-31T15:41:27Z',
61
- 'lastModifiedBy' => 'test@stackpointcloud.com',
62
- 'state' => 'AVAILABLE'
54
+ 'metadata' => {
55
+ 'createdDate' => '2016-07-31T15:41:27Z',
56
+ 'createdBy' => 'test@stackpointcloud.com',
57
+ 'etag' => '5b91832ee85a758568d4523a86bd8702',
58
+ 'lastModifiedDate' => '2016-07-31T15:41:27Z',
59
+ 'lastModifiedBy' => 'test@stackpointcloud.com',
60
+ 'state' => 'AVAILABLE'
63
61
  },
64
62
  'properties' => {
65
- 'ips' => ["777.777.777.777", "888.888.888.888", "999.999.999.999"],
66
- 'location' => options[:location],
67
- 'size' => options[:size],
68
- 'name' => options[:name]
63
+ 'ips' => ["777.777.777.777", "888.888.888.888", "999.999.999.999"],
64
+ 'location' => options[:location],
65
+ 'size' => options[:size],
66
+ 'name' => options[:name]
69
67
  }
70
68
  }
71
69
 
72
- self.data[:ip_blocks]['items'] << ip_block
70
+ data[:ip_blocks]['items'] << ip_block
73
71
  response = Excon::Response.new
74
72
  response.status = 202
75
73
  response.body = ip_block
@@ -78,4 +76,4 @@ module Fog
78
76
  end
79
77
  end
80
78
  end
81
- end
79
+ end
@@ -1,160 +1,161 @@
1
1
  module Fog
2
- module Compute
3
- class ProfitBricks
4
- class Real
5
- # Creates a LAN within a data center
6
- #
7
- # ==== Parameters
8
- # * datacenter_id<~String> - Required - UUID of virtual data center
9
- # * properties<~Hash>:
10
- # * name<~String> - The name of the LAN
11
- # * public<~Integer> - Boolean indicating if the LAN faces the public Internet or not
12
- # * entities<~Hash>:
13
- # * nics<~Array> - A collection of NICs associated with the LAN
14
- #
15
- # ==== Returns
16
- # * response<~Excon::Response>:
17
- # * body<~Hash>:
18
- # * id<~String> - The resource's unique identifier
19
- # * type<~String> - The type of the created resource
20
- # * href<~String> - URL to the object’s representation (absolute path)
21
- # * items<~Hash> - Collection of individual lan objects
22
- # * id<~String> - The resource's unique identifier
23
- # * type<~String> - The type of the created resource
24
- # * href<~String> - URL to the object’s representation (absolute path)
25
- # * metadata<~Hash> - Hash containing the LAN metadata
26
- # * createdDate<~String> - The date the resource was created
27
- # * createdBy<~String> - The user who created the resource
28
- # * etag<~String> - The etag for the resource
29
- # * lastModifiedDate<~String> - The last time the resource has been modified
30
- # * lastModifiedBy<~String> - The user who last modified the resource
31
- # * state<~String> - LAN state
32
- # * properties<~Hash> - Hash containing the LAN properties
33
- # * name<~String> - The name of the LAN
34
- # * public<~Boolean> - Boolean indicating if the LAN faces the public Internet or not
35
- # * entities<~Hash> - Hash containing the LAN entities
36
- # * nics<~Hash> - Hash containing the NIC properties
37
- # * id<~String> - The resource's unique identifier
38
- # * type<~String> - The type of the created resource
39
- # * href<~String> - URL to the object’s representation (absolute path)
40
- # * items<~Hash> - Collection of individual nic objects
41
- # * id<~String> - The resource's unique identifier
42
- # * type<~String> - The type of the created resource
43
- # * href<~String> - URL to the object’s representation (absolute path)
44
- # * metadata<~Hash> - Hash containing the NIC metadata
45
- # * createdDate<~String> - The date the resource was created
46
- # * createdBy<~String> - The user who created the resource
47
- # * etag<~String> - The etag for the resource
48
- # * lastModifiedDate<~String> - The last time the resource has been modified
49
- # * lastModifiedBy<~String> - The user who last modified the resource
50
- # * state<~String> - NIC state
51
- # * properties<~Hash> - Hash containing the NIC properties
52
- # * name<~String> - The name of the NIC
53
- # * mac<~String> - The MAC address of the NIC
54
- # * ips<~Array> - IPs assigned to the NIC represented as a collection
55
- # * dhcp<~Boolean> - Boolean value that indicates if the NIC is using DHCP or not
56
- # * lan<~Integer> - The LAN ID the NIC sits on
57
- # * firewallActive<~Boolean> - Once a firewall rule is added, this will reflect a true value
58
- # * entities<~Hash> - Hash containing the NIC entities
59
- # * firewallrules<~Hash> - A list of firewall rules associated to the NIC represented as a collection
60
- # * id<~String> - The resource's unique identifier
61
- # * type<~String> - The type of the resource
62
- # * href<~String> - URL to the object’s representation (absolute path)
63
- # * items<~Array> - Collection of individual firewall rules objects
64
- # * id<~String> - The resource's unique identifier
65
- # * type<~String> - The type of the resource
66
- # * href<~String> - URL to the object’s representation (absolute path)
67
- # * metadata<~Hash> - Hash containing the Firewall Rule metadata
68
- # * createdDate<~String> - The date the resource was created
69
- # * createdBy<~String> - The user who created the resource
70
- # * etag<~String> - The etag for the resource
71
- # * lastModifiedDate<~String> - The last time the resource has been modified
72
- # * lastModifiedBy<~String> - The user who last modified the resource
73
- # * state<~String> - Firewall Rule state
74
- # * properties<~Hash> - Hash containing the Firewall Rule properties
75
- # * name<~String> - The name of the Firewall Rule
76
- # * protocol<~String> - The protocol for the rule: TCP, UDP, ICMP, ANY
77
- # * sourceMac<~Array> - Only traffic originating from the respective MAC address is allowed.
78
- # Valid format: aa:bb:cc:dd:ee:ff. Value null allows all source MAC address
79
- # * sourceIp<~Boolean> - Only traffic originating from the respective IPv4 address is allowed.
80
- # Value null allows all source IPs
81
- # * targetIp<~Integer> - In case the target NIC has multiple IP addresses, only traffic directed
82
- # to the respective IP address of the NIC is allowed. Value null allows all target IPs
83
- # * icmpCode<~Boolean> - Defines the allowed code (from 0 to 254) if protocol ICMP is chosen.
84
- # Value null allows all codes.
85
- # * icmpType<~Boolean> - Defines the allowed type (from 0 to 254) if the protocol ICMP is chosen.
86
- # Value null allows all types
87
- # * portRangeStart<~Boolean> - Defines the start range of the allowed port (from 1 to 65534)
88
- # if protocol TCP or UDP is chosen. Leave portRangeStart and portRangeEnd
89
- # value null to allow all ports
90
- # * portRangeEnd<~Boolean> - Defines the end range of the allowed port (from 1 to 65534)
91
- # if the protocol TCP or UDP is chosen. Leave portRangeStart and
92
- # portRangeEnd value null to allow all ports
93
- #
94
- # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#create-lan]
95
- def create_lan(datacenter_id, properties={}, entities={})
96
- lan = {
97
- :properties => properties,
98
- :entities => entities
99
- }
2
+ module Compute
3
+ class ProfitBricks
4
+ class Real
5
+ # Creates a LAN within a data center
6
+ #
7
+ # ==== Parameters
8
+ # * datacenter_id<~String> - Required - UUID of virtual data center
9
+ # * properties<~Hash>:
10
+ # * name<~String> - The name of the LAN
11
+ # * public<~Integer> - Boolean indicating if the LAN faces the public Internet or not
12
+ # * entities<~Hash>:
13
+ # * nics<~Array> - A collection of NICs associated with the LAN
14
+ #
15
+ # ==== Returns
16
+ # * response<~Excon::Response>:
17
+ # * body<~Hash>:
18
+ # * id<~String> - The resource's unique identifier
19
+ # * type<~String> - The type of the created resource
20
+ # * href<~String> - URL to the object’s representation (absolute path)
21
+ # * items<~Hash> - Collection of individual lan objects
22
+ # * id<~String> - The resource's unique identifier
23
+ # * type<~String> - The type of the created resource
24
+ # * href<~String> - URL to the object’s representation (absolute path)
25
+ # * metadata<~Hash> - Hash containing the LAN metadata
26
+ # * createdDate<~String> - The date the resource was created
27
+ # * createdBy<~String> - The user who created the resource
28
+ # * etag<~String> - The etag for the resource
29
+ # * lastModifiedDate<~String> - The last time the resource has been modified
30
+ # * lastModifiedBy<~String> - The user who last modified the resource
31
+ # * state<~String> - LAN state
32
+ # * properties<~Hash> - Hash containing the LAN properties
33
+ # * name<~String> - The name of the LAN
34
+ # * public<~Boolean> - Boolean indicating if the LAN faces the public Internet or not
35
+ # * entities<~Hash> - Hash containing the LAN entities
36
+ # * nics<~Hash> - Hash containing the NIC properties
37
+ # * id<~String> - The resource's unique identifier
38
+ # * type<~String> - The type of the created resource
39
+ # * href<~String> - URL to the object’s representation (absolute path)
40
+ # * items<~Hash> - Collection of individual nic objects
41
+ # * id<~String> - The resource's unique identifier
42
+ # * type<~String> - The type of the created resource
43
+ # * href<~String> - URL to the object’s representation (absolute path)
44
+ # * metadata<~Hash> - Hash containing the NIC metadata
45
+ # * createdDate<~String> - The date the resource was created
46
+ # * createdBy<~String> - The user who created the resource
47
+ # * etag<~String> - The etag for the resource
48
+ # * lastModifiedDate<~String> - The last time the resource has been modified
49
+ # * lastModifiedBy<~String> - The user who last modified the resource
50
+ # * state<~String> - NIC state
51
+ # * properties<~Hash> - Hash containing the NIC properties
52
+ # * name<~String> - The name of the NIC
53
+ # * mac<~String> - The MAC address of the NIC
54
+ # * ips<~Array> - IPs assigned to the NIC represented as a collection
55
+ # * dhcp<~Boolean> - Boolean value that indicates if the NIC is using DHCP or not
56
+ # * lan<~Integer> - The LAN ID the NIC sits on
57
+ # * firewallActive<~Boolean> - Once a firewall rule is added, this will reflect a true value
58
+ # * entities<~Hash> - Hash containing the NIC entities
59
+ # * firewallrules<~Hash> - A list of firewall rules associated to the NIC represented as a collection
60
+ # * id<~String> - The resource's unique identifier
61
+ # * type<~String> - The type of the resource
62
+ # * href<~String> - URL to the object’s representation (absolute path)
63
+ # * items<~Array> - Collection of individual firewall rules objects
64
+ # * id<~String> - The resource's unique identifier
65
+ # * type<~String> - The type of the resource
66
+ # * href<~String> - URL to the object’s representation (absolute path)
67
+ # * metadata<~Hash> - Hash containing the Firewall Rule metadata
68
+ # * createdDate<~String> - The date the resource was created
69
+ # * createdBy<~String> - The user who created the resource
70
+ # * etag<~String> - The etag for the resource
71
+ # * lastModifiedDate<~String> - The last time the resource has been modified
72
+ # * lastModifiedBy<~String> - The user who last modified the resource
73
+ # * state<~String> - Firewall Rule state
74
+ # * properties<~Hash> - Hash containing the Firewall Rule properties
75
+ # * name<~String> - The name of the Firewall Rule
76
+ # * protocol<~String> - The protocol for the rule: TCP, UDP, ICMP, ANY
77
+ # * sourceMac<~Array> - Only traffic originating from the respective MAC address is allowed.
78
+ # Valid format: aa:bb:cc:dd:ee:ff. Value null allows all source MAC address
79
+ # * sourceIp<~Boolean> - Only traffic originating from the respective IPv4 address is allowed.
80
+ # Value null allows all source IPs
81
+ # * targetIp<~Integer> - In case the target NIC has multiple IP addresses, only traffic directed
82
+ # to the respective IP address of the NIC is allowed. Value null allows all target IPs
83
+ # * icmpCode<~Boolean> - Defines the allowed code (from 0 to 254) if protocol ICMP is chosen.
84
+ # Value null allows all codes.
85
+ # * icmpType<~Boolean> - Defines the allowed type (from 0 to 254) if the protocol ICMP is chosen.
86
+ # Value null allows all types
87
+ # * portRangeStart<~Boolean> - Defines the start range of the allowed port (from 1 to 65534)
88
+ # if protocol TCP or UDP is chosen. Leave portRangeStart and portRangeEnd
89
+ # value null to allow all ports
90
+ # * portRangeEnd<~Boolean> - Defines the end range of the allowed port (from 1 to 65534)
91
+ # if the protocol TCP or UDP is chosen. Leave portRangeStart and
92
+ # portRangeEnd value null to allow all ports
93
+ #
94
+ # {ProfitBricks API Documentation}[https://devops.profitbricks.com/api/cloud/v2/#create-lan]
95
+ def create_lan(datacenter_id, properties = {}, entities = {})
96
+ lan = {
97
+ :properties => properties,
98
+ :entities => entities
99
+ }
100
100
 
101
- request(
102
- :expects => [202],
103
- :method => 'POST',
104
- :path => "/datacenters/#{datacenter_id}/lans",
105
- :body => Fog::JSON.encode(lan)
106
- )
107
- rescue => error
108
- Fog::Errors::NotFound.new(error)
109
- end
110
- end
101
+ request(
102
+ :expects => [202],
103
+ :method => 'POST',
104
+ :path => "/datacenters/#{datacenter_id}/lans",
105
+ :body => Fog::JSON.encode(lan)
106
+ )
107
+ end
108
+ end
109
+
110
+ class Mock
111
+ def create_lan(datacenter_id, properties = {}, _entities = {})
112
+ response = Excon::Response.new
113
+ response.status = 202
114
+
115
+ if datacenter = data[:datacenters]['items'].find do |attrib|
116
+ attrib['id'] == datacenter_id
117
+ end
111
118
 
112
- class Mock
113
- def create_lan(datacenter_id, properties={}, entities={})
114
- response = Excon::Response.new
115
- response.status = 202
119
+ datacenter['properties']['version'] += 1 if datacenter['properties']
120
+ datacenter['version'] += 1 if datacenter['version']
116
121
 
117
- if datacenter = self.data[:datacenters]['items'].find {
118
- |attrib| attrib['id'] == datacenter_id
119
- }
120
- datacenter['version'] += 1
121
- else
122
- raise Fog::Errors::NotFound.new('Data center resource could not be found')
123
- end
122
+ else
123
+ raise Fog::Errors::NotFound, 'Data center resource could not be found'
124
+ end
124
125
 
125
- lan = {
126
- 'id' => '10',
127
- 'type' => 'nic',
128
- 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/lans/10",
129
- 'metadata' => {
130
- 'createdDate' => '2015-03-18T19:00:51Z',
131
- 'createdBy' => 'test@stackpointcloud.com',
132
- 'etag' => 'faa67fbacb1c0e2e02cf9650657251f1',
133
- 'lastModifiedDate' => '2015-03-18T19:00:51Z',
134
- 'lastModifiedBy' => 'test@stackpointcloud.com',
135
- 'state' => 'AVAILABLE'
136
- },
137
- 'properties' => {
138
- 'name' => properties[:name],
139
- 'public' => properties[:public]
140
- },
141
- 'entities' => {
142
- 'nics' => {
143
- 'id' => '10/nics',
144
- 'type' => 'collection',
145
- 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/lans/10/nics",
146
- 'items' => [ ]
147
- }
148
- },
149
- 'datacenter_id' => datacenter_id
150
- }
126
+ lan = {
127
+ 'id' => '10',
128
+ 'type' => 'nic',
129
+ 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/lans/10",
130
+ 'metadata' => {
131
+ 'createdDate' => '2015-03-18T19:00:51Z',
132
+ 'createdBy' => 'test@stackpointcloud.com',
133
+ 'etag' => 'faa67fbacb1c0e2e02cf9650657251f1',
134
+ 'lastModifiedDate' => '2015-03-18T19:00:51Z',
135
+ 'lastModifiedBy' => 'test@stackpointcloud.com',
136
+ 'state' => 'AVAILABLE'
137
+ },
138
+ 'properties' => {
139
+ 'name' => properties[:name],
140
+ 'public' => properties[:public]
141
+ },
142
+ 'entities' => {
143
+ 'nics' => {
144
+ 'id' => '10/nics',
145
+ 'type' => 'collection',
146
+ 'href' => "https://api.profitbricks.com/rest/v2/datacenters/#{datacenter_id}/lans/10/nics",
147
+ 'items' => []
148
+ }
149
+ },
150
+ 'datacenter_id' => datacenter_id
151
+ }
151
152
 
152
- self.data[:lans]['items'] << lan
153
+ data[:lans]['items'] << lan
153
154
 
154
- response.body = lan
155
- response
156
- end
157
- end
155
+ response.body = lan
156
+ response
158
157
  end
158
+ end
159
159
  end
160
+ end
160
161
  end