knife-profitbricks 1.0.0

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 (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +201 -0
  5. data/README.md +209 -0
  6. data/Rakefile +7 -0
  7. data/knife-profitbricks.gemspec +27 -0
  8. data/lib/chef/knife/profitbricks_base.rb +56 -0
  9. data/lib/chef/knife/profitbricks_datacenter_create.rb +51 -0
  10. data/lib/chef/knife/profitbricks_datacenter_delete.rb +44 -0
  11. data/lib/chef/knife/profitbricks_datacenter_list.rb +32 -0
  12. data/lib/chef/knife/profitbricks_firewall_create.rb +121 -0
  13. data/lib/chef/knife/profitbricks_firewall_delete.rb +58 -0
  14. data/lib/chef/knife/profitbricks_firewall_list.rb +59 -0
  15. data/lib/chef/knife/profitbricks_image_list.rb +35 -0
  16. data/lib/chef/knife/profitbricks_ipblock_create.rb +43 -0
  17. data/lib/chef/knife/profitbricks_ipblock_delete.rb +32 -0
  18. data/lib/chef/knife/profitbricks_ipblock_list.rb +29 -0
  19. data/lib/chef/knife/profitbricks_lan_create.rb +54 -0
  20. data/lib/chef/knife/profitbricks_lan_delete.rb +38 -0
  21. data/lib/chef/knife/profitbricks_lan_list.rb +35 -0
  22. data/lib/chef/knife/profitbricks_location_list.rb +26 -0
  23. data/lib/chef/knife/profitbricks_nic_create.rb +78 -0
  24. data/lib/chef/knife/profitbricks_nic_delete.rb +45 -0
  25. data/lib/chef/knife/profitbricks_nic_list.rb +44 -0
  26. data/lib/chef/knife/profitbricks_server_create.rb +81 -0
  27. data/lib/chef/knife/profitbricks_server_delete.rb +40 -0
  28. data/lib/chef/knife/profitbricks_server_list.rb +45 -0
  29. data/lib/chef/knife/profitbricks_server_reboot.rb +32 -0
  30. data/lib/chef/knife/profitbricks_server_start.rb +32 -0
  31. data/lib/chef/knife/profitbricks_server_stop.rb +32 -0
  32. data/lib/chef/knife/profitbricks_volume_attach.rb +38 -0
  33. data/lib/chef/knife/profitbricks_volume_create.rb +82 -0
  34. data/lib/chef/knife/profitbricks_volume_delete.rb +40 -0
  35. data/lib/chef/knife/profitbricks_volume_detach.rb +45 -0
  36. data/lib/chef/knife/profitbricks_volume_list.rb +61 -0
  37. data/lib/knife-profitbricks/version.rb +6 -0
  38. data/spec/chef/knife/profitbricks_datacenter_list_spec.rb +23 -0
  39. data/spec/spec_helper.rb +15 -0
  40. data/spec/test.sh +3 -0
  41. metadata +157 -0
@@ -0,0 +1,35 @@
1
+ require 'chef/knife/profitbricks_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProfitbricksImageList < Knife
6
+ include Knife::ProfitbricksBase
7
+
8
+ banner 'knife profitbricks image list'
9
+
10
+ def run
11
+ $stdout.sync = true
12
+ image_list = [
13
+ ui.color('ID', :bold),
14
+ ui.color('Name', :bold),
15
+ ui.color('Description', :bold),
16
+ ui.color('Location', :bold),
17
+ ui.color('Size', :bold),
18
+ ui.color('Public', :bold)
19
+ ]
20
+
21
+ connection
22
+ ProfitBricks::Image.list.each do |image|
23
+ image_list << image.id
24
+ image_list << image.properties['name']
25
+ image_list << image.properties['description']
26
+ image_list << image.properties['location']
27
+ image_list << image.properties['size'].to_s
28
+ image_list << image.properties['public'].to_s
29
+ end
30
+
31
+ puts ui.list(image_list, :uneven_columns_across, 6)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,43 @@
1
+ require 'chef/knife/profitbricks_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProfitbricksIpblockCreate < Knife
6
+ include Knife::ProfitbricksBase
7
+
8
+ banner 'knife profitbricks ipblock create (options)'
9
+
10
+ option :location,
11
+ short: '-l LOCATION',
12
+ long: '--location LOCATION',
13
+ description: 'Location of the IP block (us/las, de/fra, de/fkb)'
14
+
15
+ option :size,
16
+ short: '-S INT',
17
+ long: '--size INT',
18
+ description: 'The number of IP addresses to reserve'
19
+
20
+ def run
21
+ $stdout.sync = true
22
+
23
+ print "#{ui.color('Allocating IP block...', :magenta)}"
24
+
25
+ connection
26
+ ipblock = ProfitBricks::IPBlock.create(
27
+ location: config[:location],
28
+ size: config[:size]
29
+ )
30
+
31
+ dot = ui.color('.', :magenta)
32
+ ipblock.wait_for { print dot; ready? }
33
+
34
+ puts "\n"
35
+ puts "#{ui.color('ID', :cyan)}: #{ipblock.id}"
36
+ puts "#{ui.color('Location', :cyan)}: #{ipblock.properties['location']}"
37
+ puts "#{ui.color('IP Addresses', :cyan)}: #{ipblock.properties['ips']}"
38
+
39
+ puts 'done'
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,32 @@
1
+ require 'chef/knife/profitbricks_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProfitbricksIpblockDelete < Knife
6
+ include Knife::ProfitbricksBase
7
+
8
+ banner 'knife profitbricks ipblock delete IPBLOCK_ID [IPBLOCK_ID]'
9
+
10
+ def run
11
+ connection
12
+ @name_args.each do |ipblock_id|
13
+ begin
14
+ ipblock = ProfitBricks::IPBlock.get(ipblock_id)
15
+ rescue Excon::Errors::NotFound
16
+ ui.error("IP block ID #{ipblock_id} not found. Skipping.")
17
+ next
18
+ end
19
+
20
+ msg_pair('ID', ipblock.id)
21
+ msg_pair('Location', ipblock.properties['location'])
22
+ msg_pair('IP Addresses', ipblock.properties['ips'])
23
+
24
+ confirm('Do you really want to delete this IP block')
25
+
26
+ ipblock.delete
27
+ ui.warn("Released IP block #{ipblock.id}")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ require 'chef/knife/profitbricks_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProfitbricksIpblockList < Knife
6
+ include Knife::ProfitbricksBase
7
+
8
+ banner 'knife profitbricks ipblock list'
9
+
10
+ def run
11
+ $stdout.sync = true
12
+ ipblock_list = [
13
+ ui.color('ID', :bold),
14
+ ui.color('Location', :bold),
15
+ ui.color('IP Addresses', :bold),
16
+ ]
17
+ connection
18
+
19
+ ProfitBricks::IPBlock.list.each do |ipblock|
20
+ ipblock_list << ipblock.id
21
+ ipblock_list << ipblock.properties['location']
22
+ ipblock_list << ipblock.properties['ips'].join(", ").to_s
23
+ end
24
+
25
+ puts ui.list(ipblock_list, :uneven_columns_across, 3)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,54 @@
1
+ require 'chef/knife/profitbricks_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProfitbricksLanCreate < Knife
6
+ include Knife::ProfitbricksBase
7
+
8
+ banner 'knife profitbricks lan create (options)'
9
+
10
+ option :datacenter_id,
11
+ short: '-D DATACENTER_UUID',
12
+ long: '--datacenter-id DATACENTER_UUID',
13
+ description: 'Name of the data center',
14
+ proc: proc { |datacenter_id| Chef::Config[:knife][:datacenter_id] = datacenter_id }
15
+
16
+ option :name,
17
+ short: '-n NAME',
18
+ long: '--name NAME',
19
+ description: 'Name of the server'
20
+
21
+ option :public,
22
+ short: '-p',
23
+ long: '--public',
24
+ boolean: true,
25
+ default: false,
26
+ description: 'Boolean indicating if the LAN faces the public ' \
27
+ 'Internet or not; defaults to false'
28
+
29
+ def run
30
+ $stdout.sync = true
31
+
32
+ print "#{ui.color('Creating LAN...', :magenta)}"
33
+
34
+ connection
35
+ lan = ProfitBricks::LAN.create(
36
+ config[:datacenter_id],
37
+ name: config[:name],
38
+ public: config[:public]
39
+ )
40
+
41
+ dot = ui.color('.', :magenta)
42
+ lan.wait_for { print dot; ready? }
43
+ lan.reload
44
+
45
+ puts "\n"
46
+ puts "#{ui.color('ID', :cyan)}: #{lan.id}"
47
+ puts "#{ui.color('Name', :cyan)}: #{lan.properties['name']}"
48
+ puts "#{ui.color('Public', :cyan)}: #{lan.properties['public']}"
49
+
50
+ puts 'done'
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,38 @@
1
+ require 'chef/knife/profitbricks_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProfitbricksLanDelete < Knife
6
+ include Knife::ProfitbricksBase
7
+
8
+ banner 'knife profitbricks lan delete LAN_UUID [LAN_UUID] (options)'
9
+
10
+ option :datacenter_id,
11
+ short: '-D DATACENTER_UUID',
12
+ long: '--datacenter-id DATACENTER_UUID',
13
+ description: 'Name of the data center',
14
+ proc: proc { |datacenter_id| Chef::Config[:knife][:datacenter_id] = datacenter_id }
15
+
16
+ def run
17
+ connection
18
+ @name_args.each do |lan_id|
19
+ begin
20
+ lan = ProfitBricks::LAN.get(config[:datacenter_id], lan_id)
21
+ rescue Excon::Errors::NotFound
22
+ ui.error("Lan ID #{lan_id} not found. Skipping.")
23
+ next
24
+ end
25
+
26
+ msg_pair('ID', lan.id)
27
+ msg_pair('Name', lan.properties['name'])
28
+ msg_pair('Public', lan.properties['public'].to_s)
29
+
30
+ confirm('Do you really want to delete this LAN')
31
+
32
+ lan.delete
33
+ ui.warn("Deleted LAN #{lan.id}")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,35 @@
1
+ require 'chef/knife/profitbricks_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProfitbricksLanList < Knife
6
+ include Knife::ProfitbricksBase
7
+
8
+ banner 'knife profitbricks lan list (options)'
9
+
10
+ option :datacenter_id,
11
+ short: '-D DATACENTER_UUID',
12
+ long: '--datacenter-id DATACENTER_UUID',
13
+ description: 'The UUID of the data center',
14
+ proc: proc { |datacenter_id| Chef::Config[:knife][:datacenter_id] = datacenter_id }
15
+
16
+ def run
17
+ $stdout.sync = true
18
+ lan_list = [
19
+ ui.color('ID', :bold),
20
+ ui.color('Name', :bold),
21
+ ui.color('Public', :bold),
22
+ ]
23
+ connection
24
+
25
+ ProfitBricks::LAN.list(config[:datacenter_id]).each do |lan|
26
+ lan_list << lan.id
27
+ lan_list << lan.properties['name']
28
+ lan_list << lan.properties['public'].to_s
29
+ end
30
+
31
+ puts ui.list(lan_list, :uneven_columns_across, 3)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,26 @@
1
+ require 'chef/knife/profitbricks_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProfitbricksLocationList < Knife
6
+ include Knife::ProfitbricksBase
7
+
8
+ banner 'knife profitbricks location list'
9
+
10
+ def run
11
+ $stdout.sync = true
12
+ location_list = [
13
+ ui.color('ID', :bold),
14
+ ui.color('Name', :bold)
15
+ ]
16
+ connection
17
+ ProfitBricks::Location.list.each do |location|
18
+ location_list << location.id
19
+ location_list << location.properties['name']
20
+ end
21
+
22
+ puts ui.list(location_list, :uneven_columns_across, 2)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,78 @@
1
+ require 'chef/knife/profitbricks_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProfitbricksNicCreate < Knife
6
+ include Knife::ProfitbricksBase
7
+
8
+ banner 'knife profitbricks nic create (options)'
9
+
10
+ option :datacenter_id,
11
+ short: '-D DATACENTER_UUID',
12
+ long: '--datacenter-id DATACENTER_UUID',
13
+ description: 'Name of the data center',
14
+ proc: proc { |datacenter_id| Chef::Config[:knife][:datacenter_id] = datacenter_id }
15
+
16
+ option :server_id,
17
+ short: '-S SERVER_UUID',
18
+ long: '--server-id SERVER_UUID',
19
+ description: 'Name of the server'
20
+
21
+ option :name,
22
+ short: '-n NAME',
23
+ long: '--name NAME',
24
+ description: 'Name of the NIC'
25
+
26
+ option :ips,
27
+ short: '-i IP[,IP,...]',
28
+ long: '--ips IP[,IP,...]',
29
+ description: 'IPs assigned to the NIC',
30
+ proc: proc { |ips| ips.split(',') }
31
+
32
+ option :dhcp,
33
+ short: '-d',
34
+ long: '--dhcp',
35
+ boolean: true | false,
36
+ default: true,
37
+ description: 'Set to false if you wish to disable DHCP'
38
+
39
+ option :lan,
40
+ short: '-l ID',
41
+ long: '--lan ID',
42
+ description: 'The LAN ID the NIC will reside on; if the LAN ID does not exist it will be created'
43
+
44
+ def run
45
+ $stdout.sync = true
46
+
47
+ print "#{ui.color('Creating nic...', :magenta)}"
48
+
49
+ params = {
50
+ name: config[:name],
51
+ ips: config[:ips],
52
+ dhcp: config[:dhcp],
53
+ lan: config[:lan]
54
+ }
55
+
56
+ connection
57
+ nic = ProfitBricks::NIC.create(
58
+ config[:datacenter_id],
59
+ config[:server_id],
60
+ params.compact
61
+ )
62
+
63
+ dot = ui.color('.', :magenta)
64
+ nic.wait_for { print dot; ready? }
65
+ nic.reload
66
+
67
+ puts "\n"
68
+ puts "#{ui.color('ID', :cyan)}: #{nic.id}"
69
+ puts "#{ui.color('Name', :cyan)}: #{nic.properties['name']}"
70
+ puts "#{ui.color('IPs', :cyan)}: #{nic.properties['ips']}"
71
+ puts "#{ui.color('DHCP', :cyan)}: #{nic.properties['dhcp']}"
72
+ puts "#{ui.color('LAN', :cyan)}: #{nic.properties['lan']}"
73
+
74
+ puts 'done'
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,45 @@
1
+ require 'chef/knife/profitbricks_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProfitbricksNicDelete < Knife
6
+ include Knife::ProfitbricksBase
7
+
8
+ banner 'knife profitbricks nic delete NIC_UUID [NIC_UUID] (options)'
9
+
10
+ option :datacenter_id,
11
+ short: '-D DATACENTER_UUID',
12
+ long: '--datacenter-id DATACENTER_UUID',
13
+ description: 'The UUID of the data center',
14
+ proc: proc { |datacenter_id| Chef::Config[:knife][:datacenter_id] = datacenter_id }
15
+
16
+ option :server_id,
17
+ short: '-S SERVER_UUID',
18
+ long: '--server-id SERVER_UUID',
19
+ description: 'The UUID of the server assigned the NIC'
20
+
21
+ def run
22
+ connection
23
+ @name_args.each do |nic_id|
24
+ begin
25
+ nic = ProfitBricks::NIC.get(config[:datacenter_id], config[:server_id], nic_id)
26
+ rescue Excon::Errors::NotFound
27
+ ui.error("NIC ID #{nic_id} not found. Skipping.")
28
+ next
29
+ end
30
+
31
+ msg_pair('ID', nic.id)
32
+ msg_pair('Name', nic.properties['name'])
33
+ msg_pair('IPs', nic.properties['cores'])
34
+ msg_pair('DHCP', nic.properties['ram'])
35
+ msg_pair('LAN', nic.properties['availabilityZone'])
36
+
37
+ confirm('Do you really want to delete this NIC')
38
+
39
+ nic.delete
40
+ ui.warn("Deleted nic #{nic.id}")
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,44 @@
1
+ require 'chef/knife/profitbricks_base'
2
+
3
+ class Chef
4
+ class Knife
5
+ class ProfitbricksNicList < Knife
6
+ include Knife::ProfitbricksBase
7
+
8
+ banner 'knife profitbricks nic list (options)'
9
+
10
+ option :datacenter_id,
11
+ short: '-D DATACENTER_UUID',
12
+ long: '--datacenter-id DATACENTER_UUID',
13
+ description: 'The UUID of the datacenter containing the NIC',
14
+ proc: proc { |datacenter_id| Chef::Config[:knife][:datacenter_id] = datacenter_id }
15
+
16
+ option :server_id,
17
+ short: '-S SERVER_UUID',
18
+ long: '--server-id SERVER_UUID',
19
+ description: 'The UUID of the server assigned the NIC'
20
+
21
+ def run
22
+ $stdout.sync = true
23
+ nic_list = [
24
+ ui.color('ID', :bold),
25
+ ui.color('Name', :bold),
26
+ ui.color('IPs', :bold),
27
+ ui.color('DHCP', :bold),
28
+ ui.color('LAN', :bold)
29
+ ]
30
+ connection
31
+
32
+ ProfitBricks::NIC.list(config[:datacenter_id], config[:server_id]).each do |nic|
33
+ nic_list << nic.id
34
+ nic_list << nic.properties['name']
35
+ nic_list << nic.properties['ips'].to_s
36
+ nic_list << nic.properties['dhcp'].to_s
37
+ nic_list << nic.properties['lan'].to_s
38
+ end
39
+
40
+ puts ui.list(nic_list, :uneven_columns_across, 5)
41
+ end
42
+ end
43
+ end
44
+ end