knife-ionoscloud 6.1.2 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/changelog.md +8 -0
- data/docs/docs_generator.rb +2 -1
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_create.md +60 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_delete.md +41 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_get.md +45 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_list.md +41 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_rule_add.md +69 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_rule_httprule_add.md +78 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_rule_httprule_remove.md +49 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_rule_remove.md +45 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_rule_update.md +70 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_update.md +60 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_create.md +79 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_delete.md +37 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_get.md +41 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_list.md +37 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_target_add.md +59 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_target_remove.md +49 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_update.md +80 -0
- data/docs/summary.md +61 -43
- data/knife-ionoscloud.gemspec +3 -2
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_create.rb +85 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_delete.rb +64 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_get.rb +45 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_list.rb +56 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_rule_add.rb +129 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_rule_httprule_add.rb +159 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_rule_httprule_remove.rb +89 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_rule_remove.rb +70 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_rule_update.rb +137 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_update.rb +96 -0
- data/lib/chef/knife/ionoscloud_base.rb +139 -7
- data/lib/chef/knife/ionoscloud_targetgroup_create.rb +140 -0
- data/lib/chef/knife/ionoscloud_targetgroup_delete.rb +50 -0
- data/lib/chef/knife/ionoscloud_targetgroup_get.rb +34 -0
- data/lib/chef/knife/ionoscloud_targetgroup_list.rb +45 -0
- data/lib/chef/knife/ionoscloud_targetgroup_target_add.rb +93 -0
- data/lib/chef/knife/ionoscloud_targetgroup_target_remove.rb +66 -0
- data/lib/chef/knife/ionoscloud_targetgroup_update.rb +151 -0
- data/lib/knife-ionoscloud/version.rb +1 -1
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_create_spec.rb +82 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_delete_spec.rb +110 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_get_spec.rb +70 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_list_spec.rb +87 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_rule_add_spec.rb +140 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_rule_httprule_add_spec.rb +238 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_rule_httprule_remove_spec.rb +204 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_rule_remove_spec.rb +127 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_rule_update_spec.rb +219 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_update_spec.rb +97 -0
- data/spec/chef/knife/ionoscloud_targetgroup_create_spec.rb +109 -0
- data/spec/chef/knife/ionoscloud_targetgroup_delete_spec.rb +111 -0
- data/spec/chef/knife/ionoscloud_targetgroup_get_spec.rb +71 -0
- data/spec/chef/knife/ionoscloud_targetgroup_list_spec.rb +78 -0
- data/spec/chef/knife/ionoscloud_targetgroup_target_add_spec.rb +164 -0
- data/spec/chef/knife/ionoscloud_targetgroup_target_remove_spec.rb +139 -0
- data/spec/chef/knife/ionoscloud_targetgroup_update_spec.rb +144 -0
- data/spec/spec_helper.rb +135 -27
- metadata +77 -9
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudTargetgroupTargetRemove < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud targetgroup target remove (options)'
|
9
|
+
|
10
|
+
option :target_group_id,
|
11
|
+
short: '-T TARGET_GROUP_ID',
|
12
|
+
long: '--target-group-id TARGET_GROUP_ID',
|
13
|
+
description: 'ID of the Target Group'
|
14
|
+
|
15
|
+
option :ip,
|
16
|
+
long: '--ip IP',
|
17
|
+
description: 'IP of a balanced target VM'
|
18
|
+
|
19
|
+
option :port,
|
20
|
+
short: '-p PORT',
|
21
|
+
long: '--port PORT',
|
22
|
+
description: 'Port of the balanced target service. (range: 1 to 65535)'
|
23
|
+
|
24
|
+
attr_reader :description, :required_options
|
25
|
+
|
26
|
+
def initialize(args = [])
|
27
|
+
super(args)
|
28
|
+
@description =
|
29
|
+
'Removes a Target from a Target Group if it exists.'
|
30
|
+
@directory = 'application-loadbalancer'
|
31
|
+
@required_options = [:target_group_id, :ip, :port]
|
32
|
+
end
|
33
|
+
|
34
|
+
def run
|
35
|
+
$stdout.sync = true
|
36
|
+
handle_extra_config
|
37
|
+
validate_required_params(@required_options, config)
|
38
|
+
|
39
|
+
target_groups_api = Ionoscloud::TargetGroupsApi.new(api_client)
|
40
|
+
|
41
|
+
target_group = target_groups_api.targetgroups_find_by_target_group_id(config[:target_group_id])
|
42
|
+
|
43
|
+
existing_target = target_group.properties.targets.find do |target|
|
44
|
+
target.ip == config[:ip] && target.port == Integer(config[:port])
|
45
|
+
end
|
46
|
+
|
47
|
+
if existing_target
|
48
|
+
target_group.properties.targets = target_group.properties.targets.reject do |target|
|
49
|
+
target.ip == config[:ip] && target.port == Integer(config[:port])
|
50
|
+
end
|
51
|
+
|
52
|
+
_, _, headers = target_groups_api.targetgroups_patch_with_http_info(config[:target_group_id], target_group.properties)
|
53
|
+
print "#{ui.color('Removing the Target from the Target Group...', :magenta)}"
|
54
|
+
dot = ui.color('.', :magenta)
|
55
|
+
api_client.wait_for { print dot; is_done? get_request_id headers }
|
56
|
+
|
57
|
+
target_group = target_groups_api.targetgroups_find_by_target_group_id(config[:target_group_id])
|
58
|
+
else
|
59
|
+
ui.warn("Specified target does not exist (#{config[:ip]}:#{config[:port]}).")
|
60
|
+
end
|
61
|
+
|
62
|
+
print_target_group(target_group)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudTargetgroupUpdate < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud targetgroup update (options)'
|
9
|
+
|
10
|
+
option :target_group_id,
|
11
|
+
short: '-T TARGET_GROUP_ID',
|
12
|
+
long: '--target-group-id TARGET_GROUP_ID',
|
13
|
+
description: 'ID of the Target Group'
|
14
|
+
|
15
|
+
option :name,
|
16
|
+
short: '-n NAME',
|
17
|
+
long: '--name NAME',
|
18
|
+
description: 'Name of the server'
|
19
|
+
|
20
|
+
option :algorithm,
|
21
|
+
short: '-a ALGORITHM',
|
22
|
+
long: '--algorithm ALGORITHM',
|
23
|
+
description: 'Algorithm for the balancing. One of ["ROUND_ROBIN", "LEAST_CONNECTION", "RANDOM", "SOURCE_IP"]'
|
24
|
+
|
25
|
+
option :protocol,
|
26
|
+
short: '-p PROTOCOL',
|
27
|
+
long: '--protocol PROTOCOL',
|
28
|
+
description: 'Protocol of the balancing. One of ["HTTP"]'
|
29
|
+
|
30
|
+
option :check_timeout,
|
31
|
+
long: '--check-timeout CHECK_TIMEOUT',
|
32
|
+
description: 'It specifies the time (in milliseconds) for a target VM in this pool to answer the check. If '\
|
33
|
+
'a target VM has CheckInterval set and CheckTimeout is set too, then the smaller value of the two is used '\
|
34
|
+
'after the TCP connection is established.'
|
35
|
+
|
36
|
+
option :check_interval,
|
37
|
+
long: '--check-interval check_interval',
|
38
|
+
description: 'It specifies the maximum time (in milliseconds) to wait for a connection attempt to a target '\
|
39
|
+
'VM to succeed. If unset, the default of 5 seconds will be used.'
|
40
|
+
|
41
|
+
option :retries,
|
42
|
+
short: '-r RETRIES',
|
43
|
+
long: '--retries RETRIES',
|
44
|
+
description: 'Retries specifies the number of retries to perform on a target VM after a connection failure. '\
|
45
|
+
'If unset, the default value of 3 will be used. (valid range: [0, 65535])'
|
46
|
+
|
47
|
+
option :path,
|
48
|
+
long: '--path PATH',
|
49
|
+
description: 'The path for the HTTP health check; default: /.'
|
50
|
+
|
51
|
+
option :method,
|
52
|
+
short: '-m METHOD',
|
53
|
+
long: '--method METHOD',
|
54
|
+
description: 'The method for the HTTP health check.'
|
55
|
+
|
56
|
+
option :match_type,
|
57
|
+
long: '--match-type MATCH_TYPE',
|
58
|
+
description: 'The method for the HTTP health check. One of ["STATUS_CODE", "RESPONSE_BODY"].'
|
59
|
+
|
60
|
+
option :response,
|
61
|
+
long: '--response RESPONSE',
|
62
|
+
description: 'The response returned by the request.'
|
63
|
+
|
64
|
+
option :regex,
|
65
|
+
long: '--regex REGEX',
|
66
|
+
description: 'The regex used.'
|
67
|
+
|
68
|
+
option :negate,
|
69
|
+
long: '--negate',
|
70
|
+
description: 'Whether to negate or not.'
|
71
|
+
|
72
|
+
option :targets,
|
73
|
+
long: '--targets',
|
74
|
+
description: 'Array of TargetGroup targets.'
|
75
|
+
|
76
|
+
attr_reader :description, :required_options
|
77
|
+
|
78
|
+
def initialize(args = [])
|
79
|
+
super(args)
|
80
|
+
@description =
|
81
|
+
'Updates information about a Ionoscloud Application LoadBalancer.'
|
82
|
+
@directory = 'application-loadbalancer'
|
83
|
+
@required_options = [:target_group_id]
|
84
|
+
@updatable_fields = [
|
85
|
+
:name, :algorithm, :protocol, :check_timeout, :connect_timeout, :target_timeout,
|
86
|
+
:retries, :path, :method, :match_type, :response, :regex, :negate, :targets,
|
87
|
+
]
|
88
|
+
end
|
89
|
+
|
90
|
+
def run
|
91
|
+
$stdout.sync = true
|
92
|
+
handle_extra_config
|
93
|
+
validate_required_params(@required_options, config)
|
94
|
+
|
95
|
+
target_groups_api = Ionoscloud::TargetGroupsApi.new(api_client)
|
96
|
+
|
97
|
+
if @updatable_fields.map { |el| config[el] }.any?
|
98
|
+
print "#{ui.color('Updating Target Group...', :magenta)}"
|
99
|
+
|
100
|
+
unless config[:targets].nil?
|
101
|
+
config[:targets] = JSON[config[:targets]] if config[:targets].instance_of?(String)
|
102
|
+
|
103
|
+
config[:targets].map! do |target|
|
104
|
+
Ionoscloud::TargetGroupTarget.new(
|
105
|
+
ip: target['ip'],
|
106
|
+
port: Integer(target['port']),
|
107
|
+
weight: Integer(target['weight']),
|
108
|
+
health_check_enabled: target['health_check_enabled'],
|
109
|
+
maintenance_enabled: target['maintenance_enabled'],
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
send_http_health_check = config[:path] || config[:method] || config[:match_type] || config[:response] || config[:regex] || config[:negate]
|
115
|
+
|
116
|
+
target_group_properties = {
|
117
|
+
name: config[:name],
|
118
|
+
algorithm: config[:algorithm],
|
119
|
+
protocol: config[:protocol],
|
120
|
+
targets: config[:targets],
|
121
|
+
health_check: Ionoscloud::TargetGroupHealthCheck.new(
|
122
|
+
check_timeout: config[:check_timeout],
|
123
|
+
check_interval: config[:check_interval],
|
124
|
+
retries: config[:retries],
|
125
|
+
),
|
126
|
+
http_health_check: send_http_health_check ? Ionoscloud::TargetGroupHttpHealthCheck.new(
|
127
|
+
path: config[:path],
|
128
|
+
method: config[:method],
|
129
|
+
match_type: config[:match_type],
|
130
|
+
response: config[:response],
|
131
|
+
regex: config[:regex],
|
132
|
+
negate: config[:negate],
|
133
|
+
) : nil,
|
134
|
+
}
|
135
|
+
|
136
|
+
_, _, headers = target_groups_api.targetgroups_patch_with_http_info(
|
137
|
+
config[:target_group_id],
|
138
|
+
Ionoscloud::TargetGroupProperties.new(**target_group_properties.compact),
|
139
|
+
)
|
140
|
+
|
141
|
+
dot = ui.color('.', :magenta)
|
142
|
+
api_client.wait_for { print dot; is_done? get_request_id headers }
|
143
|
+
else
|
144
|
+
ui.warn("Nothing to update, please set one of the attributes #{@updatable_fields}.")
|
145
|
+
end
|
146
|
+
|
147
|
+
print_target_group(Ionoscloud::TargetGroupsApi.new(api_client).targetgroups_find_by_target_group_id(config[:target_group_id]))
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_applicationloadbalancer_create'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudApplicationloadbalancerCreate.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudApplicationloadbalancerCreate do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudApplicationloadbalancerCreate.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should call ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_post with the expected arguments and output based on what it receives' do
|
16
|
+
application_loadbalancer = application_loadbalancer_mock
|
17
|
+
subject_config = {
|
18
|
+
ionoscloud_username: 'email',
|
19
|
+
ionoscloud_password: 'password',
|
20
|
+
datacenter_id: 'datacenter_id',
|
21
|
+
name: application_loadbalancer.properties.name,
|
22
|
+
ips: application_loadbalancer.properties.ips.join(','),
|
23
|
+
listener_lan: application_loadbalancer.properties.listener_lan,
|
24
|
+
target_lan: application_loadbalancer.properties.target_lan,
|
25
|
+
lb_private_ips: application_loadbalancer.properties.lb_private_ips.join(','),
|
26
|
+
}.each do |key, value|
|
27
|
+
subject.config[key] = value
|
28
|
+
end
|
29
|
+
|
30
|
+
expect(subject).to receive(:puts).with("ID: #{application_loadbalancer.id}")
|
31
|
+
expect(subject).to receive(:puts).with("Name: #{application_loadbalancer.properties.name}")
|
32
|
+
expect(subject).to receive(:puts).with("Listener LAN: #{application_loadbalancer.properties.listener_lan}")
|
33
|
+
expect(subject).to receive(:puts).with("IPS: #{application_loadbalancer.properties.ips}")
|
34
|
+
expect(subject).to receive(:puts).with("Target LAN: #{application_loadbalancer.properties.target_lan}")
|
35
|
+
expect(subject).to receive(:puts).with("Lb Private IPS: #{application_loadbalancer.properties.lb_private_ips}")
|
36
|
+
|
37
|
+
mock_wait_for(subject)
|
38
|
+
mock_call_api(
|
39
|
+
subject,
|
40
|
+
[
|
41
|
+
{
|
42
|
+
method: 'POST',
|
43
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers",
|
44
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_post',
|
45
|
+
return_type: 'ApplicationLoadBalancer',
|
46
|
+
body: { properties: application_loadbalancer.properties.to_hash },
|
47
|
+
result: application_loadbalancer,
|
48
|
+
},
|
49
|
+
{
|
50
|
+
method: 'GET',
|
51
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers/#{application_loadbalancer.id}",
|
52
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_find_by_application_load_balancer_id',
|
53
|
+
return_type: 'ApplicationLoadBalancer',
|
54
|
+
result: application_loadbalancer,
|
55
|
+
},
|
56
|
+
],
|
57
|
+
)
|
58
|
+
|
59
|
+
expect { subject.run }.not_to raise_error(Exception)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should not make any call if any required option is missing' do
|
63
|
+
required_options = subject.instance_variable_get(:@required_options)
|
64
|
+
|
65
|
+
if required_options.length > 0
|
66
|
+
arrays_without_one_element(required_options).each do |test_case|
|
67
|
+
subject.config[:ionoscloud_token] = 'token'
|
68
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
69
|
+
|
70
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
71
|
+
expect(subject.api_client).not_to receive(:call_api)
|
72
|
+
|
73
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
74
|
+
expect(error.status).to eq(1)
|
75
|
+
end
|
76
|
+
|
77
|
+
required_options.each { |value| subject.config[value] = nil }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_applicationloadbalancer_delete'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudApplicationloadbalancerDelete.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudApplicationloadbalancerDelete do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudApplicationloadbalancerDelete.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should call ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_delete when the ID is valid' do
|
16
|
+
application_loadbalancer = application_loadbalancer_mock
|
17
|
+
subject_config = {
|
18
|
+
ionoscloud_username: 'email',
|
19
|
+
ionoscloud_password: 'password',
|
20
|
+
datacenter_id: 'datacenter_id',
|
21
|
+
yes: true,
|
22
|
+
}
|
23
|
+
|
24
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
25
|
+
subject.name_args = [application_loadbalancer.id]
|
26
|
+
|
27
|
+
expect(subject).to receive(:puts).with("ID: #{application_loadbalancer.id}")
|
28
|
+
expect(subject).to receive(:puts).with("Name: #{application_loadbalancer.properties.name}")
|
29
|
+
expect(subject).to receive(:puts).with("Listener LAN: #{application_loadbalancer.properties.listener_lan}")
|
30
|
+
expect(subject).to receive(:puts).with("IPS: #{application_loadbalancer.properties.ips}")
|
31
|
+
expect(subject).to receive(:puts).with("Target LAN: #{application_loadbalancer.properties.target_lan}")
|
32
|
+
expect(subject).to receive(:puts).with("Lb Private IPS: #{application_loadbalancer.properties.lb_private_ips}")
|
33
|
+
expect(subject).to receive(:puts).with("Rules: #{subject.get_application_loadbalancer_extended_properties(application_loadbalancer)}")
|
34
|
+
|
35
|
+
expect(subject.ui).to receive(:warn).with("Deleted Application Load balancer #{application_loadbalancer.id}. Request ID: ")
|
36
|
+
|
37
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
38
|
+
expect(subject).to receive(:get_request_id).once
|
39
|
+
mock_call_api(
|
40
|
+
subject,
|
41
|
+
[
|
42
|
+
{
|
43
|
+
method: 'GET',
|
44
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers/#{application_loadbalancer.id}",
|
45
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_find_by_application_load_balancer_id',
|
46
|
+
return_type: 'ApplicationLoadBalancer',
|
47
|
+
result: application_loadbalancer,
|
48
|
+
},
|
49
|
+
{
|
50
|
+
method: 'DELETE',
|
51
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers/#{application_loadbalancer.id}",
|
52
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_delete',
|
53
|
+
},
|
54
|
+
],
|
55
|
+
)
|
56
|
+
|
57
|
+
expect { subject.run }.not_to raise_error(Exception)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should not call ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_delete when the ID is not valid' do
|
61
|
+
application_loadbalancer_id = 'invalid_id'
|
62
|
+
subject_config = {
|
63
|
+
ionoscloud_username: 'email',
|
64
|
+
ionoscloud_password: 'password',
|
65
|
+
datacenter_id: 'datacenter_id',
|
66
|
+
}
|
67
|
+
|
68
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
69
|
+
subject.name_args = [application_loadbalancer_id]
|
70
|
+
|
71
|
+
expect(subject.ui).to receive(:error).with("Application Load balancer ID #{application_loadbalancer_id} not found. Skipping.")
|
72
|
+
|
73
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
74
|
+
mock_call_api(
|
75
|
+
subject,
|
76
|
+
[
|
77
|
+
{
|
78
|
+
method: 'GET',
|
79
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers/#{application_loadbalancer_id}",
|
80
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_find_by_application_load_balancer_id',
|
81
|
+
return_type: 'ApplicationLoadBalancer',
|
82
|
+
exception: Ionoscloud::ApiError.new(code: 404),
|
83
|
+
},
|
84
|
+
],
|
85
|
+
)
|
86
|
+
|
87
|
+
expect { subject.run }.not_to raise_error(Exception)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should not make any call if any required option is missing' do
|
91
|
+
required_options = subject.instance_variable_get(:@required_options)
|
92
|
+
|
93
|
+
if required_options.length > 0
|
94
|
+
arrays_without_one_element(required_options).each do |test_case|
|
95
|
+
subject.config[:ionoscloud_token] = 'token'
|
96
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
97
|
+
|
98
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
99
|
+
expect(subject.api_client).not_to receive(:call_api)
|
100
|
+
|
101
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
102
|
+
expect(error.status).to eq(1)
|
103
|
+
end
|
104
|
+
|
105
|
+
required_options.each { |value| subject.config[value] = nil }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_applicationloadbalancer_get'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudApplicationloadbalancerGet.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudApplicationloadbalancerGet do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudApplicationloadbalancerGet.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should call LoadBalancersApi.datacenters_applicationloadbalancers_get' do
|
16
|
+
application_load_balancer = application_loadbalancer_mock
|
17
|
+
subject_config = {
|
18
|
+
ionoscloud_username: 'email',
|
19
|
+
ionoscloud_password: 'password',
|
20
|
+
datacenter_id: 'datacenter_id',
|
21
|
+
application_loadbalancer_id: application_load_balancer.id,
|
22
|
+
}
|
23
|
+
|
24
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
25
|
+
|
26
|
+
expect(subject).to receive(:puts).with("ID: #{application_load_balancer.id}")
|
27
|
+
expect(subject).to receive(:puts).with("Name: #{application_load_balancer.properties.name}")
|
28
|
+
expect(subject).to receive(:puts).with("Listener LAN: #{application_load_balancer.properties.listener_lan}")
|
29
|
+
expect(subject).to receive(:puts).with("IPS: #{application_load_balancer.properties.ips}")
|
30
|
+
expect(subject).to receive(:puts).with("Target LAN: #{application_load_balancer.properties.target_lan}")
|
31
|
+
expect(subject).to receive(:puts).with("Lb Private IPS: #{application_load_balancer.properties.lb_private_ips}")
|
32
|
+
expect(subject).to receive(:puts).with("Rules: #{subject.get_application_loadbalancer_extended_properties(application_load_balancer)}")
|
33
|
+
|
34
|
+
mock_call_api(
|
35
|
+
subject,
|
36
|
+
[
|
37
|
+
{
|
38
|
+
method: 'GET',
|
39
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers/#{subject_config[:application_loadbalancer_id]}",
|
40
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_find_by_application_load_balancer_id',
|
41
|
+
return_type: 'ApplicationLoadBalancer',
|
42
|
+
result: application_load_balancer,
|
43
|
+
},
|
44
|
+
],
|
45
|
+
)
|
46
|
+
|
47
|
+
expect { subject.run }.not_to raise_error(Exception)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should not make any call if any required option is missing' do
|
51
|
+
required_options = subject.instance_variable_get(:@required_options)
|
52
|
+
|
53
|
+
if required_options.length > 0
|
54
|
+
arrays_without_one_element(required_options).each do |test_case|
|
55
|
+
subject.config[:ionoscloud_token] = 'token'
|
56
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
57
|
+
|
58
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
59
|
+
expect(subject.api_client).not_to receive(:call_api)
|
60
|
+
|
61
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
62
|
+
expect(error.status).to eq(1)
|
63
|
+
end
|
64
|
+
|
65
|
+
required_options.each { |value| subject.config[value] = nil }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_applicationloadbalancer_list'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudApplicationloadbalancerList.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudApplicationloadbalancerList do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudApplicationloadbalancerList.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should call ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_get' do
|
16
|
+
application_loadbalancers = application_loadbalancers_mock
|
17
|
+
subject_config = {
|
18
|
+
ionoscloud_username: 'email',
|
19
|
+
ionoscloud_password: 'password',
|
20
|
+
datacenter_id: 'datacenter_id',
|
21
|
+
}
|
22
|
+
|
23
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
24
|
+
|
25
|
+
application_loadbalancer_list = [
|
26
|
+
subject.ui.color('ID', :bold),
|
27
|
+
subject.ui.color('Name', :bold),
|
28
|
+
subject.ui.color('Listener LAN', :bold),
|
29
|
+
subject.ui.color('Target LAN', :bold),
|
30
|
+
subject.ui.color('Rules', :bold),
|
31
|
+
subject.ui.color('IPS', :bold),
|
32
|
+
subject.ui.color('Private IPS', :bold),
|
33
|
+
application_loadbalancers.items.first.id,
|
34
|
+
application_loadbalancers.items.first.properties.name,
|
35
|
+
application_loadbalancers.items.first.properties.listener_lan,
|
36
|
+
application_loadbalancers.items.first.properties.target_lan,
|
37
|
+
application_loadbalancers.items.first.entities.forwardingrules.items.length,
|
38
|
+
application_loadbalancers.items.first.properties.ips,
|
39
|
+
application_loadbalancers.items.first.properties.lb_private_ips,
|
40
|
+
application_loadbalancers.items[1].id,
|
41
|
+
application_loadbalancers.items[1].properties.name,
|
42
|
+
application_loadbalancers.items[1].properties.listener_lan,
|
43
|
+
application_loadbalancers.items[1].properties.target_lan,
|
44
|
+
application_loadbalancers.items[1].entities.forwardingrules.items.length,
|
45
|
+
application_loadbalancers.items[1].properties.ips,
|
46
|
+
application_loadbalancers.items[1].properties.lb_private_ips,
|
47
|
+
]
|
48
|
+
|
49
|
+
expect(subject.ui).to receive(:list).with(application_loadbalancer_list, :uneven_columns_across, 7)
|
50
|
+
|
51
|
+
mock_call_api(
|
52
|
+
subject,
|
53
|
+
[
|
54
|
+
{
|
55
|
+
method: 'GET',
|
56
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers",
|
57
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_get',
|
58
|
+
return_type: 'ApplicationLoadBalancers',
|
59
|
+
result: application_loadbalancers,
|
60
|
+
},
|
61
|
+
],
|
62
|
+
)
|
63
|
+
|
64
|
+
expect { subject.run }.not_to raise_error(Exception)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should not make any call if any required option is missing' do
|
68
|
+
required_options = subject.instance_variable_get(:@required_options)
|
69
|
+
|
70
|
+
if required_options.length > 0
|
71
|
+
arrays_without_one_element(required_options).each do |test_case|
|
72
|
+
subject.config[:ionoscloud_token] = 'token'
|
73
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
74
|
+
|
75
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
76
|
+
expect(subject.api_client).not_to receive(:call_api)
|
77
|
+
|
78
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
79
|
+
expect(error.status).to eq(1)
|
80
|
+
end
|
81
|
+
|
82
|
+
required_options.each { |value| subject.config[value] = nil }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|