knife-oneandone 1.0.0 → 1.2.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.
- checksums.yaml +4 -4
- data/.gitignore +12 -12
- data/.rspec +2 -2
- data/.rubocop.yml +29 -26
- data/.travis.yml +5 -5
- data/Gemfile +4 -4
- data/LICENSE +201 -201
- data/README.md +358 -278
- data/Rakefile +6 -6
- data/knife-oneandone.gemspec +30 -31
- data/lib/1and1/helpers.rb +29 -29
- data/lib/chef/knife/oneandone_appliance_list.rb +39 -39
- data/lib/chef/knife/oneandone_base.rb +32 -32
- data/lib/chef/knife/oneandone_block_storage_attach.rb +33 -0
- data/lib/chef/knife/oneandone_block_storage_create.rb +64 -0
- data/lib/chef/knife/oneandone_block_storage_delete.rb +59 -0
- data/lib/chef/knife/oneandone_block_storage_detach.rb +28 -0
- data/lib/chef/knife/oneandone_block_storage_list.rb +42 -0
- data/lib/chef/knife/oneandone_block_storage_rename.rb +38 -0
- data/lib/chef/knife/oneandone_datacenter_list.rb +33 -33
- data/lib/chef/knife/oneandone_firewall_create.rb +97 -97
- data/lib/chef/knife/oneandone_firewall_delete.rb +59 -59
- data/lib/chef/knife/oneandone_firewall_list.rb +33 -33
- data/lib/chef/knife/oneandone_ip_list.rb +39 -39
- data/lib/chef/knife/oneandone_loadbalancer_create.rb +147 -147
- data/lib/chef/knife/oneandone_loadbalancer_delete.rb +59 -59
- data/lib/chef/knife/oneandone_loadbalancer_list.rb +39 -39
- data/lib/chef/knife/oneandone_mp_list.rb +37 -37
- data/lib/chef/knife/oneandone_server_baremetal_model_list.rb +31 -0
- data/lib/chef/knife/oneandone_server_create.rb +193 -163
- data/lib/chef/knife/oneandone_server_delete.rb +63 -63
- data/lib/chef/knife/oneandone_server_hdd_add.rb +60 -60
- data/lib/chef/knife/oneandone_server_hdd_delete.rb +55 -55
- data/lib/chef/knife/oneandone_server_hdd_list.rb +44 -44
- data/lib/chef/knife/oneandone_server_hdd_resize.rb +59 -59
- data/lib/chef/knife/oneandone_server_list.rb +35 -35
- data/lib/chef/knife/oneandone_server_modify.rb +80 -80
- data/lib/chef/knife/oneandone_server_reboot.rb +41 -41
- data/lib/chef/knife/oneandone_server_rename.rb +37 -37
- data/lib/chef/knife/oneandone_server_size_list.rb +39 -39
- data/lib/chef/knife/oneandone_server_start.rb +35 -35
- data/lib/chef/knife/oneandone_server_stop.rb +41 -41
- data/lib/chef/knife/oneandone_ssh_key_create.rb +54 -0
- data/lib/chef/knife/oneandone_ssh_key_delete.rb +59 -0
- data/lib/chef/knife/oneandone_ssh_key_list.rb +44 -0
- data/lib/chef/knife/oneandone_ssh_key_rename.rb +37 -0
- data/lib/knife-oneandone/version.rb +5 -5
- metadata +24 -13
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'chef/knife/oneandone_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class OneandoneBlockStorageList < Knife
|
6
|
+
include Knife::OneandoneBase
|
7
|
+
|
8
|
+
banner 'knife oneandone block storage list'
|
9
|
+
|
10
|
+
def run
|
11
|
+
$stdout.sync = true
|
12
|
+
|
13
|
+
init_client
|
14
|
+
|
15
|
+
response = OneAndOne::BlockStorage.new.list
|
16
|
+
formated_output(response, true)
|
17
|
+
|
18
|
+
block_storages = [
|
19
|
+
ui.color('ID', :bold),
|
20
|
+
ui.color('Name', :bold),
|
21
|
+
ui.color('Size', :bold),
|
22
|
+
ui.color('State', :bold),
|
23
|
+
ui.color('Datacenter', :bold),
|
24
|
+
ui.color('Server ID', :bold),
|
25
|
+
ui.color('Server Name', :bold)
|
26
|
+
]
|
27
|
+
|
28
|
+
response.each do |blks|
|
29
|
+
block_storages << blks['id']
|
30
|
+
block_storages << blks['name']
|
31
|
+
block_storages << blks['size'].to_s
|
32
|
+
block_storages << blks['state']
|
33
|
+
block_storages << blks['datacenter']['country_code']
|
34
|
+
block_storages << (blks['server'].nil? ? '' : blks['server']['id'])
|
35
|
+
block_storages << (blks['server'].nil? ? '' : blks['server']['name'])
|
36
|
+
end
|
37
|
+
|
38
|
+
puts ui.list(block_storages, :uneven_columns_across, 7)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'chef/knife/oneandone_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class OneandoneBlockStorageRename < Knife
|
6
|
+
include Knife::OneandoneBase
|
7
|
+
|
8
|
+
banner 'knife oneandone block storage rename (options)'
|
9
|
+
|
10
|
+
option :name,
|
11
|
+
short: '-n NAME',
|
12
|
+
long: '--name NAME',
|
13
|
+
description: 'Name of the block storage'
|
14
|
+
|
15
|
+
option :description,
|
16
|
+
long: '--description DESCRIPTION',
|
17
|
+
description: 'Description of the block storage'
|
18
|
+
|
19
|
+
option :id,
|
20
|
+
short: '-I ID',
|
21
|
+
long: '--id ID',
|
22
|
+
description: 'Block storage ID'
|
23
|
+
|
24
|
+
def run
|
25
|
+
$stdout.sync = true
|
26
|
+
|
27
|
+
init_client
|
28
|
+
|
29
|
+
block_storage = OneAndOne::BlockStorage.new
|
30
|
+
response = block_storage.modify(block_storage_id: config[:id], name: config[:name],
|
31
|
+
description: config[:description])
|
32
|
+
|
33
|
+
formated_output(response, true)
|
34
|
+
puts "Block storage updated #{ui.color('updated', :bold)}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,33 +1,33 @@
|
|
1
|
-
require 'chef/knife/oneandone_base'
|
2
|
-
|
3
|
-
class Chef
|
4
|
-
class Knife
|
5
|
-
class OneandoneDatacenterList < Knife
|
6
|
-
include Knife::OneandoneBase
|
7
|
-
|
8
|
-
banner 'knife oneandone datacenter list'
|
9
|
-
|
10
|
-
def run
|
11
|
-
$stdout.sync = true
|
12
|
-
|
13
|
-
init_client
|
14
|
-
|
15
|
-
response = OneAndOne::Datacenter.new.list
|
16
|
-
formated_output(response, true)
|
17
|
-
|
18
|
-
datacenters = [
|
19
|
-
ui.color('ID', :bold),
|
20
|
-
ui.color('Location', :bold),
|
21
|
-
ui.color('Country Code', :bold)
|
22
|
-
]
|
23
|
-
response.each do |dc|
|
24
|
-
datacenters << dc['id']
|
25
|
-
datacenters << dc['location']
|
26
|
-
datacenters << dc['country_code']
|
27
|
-
end
|
28
|
-
|
29
|
-
puts ui.list(datacenters, :uneven_columns_across, 3)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
1
|
+
require 'chef/knife/oneandone_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class OneandoneDatacenterList < Knife
|
6
|
+
include Knife::OneandoneBase
|
7
|
+
|
8
|
+
banner 'knife oneandone datacenter list'
|
9
|
+
|
10
|
+
def run
|
11
|
+
$stdout.sync = true
|
12
|
+
|
13
|
+
init_client
|
14
|
+
|
15
|
+
response = OneAndOne::Datacenter.new.list
|
16
|
+
formated_output(response, true)
|
17
|
+
|
18
|
+
datacenters = [
|
19
|
+
ui.color('ID', :bold),
|
20
|
+
ui.color('Location', :bold),
|
21
|
+
ui.color('Country Code', :bold)
|
22
|
+
]
|
23
|
+
response.each do |dc|
|
24
|
+
datacenters << dc['id']
|
25
|
+
datacenters << dc['location']
|
26
|
+
datacenters << dc['country_code']
|
27
|
+
end
|
28
|
+
|
29
|
+
puts ui.list(datacenters, :uneven_columns_across, 3)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,97 +1,97 @@
|
|
1
|
-
require 'chef/knife/oneandone_base'
|
2
|
-
require '1and1/helpers'
|
3
|
-
|
4
|
-
class Chef
|
5
|
-
class Knife
|
6
|
-
class OneandoneFirewallCreate < Knife
|
7
|
-
include Knife::OneandoneBase
|
8
|
-
include Oneandone::Helpers
|
9
|
-
|
10
|
-
banner 'knife oneandone firewall create (options)'
|
11
|
-
|
12
|
-
option :name,
|
13
|
-
short: '-n NAME',
|
14
|
-
long: '--name NAME',
|
15
|
-
description: 'Name of the firewall (required)'
|
16
|
-
|
17
|
-
option :description,
|
18
|
-
long: '--description DESCRIPTION',
|
19
|
-
description: 'Description of the firewall'
|
20
|
-
|
21
|
-
option :port_from,
|
22
|
-
long: '--port-from [PORT_FROM]',
|
23
|
-
description: 'A comma separated list of the first firewall ports in range (80,161,443)'
|
24
|
-
|
25
|
-
option :port_to,
|
26
|
-
long: '--port-to [PORT_TO]',
|
27
|
-
description: 'A comma separated list of the second firewall ports in range (80,162,443)'
|
28
|
-
|
29
|
-
option :protocol,
|
30
|
-
short: '-p [PROTOCOL]',
|
31
|
-
long: '--protocol [PROTOCOL]',
|
32
|
-
description: 'A comma separated list of the firewall protocols (TCP,UDP,TCP/UDP,ICMP,IPSEC,GRE)'
|
33
|
-
|
34
|
-
option :source,
|
35
|
-
short: '-S [SOURCE_IP]',
|
36
|
-
long: '--source [SOURCE_IP]',
|
37
|
-
description: 'A comma separated list of the source IPs allowed to access though the firewall'
|
38
|
-
|
39
|
-
option :wait,
|
40
|
-
short: '-W',
|
41
|
-
long: '--wait',
|
42
|
-
description: 'Wait for the operation to complete.'
|
43
|
-
|
44
|
-
def run
|
45
|
-
$stdout.sync = true
|
46
|
-
|
47
|
-
validate(config[:name], '-n NAME')
|
48
|
-
validate(config[:protocol], 'at least one value for --protocol [PROTOCOL]')
|
49
|
-
|
50
|
-
protocols = split_delimited_input(config[:protocol])
|
51
|
-
ports_from = split_delimited_input(config[:port_from])
|
52
|
-
ports_to = split_delimited_input(config[:port_to])
|
53
|
-
sources = split_delimited_input(config[:source])
|
54
|
-
|
55
|
-
validate_rules(ports_from, ports_to, protocols)
|
56
|
-
|
57
|
-
rules = []
|
58
|
-
|
59
|
-
for i in 0..(protocols.length - 1)
|
60
|
-
rule = {
|
61
|
-
'protocol' => protocols[i].upcase,
|
62
|
-
'port_from' => ports_from[i].nil? ? nil : ports_from[i].to_i,
|
63
|
-
'port_to' => ports_to[i].nil? ? nil : ports_to[i].to_i,
|
64
|
-
'source' => sources[i]
|
65
|
-
}
|
66
|
-
rules << rule
|
67
|
-
end
|
68
|
-
|
69
|
-
init_client
|
70
|
-
|
71
|
-
firewall = OneAndOne::Firewall.new
|
72
|
-
response = firewall.create(name: config[:name], description: config[:description], rules: rules)
|
73
|
-
|
74
|
-
if config[:wait]
|
75
|
-
firewall.wait_for
|
76
|
-
formated_output(firewall.get, true)
|
77
|
-
puts "Firewall policy #{response['id']} is #{ui.color('created', :bold)}"
|
78
|
-
else
|
79
|
-
formated_output(response, true)
|
80
|
-
puts "Firewall policy #{response['id']} is #{ui.color('being created', :bold)}"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def validate_rules(ports_from, ports_to, protocols)
|
85
|
-
if ports_from.length != ports_to.length
|
86
|
-
ui.error('You must supply equal number of --port-from and --port-to values!')
|
87
|
-
exit 1
|
88
|
-
end
|
89
|
-
|
90
|
-
if protocols.length < ports_from.length
|
91
|
-
ui.error('It is required that the value count of --protocol >= --port-from value count!')
|
92
|
-
exit 1
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
1
|
+
require 'chef/knife/oneandone_base'
|
2
|
+
require '1and1/helpers'
|
3
|
+
|
4
|
+
class Chef
|
5
|
+
class Knife
|
6
|
+
class OneandoneFirewallCreate < Knife
|
7
|
+
include Knife::OneandoneBase
|
8
|
+
include Oneandone::Helpers
|
9
|
+
|
10
|
+
banner 'knife oneandone firewall create (options)'
|
11
|
+
|
12
|
+
option :name,
|
13
|
+
short: '-n NAME',
|
14
|
+
long: '--name NAME',
|
15
|
+
description: 'Name of the firewall (required)'
|
16
|
+
|
17
|
+
option :description,
|
18
|
+
long: '--description DESCRIPTION',
|
19
|
+
description: 'Description of the firewall'
|
20
|
+
|
21
|
+
option :port_from,
|
22
|
+
long: '--port-from [PORT_FROM]',
|
23
|
+
description: 'A comma separated list of the first firewall ports in range (80,161,443)'
|
24
|
+
|
25
|
+
option :port_to,
|
26
|
+
long: '--port-to [PORT_TO]',
|
27
|
+
description: 'A comma separated list of the second firewall ports in range (80,162,443)'
|
28
|
+
|
29
|
+
option :protocol,
|
30
|
+
short: '-p [PROTOCOL]',
|
31
|
+
long: '--protocol [PROTOCOL]',
|
32
|
+
description: 'A comma separated list of the firewall protocols (TCP,UDP,TCP/UDP,ICMP,IPSEC,GRE)'
|
33
|
+
|
34
|
+
option :source,
|
35
|
+
short: '-S [SOURCE_IP]',
|
36
|
+
long: '--source [SOURCE_IP]',
|
37
|
+
description: 'A comma separated list of the source IPs allowed to access though the firewall'
|
38
|
+
|
39
|
+
option :wait,
|
40
|
+
short: '-W',
|
41
|
+
long: '--wait',
|
42
|
+
description: 'Wait for the operation to complete.'
|
43
|
+
|
44
|
+
def run
|
45
|
+
$stdout.sync = true
|
46
|
+
|
47
|
+
validate(config[:name], '-n NAME')
|
48
|
+
validate(config[:protocol], 'at least one value for --protocol [PROTOCOL]')
|
49
|
+
|
50
|
+
protocols = split_delimited_input(config[:protocol])
|
51
|
+
ports_from = split_delimited_input(config[:port_from])
|
52
|
+
ports_to = split_delimited_input(config[:port_to])
|
53
|
+
sources = split_delimited_input(config[:source])
|
54
|
+
|
55
|
+
validate_rules(ports_from, ports_to, protocols)
|
56
|
+
|
57
|
+
rules = []
|
58
|
+
|
59
|
+
for i in 0..(protocols.length - 1)
|
60
|
+
rule = {
|
61
|
+
'protocol' => protocols[i].upcase,
|
62
|
+
'port_from' => ports_from[i].nil? ? nil : ports_from[i].to_i,
|
63
|
+
'port_to' => ports_to[i].nil? ? nil : ports_to[i].to_i,
|
64
|
+
'source' => sources[i]
|
65
|
+
}
|
66
|
+
rules << rule
|
67
|
+
end
|
68
|
+
|
69
|
+
init_client
|
70
|
+
|
71
|
+
firewall = OneAndOne::Firewall.new
|
72
|
+
response = firewall.create(name: config[:name], description: config[:description], rules: rules)
|
73
|
+
|
74
|
+
if config[:wait]
|
75
|
+
firewall.wait_for
|
76
|
+
formated_output(firewall.get, true)
|
77
|
+
puts "Firewall policy #{response['id']} is #{ui.color('created', :bold)}"
|
78
|
+
else
|
79
|
+
formated_output(response, true)
|
80
|
+
puts "Firewall policy #{response['id']} is #{ui.color('being created', :bold)}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def validate_rules(ports_from, ports_to, protocols)
|
85
|
+
if ports_from.length != ports_to.length
|
86
|
+
ui.error('You must supply equal number of --port-from and --port-to values!')
|
87
|
+
exit 1
|
88
|
+
end
|
89
|
+
|
90
|
+
if protocols.length < ports_from.length
|
91
|
+
ui.error('It is required that the value count of --protocol >= --port-from value count!')
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -1,59 +1,59 @@
|
|
1
|
-
require 'chef/knife/oneandone_base'
|
2
|
-
|
3
|
-
class Chef
|
4
|
-
class Knife
|
5
|
-
class OneandoneFirewallDelete < Knife
|
6
|
-
include Knife::OneandoneBase
|
7
|
-
|
8
|
-
banner 'knife oneandone firewall delete FIREWALL_ID [FIREWALL_ID] (options)'
|
9
|
-
|
10
|
-
option :wait,
|
11
|
-
short: '-W',
|
12
|
-
long: '--wait',
|
13
|
-
description: 'Wait for the operation to complete.'
|
14
|
-
|
15
|
-
def run
|
16
|
-
$stdout.sync = true
|
17
|
-
|
18
|
-
init_client
|
19
|
-
|
20
|
-
name_args.each do |firewall_id|
|
21
|
-
firewall = OneAndOne::Firewall.new
|
22
|
-
|
23
|
-
begin
|
24
|
-
firewall.get(firewall_id: firewall_id)
|
25
|
-
rescue StandardError => e
|
26
|
-
if e.message.include? 'NOT_FOUND'
|
27
|
-
ui.error("Firewall ID #{firewall_id} not found. Skipping.")
|
28
|
-
else
|
29
|
-
ui.error(e.message)
|
30
|
-
end
|
31
|
-
next
|
32
|
-
end
|
33
|
-
|
34
|
-
firewall_name = firewall.specs['name']
|
35
|
-
|
36
|
-
confirm("Do you really want to delete firewall policy '#{firewall_name}'")
|
37
|
-
|
38
|
-
firewall.delete
|
39
|
-
|
40
|
-
if config[:wait]
|
41
|
-
begin
|
42
|
-
puts ui.color('Deleting, wait for the operation to complete...', :cyan).to_s
|
43
|
-
firewall.wait_for
|
44
|
-
puts "Firewall policy '#{firewall_name}' is #{ui.color('deleted', :bold)}"
|
45
|
-
rescue StandardError => e
|
46
|
-
if e.message.include? 'NOT_FOUND'
|
47
|
-
puts "Firewall policy '#{firewall_name}' is #{ui.color('deleted', :bold)}"
|
48
|
-
else
|
49
|
-
ui.error(e.message)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
else
|
53
|
-
puts "Firewall policy '#{firewall_name}' is #{ui.color('being deleted', :bold)}"
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
1
|
+
require 'chef/knife/oneandone_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class OneandoneFirewallDelete < Knife
|
6
|
+
include Knife::OneandoneBase
|
7
|
+
|
8
|
+
banner 'knife oneandone firewall delete FIREWALL_ID [FIREWALL_ID] (options)'
|
9
|
+
|
10
|
+
option :wait,
|
11
|
+
short: '-W',
|
12
|
+
long: '--wait',
|
13
|
+
description: 'Wait for the operation to complete.'
|
14
|
+
|
15
|
+
def run
|
16
|
+
$stdout.sync = true
|
17
|
+
|
18
|
+
init_client
|
19
|
+
|
20
|
+
name_args.each do |firewall_id|
|
21
|
+
firewall = OneAndOne::Firewall.new
|
22
|
+
|
23
|
+
begin
|
24
|
+
firewall.get(firewall_id: firewall_id)
|
25
|
+
rescue StandardError => e
|
26
|
+
if e.message.include? 'NOT_FOUND'
|
27
|
+
ui.error("Firewall ID #{firewall_id} not found. Skipping.")
|
28
|
+
else
|
29
|
+
ui.error(e.message)
|
30
|
+
end
|
31
|
+
next
|
32
|
+
end
|
33
|
+
|
34
|
+
firewall_name = firewall.specs['name']
|
35
|
+
|
36
|
+
confirm("Do you really want to delete firewall policy '#{firewall_name}'")
|
37
|
+
|
38
|
+
firewall.delete
|
39
|
+
|
40
|
+
if config[:wait]
|
41
|
+
begin
|
42
|
+
puts ui.color('Deleting, wait for the operation to complete...', :cyan).to_s
|
43
|
+
firewall.wait_for
|
44
|
+
puts "Firewall policy '#{firewall_name}' is #{ui.color('deleted', :bold)}"
|
45
|
+
rescue StandardError => e
|
46
|
+
if e.message.include? 'NOT_FOUND'
|
47
|
+
puts "Firewall policy '#{firewall_name}' is #{ui.color('deleted', :bold)}"
|
48
|
+
else
|
49
|
+
ui.error(e.message)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
else
|
53
|
+
puts "Firewall policy '#{firewall_name}' is #{ui.color('being deleted', :bold)}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|