knife-profitbricks 1.2.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +303 -96
  4. data/knife-profitbricks.gemspec +1 -1
  5. data/lib/chef/knife/profitbricks_base.rb +24 -0
  6. data/lib/chef/knife/profitbricks_composite_server_create.rb +59 -45
  7. data/lib/chef/knife/profitbricks_contract_list.rb +37 -0
  8. data/lib/chef/knife/profitbricks_datacenter_create.rb +8 -7
  9. data/lib/chef/knife/profitbricks_firewall_create.rb +15 -15
  10. data/lib/chef/knife/profitbricks_firewall_delete.rb +6 -8
  11. data/lib/chef/knife/profitbricks_firewall_list.rb +6 -5
  12. data/lib/chef/knife/profitbricks_ipblock_create.rb +6 -7
  13. data/lib/chef/knife/profitbricks_ipfailover_add.rb +60 -0
  14. data/lib/chef/knife/profitbricks_ipfailover_remove.rb +60 -0
  15. data/lib/chef/knife/profitbricks_lan_create.rb +5 -3
  16. data/lib/chef/knife/profitbricks_lan_list.rb +1 -1
  17. data/lib/chef/knife/profitbricks_nic_create.rb +12 -14
  18. data/lib/chef/knife/profitbricks_nic_delete.rb +4 -3
  19. data/lib/chef/knife/profitbricks_nic_list.rb +4 -3
  20. data/lib/chef/knife/profitbricks_server_create.rb +14 -16
  21. data/lib/chef/knife/profitbricks_server_delete.rb +1 -1
  22. data/lib/chef/knife/profitbricks_server_list.rb +1 -1
  23. data/lib/chef/knife/profitbricks_server_reboot.rb +1 -1
  24. data/lib/chef/knife/profitbricks_server_start.rb +1 -1
  25. data/lib/chef/knife/profitbricks_server_stop.rb +1 -1
  26. data/lib/chef/knife/profitbricks_volume_attach.rb +5 -5
  27. data/lib/chef/knife/profitbricks_volume_create.rb +38 -18
  28. data/lib/chef/knife/profitbricks_volume_delete.rb +1 -1
  29. data/lib/chef/knife/profitbricks_volume_detach.rb +4 -4
  30. data/lib/chef/knife/profitbricks_volume_list.rb +5 -6
  31. data/lib/knife-profitbricks/version.rb +1 -1
  32. data/spec/chef/knife/profitbricks_composite_server_create_spec.rb +64 -0
  33. data/spec/chef/knife/profitbricks_contract_list_spec.rb +20 -0
  34. data/spec/chef/knife/profitbricks_datacenter_create_spec.rb +44 -0
  35. data/spec/chef/knife/profitbricks_datacenter_delete_spec.rb +39 -0
  36. data/spec/chef/knife/profitbricks_datacenter_list_spec.rb +7 -6
  37. data/spec/chef/knife/profitbricks_firewall_create_spec.rb +74 -0
  38. data/spec/chef/knife/profitbricks_firewall_delete_spec.rb +86 -0
  39. data/spec/chef/knife/profitbricks_firewall_list_spec.rb +61 -0
  40. data/spec/chef/knife/profitbricks_image_list_spec.rb +19 -0
  41. data/spec/chef/knife/profitbricks_ipblock_create_spec.rb +39 -0
  42. data/spec/chef/knife/profitbricks_ipblock_delete_spec.rb +37 -0
  43. data/spec/chef/knife/profitbricks_ipfailover_add_spec.rb +80 -0
  44. data/spec/chef/knife/profitbricks_ipfailover_remove_spec.rb +85 -0
  45. data/spec/chef/knife/profitbricks_lan_create_spec.rb +59 -0
  46. data/spec/chef/knife/profitbricks_lan_delete_spec.rb +58 -0
  47. data/spec/chef/knife/profitbricks_lan_list_spec.rb +37 -0
  48. data/spec/chef/knife/profitbricks_location_list_spec.rb +24 -0
  49. data/spec/chef/knife/profitbricks_nic_create_spec.rb +71 -0
  50. data/spec/chef/knife/profitbricks_nic_delete_spec.rb +69 -0
  51. data/spec/chef/knife/profitbricks_nic_list_spec.rb +69 -0
  52. data/spec/chef/knife/profitbricks_server_create_spec.rb +63 -0
  53. data/spec/chef/knife/profitbricks_server_delete_spec.rb +63 -0
  54. data/spec/chef/knife/profitbricks_server_list_spec.rb +65 -0
  55. data/spec/chef/knife/profitbricks_server_reboot_spec.rb +65 -0
  56. data/spec/chef/knife/profitbricks_server_start_spec.rb +68 -0
  57. data/spec/chef/knife/profitbricks_server_stop_spec.rb +65 -0
  58. data/spec/chef/knife/profitbricks_volume_attach_spec.rb +70 -0
  59. data/spec/chef/knife/profitbricks_volume_create_spec.rb +63 -0
  60. data/spec/chef/knife/profitbricks_volume_delete_spec.rb +70 -0
  61. data/spec/chef/knife/profitbricks_volume_detach_spec.rb +81 -0
  62. data/spec/chef/knife/profitbricks_volume_list_spec.rb +80 -0
  63. data/spec/spec_helper.rb +22 -3
  64. data/spec/test.sh +1 -1
  65. metadata +81 -18
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "profitbricks-sdk-ruby", "~> 3.0"
21
+ spec.add_runtime_dependency "profitbricks-sdk-ruby", "~> 4.0"
22
22
  spec.add_runtime_dependency "chef", "~> 12"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.6"
@@ -1,4 +1,5 @@
1
1
  require 'chef/knife'
2
+ require 'knife-profitbricks/version'
2
3
 
3
4
  class Chef
4
5
  class Knife
@@ -36,6 +37,8 @@ class Chef
36
37
  config.url = Chef::Config[:knife][:profitbricks_url]
37
38
  config.debug = Chef::Config[:knife][:profitbricks_debug] || false
38
39
  config.global_classes = false
40
+ config.headers = Hash.new
41
+ config.headers['User-Agent'] = "Chef/#{::Chef::VERSION} knife-profitbricks/#{::Knife::ProfitBricks::VERSION}"
39
42
  end
40
43
  end
41
44
 
@@ -44,6 +47,27 @@ class Chef
44
47
  puts "#{ui.color(label, color)}: #{value}"
45
48
  end
46
49
  end
50
+
51
+ def validate_required_params(required_params, params)
52
+ missing_params = required_params.select do |param|
53
+ params[param].nil?
54
+ end
55
+ def error_and_exit(message)
56
+ ui.error message
57
+ exit(1)
58
+ end
59
+ end
60
+
61
+ def get_image(image_name, image_type, image_location)
62
+ images = ProfitBricks::Image.list
63
+ min_image = nil
64
+ images.each do |image|
65
+ if image.properties['name'].downcase.include? image_name && image.properties['public'] == true && image.properties['imageType'] == image_type && image.properties['location'] == image_location
66
+ min_image = image
67
+ end
68
+ end
69
+ min_image
70
+ end
47
71
  end
48
72
  end
49
73
  end
@@ -16,14 +16,12 @@ class Chef
16
16
  option :name,
17
17
  short: '-n NAME',
18
18
  long: '--name NAME',
19
- description: 'Name of the server',
20
- required: true
19
+ description: '(required) Name of the server'
21
20
 
22
21
  option :cores,
23
22
  short: '-C CORES',
24
23
  long: '--cores CORES',
25
- description: 'The number of processor cores',
26
- required: true
24
+ description: '(required) The number of processor cores'
27
25
 
28
26
  option :cpufamily,
29
27
  short: '-f CPU_FAMILY',
@@ -34,8 +32,7 @@ class Chef
34
32
  option :ram,
35
33
  short: '-r RAM',
36
34
  long: '--ram RAM',
37
- description: 'The amount of RAM in MB',
38
- required: true
35
+ description: '(required) The amount of RAM in MB'
39
36
 
40
37
  option :availabilityzone,
41
38
  short: '-a AVAILABILITY_ZONE',
@@ -50,8 +47,7 @@ class Chef
50
47
  option :size,
51
48
  short: '-S SIZE',
52
49
  long: '--size SIZE',
53
- description: 'The size of the volume in GB',
54
- required: true
50
+ description: '(required) The size of the volume in GB'
55
51
 
56
52
  option :bus,
57
53
  short: '-b BUS',
@@ -61,18 +57,21 @@ class Chef
61
57
  option :image,
62
58
  short: '-N ID',
63
59
  long: '--image ID',
64
- description: 'The image or snapshot ID'
60
+ description: '(required) The image or snapshot ID'
61
+
62
+ option :imagealias,
63
+ long: '--image-alias IMAGE_ALIAS',
64
+ description: '(required) The image alias'
65
65
 
66
66
  option :type,
67
67
  short: '-t TYPE',
68
68
  long: '--type TYPE',
69
- description: 'The disk type (HDD or SSD)',
70
- required: true
69
+ description: '(required) The disk type (HDD or SSD)'
71
70
 
72
71
  option :licencetype,
73
72
  short: '-l LICENCE',
74
73
  long: '--licence-type LICENCE',
75
- description: 'The licence type of the volume (LINUX, WINDOWS, UNKNOWN, OTHER)'
74
+ description: 'The licence type of the volume (LINUX, WINDOWS, WINDOWS2016, UNKNOWN, OTHER)'
76
75
 
77
76
  option :imagepassword,
78
77
  short: '-P PASSWORD',
@@ -82,8 +81,7 @@ class Chef
82
81
  option :volume_availability_zone,
83
82
  short: '-Z AVAILABILITY_ZONE',
84
83
  long: '--volume-availability-zone AVAILABILITY_ZONE',
85
- description: 'The volume availability zone of the server',
86
- required: false
84
+ description: 'The volume availability zone of the server'
87
85
 
88
86
  option :sshkeys,
89
87
  short: '-K SSHKEY[,SSHKEY,...]',
@@ -106,74 +104,90 @@ class Chef
106
104
  long: '--dhcp',
107
105
  boolean: true | false,
108
106
  default: true,
109
- description: 'Set to false if you wish to disable DHCP'
107
+ description: '(required) Set to false if you wish to disable DHCP'
110
108
 
111
109
  option :lan,
112
110
  short: '-L ID',
113
111
  long: '--lan ID',
114
- description: 'The LAN ID the NIC will reside on; if the LAN ID does not exist it will be created',
115
- required: true
112
+ description: 'The LAN ID the NIC will reside on; if the LAN ID does not exist it will be created'
116
113
 
117
114
  option :nat,
118
115
  long: '--nat',
119
- description: 'Set to enable NAT on the NIC',
120
- required: false
116
+ description: 'Set to enable NAT on the NIC'
121
117
 
122
118
  def run
123
119
  $stdout.sync = true
124
120
 
125
- print "#{ui.color('Creating composite server...', :magenta)}"
121
+ validate_required_params(%i[datacenter_id name cores ram size type dhcp lan], Chef::Config[:knife])
122
+
123
+ if !Chef::Config[:knife][:image] && !Chef::Config[:knife][:imagealias]
124
+ ui.error("Either '--image' or '--image-alias' parameter must be provided")
125
+ exit(1)
126
+ end
127
+
128
+ if !Chef::Config[:knife][:sshkeys] && !Chef::Config[:knife][:imagepassword]
129
+ ui.error("Either '--image-password' or '--ssh-keys' parameter must be provided")
130
+ exit(1)
131
+ end
132
+
133
+ print ui.color('Creating composite server...', :magenta).to_s
126
134
  volume_params = {
127
- name: config[:volumename],
128
- size: config[:size],
129
- bus: config[:bus] || 'VIRTIO',
130
- image: config[:image],
131
- type: config[:type],
132
- licenceType: config[:licencetype]
135
+ name: Chef::Config[:knife][:volumename],
136
+ size: Chef::Config[:knife][:size],
137
+ bus: Chef::Config[:knife][:bus] || 'VIRTIO',
138
+ image: Chef::Config[:knife][:image],
139
+ type: Chef::Config[:knife][:type],
140
+ licenceType: Chef::Config[:knife][:licencetype]
133
141
  }
134
142
 
135
- if config[:sshkeys]
136
- volume_params[:sshKeys] = config[:sshkeys]
143
+ if Chef::Config[:knife][:image]
144
+ volume_params['image'] = Chef::Config[:knife][:image]
137
145
  end
138
146
 
139
- if config[:imagepassword]
140
- volume_params[:imagePassword] = config[:imagepassword]
147
+ if Chef::Config[:knife][:imagealias]
148
+ volume_params['imageAlias'] = Chef::Config[:knife][:imagealias]
149
+ end
150
+
151
+ if Chef::Config[:knife][:sshkeys]
152
+ volume_params[:sshKeys] = Chef::Config[:knife][:sshkeys]
153
+ end
154
+
155
+ if Chef::Config[:knife][:imagepassword]
156
+ volume_params[:imagePassword] = Chef::Config[:knife][:imagepassword]
141
157
  end
142
158
 
143
159
  if config[:volume_availability_zone]
144
- volume_params[:availabilityZone] = config[:volume_availability_zone]
160
+ volume_params[:availabilityZone] = Chef::Config[:knife][:volume_availability_zone]
145
161
  end
146
162
 
147
163
  nic_params = {
148
- name: config[:nicname],
149
- ips: config[:ips],
150
- dhcp: config[:dhcp],
151
- lan: config[:lan]
164
+ name: Chef::Config[:knife][:nicname],
165
+ ips: Chef::Config[:knife][:ips],
166
+ dhcp: Chef::Config[:knife][:dhcp],
167
+ lan: Chef::Config[:knife][:lan]
152
168
  }
153
169
 
154
- if config[:nat]
155
- nic_params[:nat] = config[:nat]
156
- end
170
+ nic_params[:nat] = Chef::Config[:knife][:nat] if config[:nat]
157
171
 
158
172
  params = {
159
- name: config[:name],
160
- cores: config[:cores],
161
- cpuFamily: config[:cpufamily],
162
- ram: config[:ram],
163
- availabilityZone: config[:availabilityzone],
173
+ name: Chef::Config[:knife][:name],
174
+ cores: Chef::Config[:knife][:cores],
175
+ cpuFamily: Chef::Config[:knife][:cpufamily],
176
+ ram: Chef::Config[:knife][:ram],
177
+ availabilityZone: Chef::Config[:knife][:availabilityzone],
164
178
  volumes: [volume_params],
165
179
  nics: [nic_params]
166
180
  }
167
181
 
168
182
  connection
183
+
169
184
  server = ProfitBricks::Server.create(
170
- config[:datacenter_id],
185
+ Chef::Config[:knife][:datacenter_id],
171
186
  params.compact
172
187
  )
173
188
 
174
189
  dot = ui.color('.', :magenta)
175
190
  server.wait_for(300) { print dot; ready? }
176
- server.reload
177
191
 
178
192
  puts "\n"
179
193
  puts "#{ui.color('ID', :cyan)}: #{server.id}"
@@ -0,0 +1,37 @@
1
+ require 'chef/knife/profitbricks_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProfitbricksContractList < Knife
6
+ include Knife::ProfitbricksBase
7
+
8
+ banner 'knife profitbricks contract list'
9
+
10
+ def run
11
+ $stdout.sync = true
12
+ connection
13
+ contract = ProfitBricks::Contract.get
14
+
15
+ puts "#{ui.color('Contract Type', :cyan)}: #{contract.type}"
16
+ puts "#{ui.color('Contract Number', :cyan)}: #{contract.properties['contractNumber']}"
17
+ puts "#{ui.color('Status', :cyan)}: #{contract.properties['status']}"
18
+ puts "#{ui.color('Cores per server', :cyan)}: #{contract.properties['resourceLimits']['coresPerServer']}"
19
+ puts "#{ui.color('Cores per contract', :cyan)}: #{contract.properties['resourceLimits']['coresPerContract']}"
20
+ puts "#{ui.color('Cores provisioned', :cyan)}: #{contract.properties['resourceLimits']['coresProvisioned']}"
21
+ puts "#{ui.color('RAM per server', :cyan)}: #{contract.properties['resourceLimits']['ramPerServer']}"
22
+ puts "#{ui.color('RAM per contract', :cyan)}: #{contract.properties['resourceLimits']['ramPerContract']}"
23
+ puts "#{ui.color('RAM provisioned', :cyan)}: #{contract.properties['resourceLimits']['ramProvisioned']}"
24
+ puts "#{ui.color('HDD limit per volume', :cyan)}: #{contract.properties['resourceLimits']['hddLimitPerVolume']}"
25
+ puts "#{ui.color('HDD limit per contract', :cyan)}: #{contract.properties['resourceLimits']['hddLimitPerContract']}"
26
+ puts "#{ui.color('HDD volume provisioned', :cyan)}: #{contract.properties['resourceLimits']['hddVolumeProvisioned']}"
27
+ puts "#{ui.color('SSD limit per volume', :cyan)}: #{contract.properties['resourceLimits']['ssdLimitPerVolume']}"
28
+ puts "#{ui.color('SSD limit per contract', :cyan)}: #{contract.properties['resourceLimits']['ssdLimitPerContract']}"
29
+ puts "#{ui.color('SSD volume provisioned', :cyan)}: #{contract.properties['resourceLimits']['ssdVolumeProvisioned']}"
30
+ puts "#{ui.color('Reservable IPs', :cyan)}: #{contract.properties['resourceLimits']['reservableIps']}"
31
+ puts "#{ui.color('Reservable IPs on contract', :cyan)}: #{contract.properties['resourceLimits']['reservedIpsOnContract']}"
32
+ puts "#{ui.color('Reservable IPs in use', :cyan)}: #{contract.properties['resourceLimits']['reservedIpsInUse']}"
33
+
34
+ end
35
+ end
36
+ end
37
+ end
@@ -11,7 +11,7 @@ class Chef
11
11
  short: '-n NAME',
12
12
  long: '--name NAME',
13
13
  description: 'Name of the data center',
14
- required: true
14
+ proc: proc { |name| Chef::Config[:knife][:name] = name }
15
15
 
16
16
  option :description,
17
17
  short: '-D DESCRIPTION',
@@ -22,25 +22,26 @@ class Chef
22
22
  short: '-l LOCATION',
23
23
  long: '--location LOCATION',
24
24
  description: 'Location of the data center',
25
- proc: proc { |location| Chef::Config[:knife][:location] = location },
26
- required: true
25
+ proc: proc { |location| Chef::Config[:knife][:location] = location }#,
27
26
 
28
27
  def run
29
28
  $stdout.sync = true
30
29
 
30
+ validate_required_params(%i(name location), Chef::Config[:knife])
31
+
31
32
  print "#{ui.color('Creating data center...', :magenta)}"
32
33
 
33
34
  connection
34
35
  datacenter = ProfitBricks::Datacenter.create(
35
- name: config[:name],
36
- description: config[:description],
37
- location: config[:location]
36
+ name: Chef::Config[:knife][:name],
37
+ description: Chef::Config[:knife][:description],
38
+ location: Chef::Config[:knife][:location]
38
39
  )
39
40
 
40
41
  dot = ui.color('.', :magenta)
41
42
  datacenter.wait_for { print dot; ready? }
42
- datacenter.reload
43
43
 
44
+ @dcid = datacenter.id
44
45
  puts "\n"
45
46
  puts "#{ui.color('ID', :cyan)}: #{datacenter.id}"
46
47
  puts "#{ui.color('Name', :cyan)}: #{datacenter.properties['name']}"
@@ -33,8 +33,7 @@ class Chef
33
33
  long: '--protocol PROTOCOL',
34
34
  default: 'TCP',
35
35
  description: 'The protocol of the firewall rule (TCP, UDP, ICMP,' \
36
- ' ANY)',
37
- required: true
36
+ ' ANY)'
38
37
 
39
38
  option :sourcemac,
40
39
  short: '-m MAC',
@@ -78,31 +77,32 @@ class Chef
78
77
  def run
79
78
  $stdout.sync = true
80
79
 
80
+ validate_required_params(%i(datacenter_id server_id nic_id protocol) , Chef::Config[:knife])
81
+
81
82
  print "#{ui.color('Creating firewall...', :magenta)}"
82
83
 
83
84
  params = {
84
- name: config[:name],
85
- protocol: config[:protocol],
86
- sourceMac: config[:sourcemac],
87
- sourceIp: config[:sourceip],
88
- targetIp: config[:targetip],
89
- portRangeStart: config[:portrangestart],
90
- portRangeEnd: config[:portrangeend],
91
- icmpType: config[:icmptype],
92
- icmpCode: config[:icmpcode]
85
+ name: Chef::Config[:knife][:name],
86
+ protocol: Chef::Config[:knife][:protocol],
87
+ sourceMac: Chef::Config[:knife][:sourcemac],
88
+ sourceIp: Chef::Config[:knife][:sourceip],
89
+ targetIp: Chef::Config[:knife][:targetip],
90
+ portRangeStart: Chef::Config[:knife][:portrangestart],
91
+ portRangeEnd: Chef::Config[:knife][:portrangeend],
92
+ icmpType: Chef::Config[:knife][:icmptype],
93
+ icmpCode: Chef::Config[:knife][:icmpcode]
93
94
  }
94
95
 
95
96
  connection
96
97
  firewall = ProfitBricks::Firewall.create(
97
- config[:datacenter_id],
98
- config[:server_id],
99
- config[:nic_id],
98
+ Chef::Config[:knife][:datacenter_id],
99
+ Chef::Config[:knife][:server_id],
100
+ Chef::Config[:knife][:nic_id],
100
101
  params.compact
101
102
  )
102
103
 
103
104
  dot = ui.color('.', :magenta)
104
105
  firewall.wait_for { print dot; ready? }
105
- firewall.reload
106
106
 
107
107
  puts "\n"
108
108
  puts "#{ui.color('ID', :cyan)}: #{firewall.id}"
@@ -16,22 +16,20 @@ class Chef
16
16
  option :server_id,
17
17
  short: '-S SERVER_ID',
18
18
  long: '--server-id SERVER_ID',
19
- description: 'The ID of the server',
20
- required: true
21
-
19
+ description: 'The ID of the server'
22
20
  option :nic_id,
23
21
  short: '-N NIC_ID',
24
22
  long: '--nic-id NIC_ID',
25
- description: 'ID of the NIC',
26
- required: true
23
+ description: 'ID of the NIC'
27
24
 
28
25
  def run
26
+ validate_required_params(%i(datacenter_id server_id nic_id), Chef::Config[:knife])
29
27
  connection
30
28
  @name_args.each do |firewall_id|
31
29
  begin
32
- firewall = ProfitBricks::Firewall.get(config[:datacenter_id],
33
- config[:server_id],
34
- config[:nic_id],
30
+ firewall = ProfitBricks::Firewall.get(Chef::Config[:knife][:datacenter_id],
31
+ Chef::Config[:knife][:server_id],
32
+ Chef::Config[:knife][:nic_id],
35
33
  firewall_id)
36
34
  rescue Excon::Errors::NotFound
37
35
  ui.error("Firewall ID #{firewall_id} not found. Skipping.")
@@ -16,17 +16,18 @@ class Chef
16
16
  option :server_id,
17
17
  short: '-S SERVER_ID',
18
18
  long: '--server-id SERVER_ID',
19
- description: 'The ID of the server',
20
- required: true
19
+ description: 'The ID of the server'
21
20
 
22
21
  option :nic_id,
23
22
  short: '-N NIC_ID',
24
23
  long: '--nic-id NIC_ID',
25
- description: 'ID of the NIC',
26
- required: true
24
+ description: 'ID of the NIC'
27
25
 
28
26
  def run
29
27
  $stdout.sync = true
28
+
29
+ validate_required_params(%i(datacenter_id server_id nic_id), Chef::Config[:knife])
30
+
30
31
  firewall_list = [
31
32
  ui.color('ID', :bold),
32
33
  ui.color('Name', :bold),
@@ -41,7 +42,7 @@ class Chef
41
42
  ]
42
43
  connection
43
44
 
44
- ProfitBricks::Firewall.list(config[:datacenter_id], config[:server_id], config[:nic_id]).each do |firewall|
45
+ ProfitBricks::Firewall.list(Chef::Config[:knife][:datacenter_id], Chef::Config[:knife][:server_id], Chef::Config[:knife][:nic_id]).each do |firewall|
45
46
  firewall_list << firewall.id
46
47
  firewall_list << firewall.properties['name']
47
48
  firewall_list << firewall.properties['protocol'].to_s
@@ -10,24 +10,23 @@ class Chef
10
10
  option :location,
11
11
  short: '-l LOCATION',
12
12
  long: '--location LOCATION',
13
- description: 'Location of the IP block (us/las, de/fra, de/fkb)',
14
- required: true
13
+ description: 'Location of the IP block (us/las, us/ewr, de/fra, de/fkb)'
15
14
 
16
15
  option :size,
17
16
  short: '-S INT',
18
17
  long: '--size INT',
19
- description: 'The number of IP addresses to reserve',
20
- required: true
18
+ description: 'The number of IP addresses to reserve'
21
19
 
22
20
  def run
23
21
  $stdout.sync = true
22
+ validate_required_params(%i(size location), Chef::Config[:knife])
24
23
 
25
24
  print "#{ui.color('Allocating IP block...', :magenta)}"
26
25
 
27
26
  connection
28
27
  ipblock = ProfitBricks::IPBlock.create(
29
- location: config[:location],
30
- size: config[:size]
28
+ location: Chef::Config[:knife][:location],
29
+ size: Chef::Config[:knife][:size]
31
30
  )
32
31
 
33
32
  dot = ui.color('.', :magenta)
@@ -37,7 +36,7 @@ class Chef
37
36
  puts "#{ui.color('ID', :cyan)}: #{ipblock.id}"
38
37
  puts "#{ui.color('Location', :cyan)}: #{ipblock.properties['location']}"
39
38
  puts "#{ui.color('IP Addresses', :cyan)}: #{ipblock.properties['ips']}"
40
-
39
+ @ipid = ipblock.id
41
40
  puts 'done'
42
41
  end
43
42
  end