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
@@ -1,33 +1,33 @@
|
|
1
|
-
require 'chef/knife/oneandone_base'
|
2
|
-
|
3
|
-
class Chef
|
4
|
-
class Knife
|
5
|
-
class OneandoneFirewallList < Knife
|
6
|
-
include Knife::OneandoneBase
|
7
|
-
|
8
|
-
banner 'knife oneandone firewall list'
|
9
|
-
|
10
|
-
def run
|
11
|
-
$stdout.sync = true
|
12
|
-
|
13
|
-
init_client
|
14
|
-
|
15
|
-
response = OneAndOne::Firewall.new.list
|
16
|
-
formated_output(response, true)
|
17
|
-
|
18
|
-
firewall_list = [
|
19
|
-
ui.color('ID', :bold),
|
20
|
-
ui.color('Name', :bold),
|
21
|
-
ui.color('State', :bold)
|
22
|
-
]
|
23
|
-
response.each do |fw|
|
24
|
-
firewall_list << fw['id']
|
25
|
-
firewall_list << fw['name']
|
26
|
-
firewall_list << fw['state']
|
27
|
-
end
|
28
|
-
|
29
|
-
puts ui.list(firewall_list, :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 OneandoneFirewallList < Knife
|
6
|
+
include Knife::OneandoneBase
|
7
|
+
|
8
|
+
banner 'knife oneandone firewall list'
|
9
|
+
|
10
|
+
def run
|
11
|
+
$stdout.sync = true
|
12
|
+
|
13
|
+
init_client
|
14
|
+
|
15
|
+
response = OneAndOne::Firewall.new.list
|
16
|
+
formated_output(response, true)
|
17
|
+
|
18
|
+
firewall_list = [
|
19
|
+
ui.color('ID', :bold),
|
20
|
+
ui.color('Name', :bold),
|
21
|
+
ui.color('State', :bold)
|
22
|
+
]
|
23
|
+
response.each do |fw|
|
24
|
+
firewall_list << fw['id']
|
25
|
+
firewall_list << fw['name']
|
26
|
+
firewall_list << fw['state']
|
27
|
+
end
|
28
|
+
|
29
|
+
puts ui.list(firewall_list, :uneven_columns_across, 3)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,39 +1,39 @@
|
|
1
|
-
require 'chef/knife/oneandone_base'
|
2
|
-
|
3
|
-
class Chef
|
4
|
-
class Knife
|
5
|
-
class OneandoneIpList < Knife
|
6
|
-
include Knife::OneandoneBase
|
7
|
-
|
8
|
-
banner 'knife oneandone ip list'
|
9
|
-
|
10
|
-
def run
|
11
|
-
$stdout.sync = true
|
12
|
-
|
13
|
-
init_client
|
14
|
-
|
15
|
-
response = OneAndOne::PublicIP.new.list
|
16
|
-
formated_output(response, true)
|
17
|
-
|
18
|
-
ip_list = [
|
19
|
-
ui.color('ID', :bold),
|
20
|
-
ui.color('IP Address', :bold),
|
21
|
-
ui.color('DHCP', :bold),
|
22
|
-
ui.color('State', :bold),
|
23
|
-
ui.color('Data Center', :bold),
|
24
|
-
ui.color('Assigned To', :bold)
|
25
|
-
]
|
26
|
-
response.each do |ip|
|
27
|
-
ip_list << ip['id']
|
28
|
-
ip_list << ip['ip']
|
29
|
-
ip_list << ip['is_dhcp'].to_s
|
30
|
-
ip_list << ip['state']
|
31
|
-
ip_list << ip['datacenter']['country_code']
|
32
|
-
ip_list << (ip['assigned_to'].nil? ? '' : ip['assigned_to']['name'])
|
33
|
-
end
|
34
|
-
|
35
|
-
puts ui.list(ip_list, :uneven_columns_across, 6)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
1
|
+
require 'chef/knife/oneandone_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class OneandoneIpList < Knife
|
6
|
+
include Knife::OneandoneBase
|
7
|
+
|
8
|
+
banner 'knife oneandone ip list'
|
9
|
+
|
10
|
+
def run
|
11
|
+
$stdout.sync = true
|
12
|
+
|
13
|
+
init_client
|
14
|
+
|
15
|
+
response = OneAndOne::PublicIP.new.list
|
16
|
+
formated_output(response, true)
|
17
|
+
|
18
|
+
ip_list = [
|
19
|
+
ui.color('ID', :bold),
|
20
|
+
ui.color('IP Address', :bold),
|
21
|
+
ui.color('DHCP', :bold),
|
22
|
+
ui.color('State', :bold),
|
23
|
+
ui.color('Data Center', :bold),
|
24
|
+
ui.color('Assigned To', :bold)
|
25
|
+
]
|
26
|
+
response.each do |ip|
|
27
|
+
ip_list << ip['id']
|
28
|
+
ip_list << ip['ip']
|
29
|
+
ip_list << ip['is_dhcp'].to_s
|
30
|
+
ip_list << ip['state']
|
31
|
+
ip_list << ip['datacenter']['country_code']
|
32
|
+
ip_list << (ip['assigned_to'].nil? ? '' : ip['assigned_to']['name'])
|
33
|
+
end
|
34
|
+
|
35
|
+
puts ui.list(ip_list, :uneven_columns_across, 6)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -1,147 +1,147 @@
|
|
1
|
-
require 'chef/knife/oneandone_base'
|
2
|
-
require '1and1/helpers'
|
3
|
-
|
4
|
-
class Chef
|
5
|
-
class Knife
|
6
|
-
class OneandoneLoadbalancerCreate < Knife
|
7
|
-
include Knife::OneandoneBase
|
8
|
-
include Oneandone::Helpers
|
9
|
-
|
10
|
-
banner 'knife oneandone loadbalancer create (options)'
|
11
|
-
|
12
|
-
option :datacenter_id,
|
13
|
-
short: '-D DATACENTER_ID',
|
14
|
-
long: '--datacenter-id DATACENTER_ID',
|
15
|
-
description: 'ID of the virtual data center',
|
16
|
-
proc: proc { |datacenter_id| Chef::Config[:knife][:datacenter_id] = datacenter_id }
|
17
|
-
|
18
|
-
option :name,
|
19
|
-
short: '-n NAME',
|
20
|
-
long: '--name NAME',
|
21
|
-
description: 'Name of the load balancer (required)'
|
22
|
-
|
23
|
-
option :description,
|
24
|
-
long: '--description DESCRIPTION',
|
25
|
-
description: 'Description of the load balancer'
|
26
|
-
|
27
|
-
option :health_check,
|
28
|
-
long: '--health-check HEALTH_CHECK',
|
29
|
-
description: 'Health check test: TCP, ICMP or NONE. Default is TCP.',
|
30
|
-
default: 'TCP'
|
31
|
-
|
32
|
-
option :health_int,
|
33
|
-
long: '--health-int HEALTH_INTERVAL',
|
34
|
-
description: 'Health check interval (sec.). Default is 15.',
|
35
|
-
default: 15
|
36
|
-
|
37
|
-
option :health_path,
|
38
|
-
long: '--health-path HEALTH_PATH',
|
39
|
-
description: 'URL to call for the health checking'
|
40
|
-
|
41
|
-
option :health_regex,
|
42
|
-
long: '--health-regex HEALTH_REGEX',
|
43
|
-
description: 'Regular expression to check for the health checking'
|
44
|
-
|
45
|
-
option :method,
|
46
|
-
short: '-m METHOD',
|
47
|
-
long: '--method METHOD',
|
48
|
-
description: 'Balancing procedure: ROUND_ROBIN or LEAST_CONNECTIONS. Default is ROUND_ROBIN.',
|
49
|
-
default: 'ROUND_ROBIN'
|
50
|
-
|
51
|
-
option :persistence,
|
52
|
-
short: '-P',
|
53
|
-
long: '--persistence',
|
54
|
-
description: 'Enable load balancer persistence (true by default)',
|
55
|
-
boolean: true,
|
56
|
-
default: true
|
57
|
-
|
58
|
-
option :persistence_int,
|
59
|
-
long: '--persistence-int PERSISTENCE_INTERVAL',
|
60
|
-
description: 'Persistence interval (sec.). Default is 1200.',
|
61
|
-
default: 1200
|
62
|
-
|
63
|
-
option :port_balancer,
|
64
|
-
long: '--port-balancer [PORT_BALANCER]',
|
65
|
-
description: 'A comma separated list of the load balancer ports (80,161,443)'
|
66
|
-
|
67
|
-
option :port_server,
|
68
|
-
long: '--port-server [PORT_SERVER]',
|
69
|
-
description: 'A comma separated list of the servers ports (8080,161,443)'
|
70
|
-
|
71
|
-
option :protocol,
|
72
|
-
short: '-p [PROTOCOL]',
|
73
|
-
long: '--protocol [PROTOCOL]',
|
74
|
-
description: 'A comma separated list of the load balancer protocols (TCP,UDP)'
|
75
|
-
|
76
|
-
option :source,
|
77
|
-
short: '-S [SOURCE_IP]',
|
78
|
-
long: '--source [SOURCE_IP]',
|
79
|
-
description: 'A comma separated list of the source IPs from which the access is allowed'
|
80
|
-
|
81
|
-
option :wait,
|
82
|
-
short: '-W',
|
83
|
-
long: '--wait',
|
84
|
-
description: 'Wait for the operation to complete.'
|
85
|
-
|
86
|
-
def run
|
87
|
-
$stdout.sync = true
|
88
|
-
|
89
|
-
validate(config[:name], '-n NAME')
|
90
|
-
validate(config[:protocol], 'at least one value for --protocol [PROTOCOL]')
|
91
|
-
|
92
|
-
protocols = split_delimited_input(config[:protocol])
|
93
|
-
ports_balancer = split_delimited_input(config[:port_balancer])
|
94
|
-
ports_server = split_delimited_input(config[:port_server])
|
95
|
-
sources = split_delimited_input(config[:source])
|
96
|
-
|
97
|
-
validate_rules(protocols, ports_balancer, ports_server)
|
98
|
-
|
99
|
-
rules = []
|
100
|
-
|
101
|
-
for i in 0..(protocols.length - 1)
|
102
|
-
rule = {
|
103
|
-
'protocol' => protocols[i].upcase,
|
104
|
-
'port_balancer' => ports_balancer[i].to_i,
|
105
|
-
'port_server' => ports_server[i].to_i,
|
106
|
-
'source' => sources[i]
|
107
|
-
}
|
108
|
-
rules << rule
|
109
|
-
end
|
110
|
-
|
111
|
-
init_client
|
112
|
-
|
113
|
-
load_balancer = OneAndOne::LoadBalancer.new
|
114
|
-
response = load_balancer.create(
|
115
|
-
name: config[:name],
|
116
|
-
description: config[:description],
|
117
|
-
health_check_test: config[:health_check].to_s.upcase,
|
118
|
-
health_check_interval: config[:health_int].to_i,
|
119
|
-
persistence: config[:persistence],
|
120
|
-
persistence_time: config[:persistence_int].to_i,
|
121
|
-
method: config[:method].to_s.upcase,
|
122
|
-
rules: rules,
|
123
|
-
health_check_path: config[:health_path],
|
124
|
-
health_check_parse: config[:health_regex],
|
125
|
-
datacenter_id: config[:datacenter_id]
|
126
|
-
)
|
127
|
-
|
128
|
-
if config[:wait]
|
129
|
-
puts ui.color('Creating, wait for the operation to complete...', :cyan).to_s
|
130
|
-
load_balancer.wait_for
|
131
|
-
formated_output(load_balancer.get, true)
|
132
|
-
puts "Load balancer #{response['id']} is #{ui.color('created', :bold)}"
|
133
|
-
else
|
134
|
-
formated_output(response, true)
|
135
|
-
puts "Load balancer #{response['id']} is #{ui.color('being created', :bold)}"
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def validate_rules(protocols, ports_balancer, ports_server)
|
140
|
-
if (ports_balancer.length != ports_server.length) || (ports_balancer.length != protocols.length)
|
141
|
-
ui.error('You must supply equal number of --protocol, --port-balancer and --port-server values!')
|
142
|
-
exit 1
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
1
|
+
require 'chef/knife/oneandone_base'
|
2
|
+
require '1and1/helpers'
|
3
|
+
|
4
|
+
class Chef
|
5
|
+
class Knife
|
6
|
+
class OneandoneLoadbalancerCreate < Knife
|
7
|
+
include Knife::OneandoneBase
|
8
|
+
include Oneandone::Helpers
|
9
|
+
|
10
|
+
banner 'knife oneandone loadbalancer create (options)'
|
11
|
+
|
12
|
+
option :datacenter_id,
|
13
|
+
short: '-D DATACENTER_ID',
|
14
|
+
long: '--datacenter-id DATACENTER_ID',
|
15
|
+
description: 'ID of the virtual data center',
|
16
|
+
proc: proc { |datacenter_id| Chef::Config[:knife][:datacenter_id] = datacenter_id }
|
17
|
+
|
18
|
+
option :name,
|
19
|
+
short: '-n NAME',
|
20
|
+
long: '--name NAME',
|
21
|
+
description: 'Name of the load balancer (required)'
|
22
|
+
|
23
|
+
option :description,
|
24
|
+
long: '--description DESCRIPTION',
|
25
|
+
description: 'Description of the load balancer'
|
26
|
+
|
27
|
+
option :health_check,
|
28
|
+
long: '--health-check HEALTH_CHECK',
|
29
|
+
description: 'Health check test: TCP, ICMP or NONE. Default is TCP.',
|
30
|
+
default: 'TCP'
|
31
|
+
|
32
|
+
option :health_int,
|
33
|
+
long: '--health-int HEALTH_INTERVAL',
|
34
|
+
description: 'Health check interval (sec.). Default is 15.',
|
35
|
+
default: 15
|
36
|
+
|
37
|
+
option :health_path,
|
38
|
+
long: '--health-path HEALTH_PATH',
|
39
|
+
description: 'URL to call for the health checking'
|
40
|
+
|
41
|
+
option :health_regex,
|
42
|
+
long: '--health-regex HEALTH_REGEX',
|
43
|
+
description: 'Regular expression to check for the health checking'
|
44
|
+
|
45
|
+
option :method,
|
46
|
+
short: '-m METHOD',
|
47
|
+
long: '--method METHOD',
|
48
|
+
description: 'Balancing procedure: ROUND_ROBIN or LEAST_CONNECTIONS. Default is ROUND_ROBIN.',
|
49
|
+
default: 'ROUND_ROBIN'
|
50
|
+
|
51
|
+
option :persistence,
|
52
|
+
short: '-P',
|
53
|
+
long: '--persistence',
|
54
|
+
description: 'Enable load balancer persistence (true by default)',
|
55
|
+
boolean: true,
|
56
|
+
default: true
|
57
|
+
|
58
|
+
option :persistence_int,
|
59
|
+
long: '--persistence-int PERSISTENCE_INTERVAL',
|
60
|
+
description: 'Persistence interval (sec.). Default is 1200.',
|
61
|
+
default: 1200
|
62
|
+
|
63
|
+
option :port_balancer,
|
64
|
+
long: '--port-balancer [PORT_BALANCER]',
|
65
|
+
description: 'A comma separated list of the load balancer ports (80,161,443)'
|
66
|
+
|
67
|
+
option :port_server,
|
68
|
+
long: '--port-server [PORT_SERVER]',
|
69
|
+
description: 'A comma separated list of the servers ports (8080,161,443)'
|
70
|
+
|
71
|
+
option :protocol,
|
72
|
+
short: '-p [PROTOCOL]',
|
73
|
+
long: '--protocol [PROTOCOL]',
|
74
|
+
description: 'A comma separated list of the load balancer protocols (TCP,UDP)'
|
75
|
+
|
76
|
+
option :source,
|
77
|
+
short: '-S [SOURCE_IP]',
|
78
|
+
long: '--source [SOURCE_IP]',
|
79
|
+
description: 'A comma separated list of the source IPs from which the access is allowed'
|
80
|
+
|
81
|
+
option :wait,
|
82
|
+
short: '-W',
|
83
|
+
long: '--wait',
|
84
|
+
description: 'Wait for the operation to complete.'
|
85
|
+
|
86
|
+
def run
|
87
|
+
$stdout.sync = true
|
88
|
+
|
89
|
+
validate(config[:name], '-n NAME')
|
90
|
+
validate(config[:protocol], 'at least one value for --protocol [PROTOCOL]')
|
91
|
+
|
92
|
+
protocols = split_delimited_input(config[:protocol])
|
93
|
+
ports_balancer = split_delimited_input(config[:port_balancer])
|
94
|
+
ports_server = split_delimited_input(config[:port_server])
|
95
|
+
sources = split_delimited_input(config[:source])
|
96
|
+
|
97
|
+
validate_rules(protocols, ports_balancer, ports_server)
|
98
|
+
|
99
|
+
rules = []
|
100
|
+
|
101
|
+
for i in 0..(protocols.length - 1)
|
102
|
+
rule = {
|
103
|
+
'protocol' => protocols[i].upcase,
|
104
|
+
'port_balancer' => ports_balancer[i].to_i,
|
105
|
+
'port_server' => ports_server[i].to_i,
|
106
|
+
'source' => sources[i]
|
107
|
+
}
|
108
|
+
rules << rule
|
109
|
+
end
|
110
|
+
|
111
|
+
init_client
|
112
|
+
|
113
|
+
load_balancer = OneAndOne::LoadBalancer.new
|
114
|
+
response = load_balancer.create(
|
115
|
+
name: config[:name],
|
116
|
+
description: config[:description],
|
117
|
+
health_check_test: config[:health_check].to_s.upcase,
|
118
|
+
health_check_interval: config[:health_int].to_i,
|
119
|
+
persistence: config[:persistence],
|
120
|
+
persistence_time: config[:persistence_int].to_i,
|
121
|
+
method: config[:method].to_s.upcase,
|
122
|
+
rules: rules,
|
123
|
+
health_check_path: config[:health_path],
|
124
|
+
health_check_parse: config[:health_regex],
|
125
|
+
datacenter_id: config[:datacenter_id]
|
126
|
+
)
|
127
|
+
|
128
|
+
if config[:wait]
|
129
|
+
puts ui.color('Creating, wait for the operation to complete...', :cyan).to_s
|
130
|
+
load_balancer.wait_for
|
131
|
+
formated_output(load_balancer.get, true)
|
132
|
+
puts "Load balancer #{response['id']} is #{ui.color('created', :bold)}"
|
133
|
+
else
|
134
|
+
formated_output(response, true)
|
135
|
+
puts "Load balancer #{response['id']} is #{ui.color('being created', :bold)}"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def validate_rules(protocols, ports_balancer, ports_server)
|
140
|
+
if (ports_balancer.length != ports_server.length) || (ports_balancer.length != protocols.length)
|
141
|
+
ui.error('You must supply equal number of --protocol, --port-balancer and --port-server values!')
|
142
|
+
exit 1
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -1,59 +1,59 @@
|
|
1
|
-
require 'chef/knife/oneandone_base'
|
2
|
-
|
3
|
-
class Chef
|
4
|
-
class Knife
|
5
|
-
class OneandoneLoadbalancerDelete < Knife
|
6
|
-
include Knife::OneandoneBase
|
7
|
-
|
8
|
-
banner 'knife oneandone loadbalancer delete LOAD_BALANCER_ID [LOAD_BALANCER_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 |load_balancer_id|
|
21
|
-
load_balancer = OneAndOne::LoadBalancer.new
|
22
|
-
|
23
|
-
begin
|
24
|
-
load_balancer.get(load_balancer_id: load_balancer_id)
|
25
|
-
rescue StandardError => e
|
26
|
-
if e.message.include? 'NOT_FOUND'
|
27
|
-
ui.error("Load balancer ID #{load_balancer_id} not found. Skipping.")
|
28
|
-
else
|
29
|
-
ui.error(e.message)
|
30
|
-
end
|
31
|
-
next
|
32
|
-
end
|
33
|
-
|
34
|
-
load_balancer_name = load_balancer.specs['name']
|
35
|
-
|
36
|
-
confirm("Do you really want to delete load_balancer policy '#{load_balancer_name}'")
|
37
|
-
|
38
|
-
load_balancer.delete
|
39
|
-
|
40
|
-
if config[:wait]
|
41
|
-
begin
|
42
|
-
puts ui.color('Deleting, wait for the operation to complete...', :cyan).to_s
|
43
|
-
load_balancer.wait_for
|
44
|
-
puts "Load balancer '#{load_balancer_name}' is #{ui.color('deleted', :bold)}"
|
45
|
-
rescue StandardError => e
|
46
|
-
if e.message.include? 'NOT_FOUND'
|
47
|
-
puts "Load balancer '#{load_balancer_name}' is #{ui.color('deleted', :bold)}"
|
48
|
-
else
|
49
|
-
ui.error(e.message)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
else
|
53
|
-
puts "Load balancer '#{load_balancer_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 OneandoneLoadbalancerDelete < Knife
|
6
|
+
include Knife::OneandoneBase
|
7
|
+
|
8
|
+
banner 'knife oneandone loadbalancer delete LOAD_BALANCER_ID [LOAD_BALANCER_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 |load_balancer_id|
|
21
|
+
load_balancer = OneAndOne::LoadBalancer.new
|
22
|
+
|
23
|
+
begin
|
24
|
+
load_balancer.get(load_balancer_id: load_balancer_id)
|
25
|
+
rescue StandardError => e
|
26
|
+
if e.message.include? 'NOT_FOUND'
|
27
|
+
ui.error("Load balancer ID #{load_balancer_id} not found. Skipping.")
|
28
|
+
else
|
29
|
+
ui.error(e.message)
|
30
|
+
end
|
31
|
+
next
|
32
|
+
end
|
33
|
+
|
34
|
+
load_balancer_name = load_balancer.specs['name']
|
35
|
+
|
36
|
+
confirm("Do you really want to delete load_balancer policy '#{load_balancer_name}'")
|
37
|
+
|
38
|
+
load_balancer.delete
|
39
|
+
|
40
|
+
if config[:wait]
|
41
|
+
begin
|
42
|
+
puts ui.color('Deleting, wait for the operation to complete...', :cyan).to_s
|
43
|
+
load_balancer.wait_for
|
44
|
+
puts "Load balancer '#{load_balancer_name}' is #{ui.color('deleted', :bold)}"
|
45
|
+
rescue StandardError => e
|
46
|
+
if e.message.include? 'NOT_FOUND'
|
47
|
+
puts "Load balancer '#{load_balancer_name}' is #{ui.color('deleted', :bold)}"
|
48
|
+
else
|
49
|
+
ui.error(e.message)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
else
|
53
|
+
puts "Load balancer '#{load_balancer_name}' is #{ui.color('being deleted', :bold)}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|