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,96 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudApplicationloadbalancerUpdate < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud applicationloadbalancer update (options)'
|
9
|
+
|
10
|
+
option :datacenter_id,
|
11
|
+
short: '-D DATACENTER_ID',
|
12
|
+
long: '--datacenter-id DATACENTER_ID',
|
13
|
+
description: 'ID of the data center'
|
14
|
+
|
15
|
+
option :application_loadbalancer_id,
|
16
|
+
short: '-L APPLICATION_LOADBALANCER_ID',
|
17
|
+
long: '--application-loadbalancer APPLICATION_LOADBALANCER_ID',
|
18
|
+
description: 'ID of the Application Loadbalancer'
|
19
|
+
|
20
|
+
option :name,
|
21
|
+
short: '-n NAME',
|
22
|
+
long: '--name NAME',
|
23
|
+
description: 'Name of the Application Load Balancer'
|
24
|
+
|
25
|
+
option :listener_lan,
|
26
|
+
short: '-l LISTENER_LAN_ID',
|
27
|
+
long: '--listener-lan LISTENER_LAN_ID',
|
28
|
+
description: 'Id of the listening LAN. (inbound)'
|
29
|
+
|
30
|
+
option :target_lan,
|
31
|
+
short: '-t TARGET_LAN_ID',
|
32
|
+
long: '--target-lan TARGET_LAN_ID',
|
33
|
+
description: 'Id of the balanced private target LAN. (outbound)'
|
34
|
+
|
35
|
+
option :ips,
|
36
|
+
short: '-i IP[,IP,...]',
|
37
|
+
long: '--ips IP[,IP,...]',
|
38
|
+
description: 'Collection of IP addresses of the Application Load Balancer. (inbound and outbound) IP of the '\
|
39
|
+
'listenerLan must be a customer reserved IP for the public load balancer and private IP for the private load balancer.'
|
40
|
+
|
41
|
+
option :lb_private_ips,
|
42
|
+
long: '--private-ips IP[,IP,...]',
|
43
|
+
description: 'Collection of private IP addresses with subnet mask of the Application Load Balancer. '\
|
44
|
+
'IPs must contain valid subnet mask. If user will not provide any IP then the system will generate one IP with /24 subnet.'
|
45
|
+
|
46
|
+
attr_reader :description, :required_options
|
47
|
+
|
48
|
+
def initialize(args = [])
|
49
|
+
super(args)
|
50
|
+
@description =
|
51
|
+
'Updates information about a Ionoscloud Application LoadBalancer.'
|
52
|
+
@directory = 'application-loadbalancer'
|
53
|
+
@required_options = [:datacenter_id, :application_loadbalancer_id]
|
54
|
+
@updatable_fields = [:name, :listener_lan, :target_lan, :ips, :lb_private_ips]
|
55
|
+
end
|
56
|
+
|
57
|
+
def run
|
58
|
+
$stdout.sync = true
|
59
|
+
handle_extra_config
|
60
|
+
validate_required_params(@required_options, config)
|
61
|
+
|
62
|
+
application_load_balancers_api = Ionoscloud::ApplicationLoadBalancersApi.new(api_client)
|
63
|
+
|
64
|
+
if @updatable_fields.map { |el| config[el] }.any?
|
65
|
+
print "#{ui.color('Updating Application LoadBalancer...', :magenta)}"
|
66
|
+
|
67
|
+
config[:ips] = config[:ips].split(',') if config[:ips] && config[:ips].instance_of?(String)
|
68
|
+
config[:lb_private_ips] = config[:lb_private_ips].split(',') if config[:lb_private_ips] && config[:lb_private_ips].instance_of?(String)
|
69
|
+
|
70
|
+
_, _, headers = application_load_balancers_api.datacenters_applicationloadbalancers_patch_with_http_info(
|
71
|
+
config[:datacenter_id],
|
72
|
+
config[:application_loadbalancer_id],
|
73
|
+
Ionoscloud::ApplicationLoadBalancerProperties.new({
|
74
|
+
name: config[:name],
|
75
|
+
ips: config[:ips],
|
76
|
+
listener_lan: config[:listener_lan],
|
77
|
+
target_lan: config[:target_lan],
|
78
|
+
lb_private_ips: config[:lb_private_ips],
|
79
|
+
}.compact),
|
80
|
+
)
|
81
|
+
|
82
|
+
dot = ui.color('.', :magenta)
|
83
|
+
api_client.wait_for { print dot; is_done? get_request_id headers }
|
84
|
+
else
|
85
|
+
ui.warn("Nothing to update, please set one of the attributes #{@updatable_fields}.")
|
86
|
+
end
|
87
|
+
|
88
|
+
print_application_loadbalancer(
|
89
|
+
application_load_balancers_api.datacenters_applicationloadbalancers_find_by_application_load_balancer_id(
|
90
|
+
config[:datacenter_id], config[:application_loadbalancer_id], depth: 2,
|
91
|
+
),
|
92
|
+
)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -53,9 +53,7 @@ class Chef
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def msg_pair(label, value, color = :cyan)
|
56
|
-
if !value.nil? && !value.to_s.empty?
|
57
|
-
puts "#{ui.color(label, color)}: #{value}"
|
58
|
-
end
|
56
|
+
puts "#{ui.color(label, color)}: #{value}" if !value.nil? && !value.to_s.empty?
|
59
57
|
end
|
60
58
|
|
61
59
|
def validate_required_params(required_params, params)
|
@@ -84,7 +82,7 @@ class Chef
|
|
84
82
|
if config.key?(key) || !ionoscloud_options.include?(key)
|
85
83
|
ignored_options << key
|
86
84
|
else
|
87
|
-
config[key] = value
|
85
|
+
config[key] = value
|
88
86
|
end
|
89
87
|
end
|
90
88
|
|
@@ -116,7 +114,7 @@ class Chef
|
|
116
114
|
|
117
115
|
@api_client = Ionoscloud::ApiClient.new(api_config)
|
118
116
|
|
119
|
-
@api_client.user_agent =
|
117
|
+
@api_client.user_agent = [
|
120
118
|
'knife/v' + MODULE_VERSION,
|
121
119
|
@api_client.default_headers['User-Agent'],
|
122
120
|
'chef/' + Chef::VERSION,
|
@@ -141,7 +139,7 @@ class Chef
|
|
141
139
|
|
142
140
|
@api_client_dbaas = IonoscloudDbaasPostgres::ApiClient.new(api_config_dbaas)
|
143
141
|
|
144
|
-
@api_client_dbaas.user_agent =
|
142
|
+
@api_client_dbaas.user_agent = [
|
145
143
|
'knife/v' + MODULE_VERSION,
|
146
144
|
@api_client_dbaas.default_headers['User-Agent'],
|
147
145
|
'chef/' + Chef::VERSION,
|
@@ -167,6 +165,51 @@ class Chef
|
|
167
165
|
response.metadata.status == 'DONE'
|
168
166
|
end
|
169
167
|
|
168
|
+
def get_target_group_extended_properties(target_group)
|
169
|
+
health_check = target_group.properties.health_check.nil? ? nil : {
|
170
|
+
check_timeout: target_group.properties.health_check.check_timeout,
|
171
|
+
connect_timeout: target_group.properties.health_check.connect_timeout,
|
172
|
+
target_timeout: target_group.properties.health_check.target_timeout,
|
173
|
+
retries: target_group.properties.health_check.retries,
|
174
|
+
}
|
175
|
+
http_health_check = target_group.properties.http_health_check.nil? ? nil : {
|
176
|
+
path: target_group.properties.http_health_check.path,
|
177
|
+
method: target_group.properties.http_health_check.method,
|
178
|
+
match_type: target_group.properties.http_health_check.match_type,
|
179
|
+
response: target_group.properties.http_health_check.response,
|
180
|
+
regex: target_group.properties.http_health_check.regex,
|
181
|
+
negate: target_group.properties.http_health_check.negate,
|
182
|
+
}
|
183
|
+
targets = target_group.properties.targets.nil? ? [] : target_group.properties.targets.map do |target|
|
184
|
+
{
|
185
|
+
ip: target.ip,
|
186
|
+
port: target.port,
|
187
|
+
weight: target.weight,
|
188
|
+
health_check: target.health_check.nil? ? nil : {
|
189
|
+
check: target.health_check.check,
|
190
|
+
check_interval: target.health_check.check_interval,
|
191
|
+
maintenance: target.health_check.maintenance,
|
192
|
+
},
|
193
|
+
}
|
194
|
+
end
|
195
|
+
|
196
|
+
return health_check, http_health_check, targets
|
197
|
+
end
|
198
|
+
|
199
|
+
def print_target_group(target_group)
|
200
|
+
health_check, http_health_check, targets = get_target_group_extended_properties(target_group)
|
201
|
+
|
202
|
+
puts "\n"
|
203
|
+
puts "#{ui.color('ID', :cyan)}: #{target_group.id}"
|
204
|
+
puts "#{ui.color('Name', :cyan)}: #{target_group.properties.name}"
|
205
|
+
puts "#{ui.color('Algorithm', :cyan)}: #{target_group.properties.algorithm}"
|
206
|
+
puts "#{ui.color('Protocol', :cyan)}: #{target_group.properties.protocol}"
|
207
|
+
puts "#{ui.color('Health Check', :cyan)}: #{health_check}"
|
208
|
+
puts "#{ui.color('HTTP Health Check', :cyan)}: #{http_health_check}"
|
209
|
+
puts "#{ui.color('Targets', :cyan)}: #{targets}"
|
210
|
+
puts 'done'
|
211
|
+
end
|
212
|
+
|
170
213
|
def print_datacenter(datacenter)
|
171
214
|
print "\n"
|
172
215
|
cpu_architecture = datacenter.properties.cpu_architecture.nil? ? [] : datacenter.properties.cpu_architecture.map { |arch| arch.to_hash }
|
@@ -469,9 +512,98 @@ class Chef
|
|
469
512
|
puts "#{ui.color('Flowlogs', :cyan)}: #{natgateway.entities.flowlogs.items.map { |flowlog| flowlog.id }}"
|
470
513
|
end
|
471
514
|
|
515
|
+
def get_application_loadbalancer_extended_properties(application_loadbalancer)
|
516
|
+
fw_rules = application_loadbalancer.entities.forwardingrules.items
|
517
|
+
fw_rules.nil? ? [] : fw_rules.map do |rule|
|
518
|
+
{
|
519
|
+
id: rule.id,
|
520
|
+
name: rule.properties.name,
|
521
|
+
protocol: rule.properties.protocol,
|
522
|
+
listener_ip: rule.properties.listener_ip,
|
523
|
+
listener_port: rule.properties.listener_port,
|
524
|
+
client_timeout: rule.properties.client_timeout,
|
525
|
+
server_certificates: rule.properties.server_certificates,
|
526
|
+
http_rules: rule.properties.http_rules.nil? ? [] : rule.properties.http_rules.map do |http_rule|
|
527
|
+
{
|
528
|
+
name: http_rule.name,
|
529
|
+
type: http_rule.type,
|
530
|
+
target_group: http_rule.target_group,
|
531
|
+
drop_query: http_rule.drop_query,
|
532
|
+
location: http_rule.location,
|
533
|
+
status_code: http_rule.status_code,
|
534
|
+
response_message: http_rule.response_message,
|
535
|
+
content_type: http_rule.content_type,
|
536
|
+
conditions: http_rule.conditions.nil? ? [] : http_rule.conditions.map do |condition|
|
537
|
+
{
|
538
|
+
type: condition.type,
|
539
|
+
condition: condition.condition,
|
540
|
+
negate: condition.negate,
|
541
|
+
key: condition.key,
|
542
|
+
value: condition.value,
|
543
|
+
}
|
544
|
+
end,
|
545
|
+
}
|
546
|
+
end,
|
547
|
+
}
|
548
|
+
end
|
549
|
+
end
|
550
|
+
|
551
|
+
def print_application_loadbalancer(application_loadbalancer)
|
552
|
+
rules = get_application_loadbalancer_extended_properties(application_loadbalancer)
|
553
|
+
|
554
|
+
print "\n"
|
555
|
+
puts "#{ui.color('ID', :cyan)}: #{application_loadbalancer.id}"
|
556
|
+
puts "#{ui.color('Name', :cyan)}: #{application_loadbalancer.properties.name}"
|
557
|
+
puts "#{ui.color('Listener LAN', :cyan)}: #{application_loadbalancer.properties.listener_lan}"
|
558
|
+
puts "#{ui.color('Target LAN', :cyan)}: #{application_loadbalancer.properties.target_lan}"
|
559
|
+
puts "#{ui.color('IPS', :cyan)}: #{application_loadbalancer.properties.ips}"
|
560
|
+
puts "#{ui.color('Lb Private IPS', :cyan)}: #{application_loadbalancer.properties.lb_private_ips}"
|
561
|
+
puts "#{ui.color('Rules', :cyan)}: #{rules}"
|
562
|
+
end
|
563
|
+
|
564
|
+
def get_target_group_extended_properties(target_group)
|
565
|
+
health_check = target_group.properties.health_check.nil? ? nil : {
|
566
|
+
check_timeout: target_group.properties.health_check.check_timeout,
|
567
|
+
check_interval: target_group.properties.health_check.check_interval,
|
568
|
+
retries: target_group.properties.health_check.retries,
|
569
|
+
}
|
570
|
+
http_health_check = target_group.properties.http_health_check.nil? ? nil : {
|
571
|
+
path: target_group.properties.http_health_check.path,
|
572
|
+
method: target_group.properties.http_health_check.method,
|
573
|
+
match_type: target_group.properties.http_health_check.match_type,
|
574
|
+
response: target_group.properties.http_health_check.response,
|
575
|
+
regex: target_group.properties.http_health_check.regex,
|
576
|
+
negate: target_group.properties.http_health_check.negate,
|
577
|
+
}
|
578
|
+
targets = target_group.properties.targets.nil? ? [] : target_group.properties.targets.map do |target|
|
579
|
+
{
|
580
|
+
ip: target.ip,
|
581
|
+
port: target.port,
|
582
|
+
weight: target.weight,
|
583
|
+
health_check_enabled: target.health_check_enabled,
|
584
|
+
maintenance_enabled: target.maintenance_enabled,
|
585
|
+
}
|
586
|
+
end
|
587
|
+
|
588
|
+
return health_check, http_health_check, targets
|
589
|
+
end
|
590
|
+
|
591
|
+
def print_target_group(target_group)
|
592
|
+
health_check, http_health_check, targets = get_target_group_extended_properties(target_group)
|
593
|
+
print "\n"
|
594
|
+
puts "#{ui.color('ID', :cyan)}: #{target_group.id}"
|
595
|
+
puts "#{ui.color('Name', :cyan)}: #{target_group.properties.name}"
|
596
|
+
puts "#{ui.color('Algorithm', :cyan)}: #{target_group.properties.algorithm}"
|
597
|
+
puts "#{ui.color('Protocol', :cyan)}: #{target_group.properties.protocol}"
|
598
|
+
puts "#{ui.color('Health Check', :cyan)}: #{health_check}"
|
599
|
+
puts "#{ui.color('HTTP Health Check', :cyan)}: #{http_health_check}"
|
600
|
+
puts "#{ui.color('Targets', :cyan)}: #{targets}"
|
601
|
+
puts 'done'
|
602
|
+
end
|
603
|
+
|
472
604
|
def print_cluster(cluster)
|
473
605
|
connections = cluster.properties.connections.map { |connection| connection.to_hash }
|
474
|
-
|
606
|
+
|
475
607
|
print "\n"
|
476
608
|
puts "#{ui.color('ID', :cyan)}: #{cluster.id}"
|
477
609
|
puts "#{ui.color('Display Name', :cyan)}: #{cluster.properties.display_name}"
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudTargetgroupCreate < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud targetgroup create (options)'
|
9
|
+
|
10
|
+
option :name,
|
11
|
+
short: '-n NAME',
|
12
|
+
long: '--name NAME',
|
13
|
+
description: 'Name of the server'
|
14
|
+
|
15
|
+
option :algorithm,
|
16
|
+
short: '-a ALGORITHM',
|
17
|
+
long: '--algorithm ALGORITHM',
|
18
|
+
description: 'Algorithm for the balancing. One of ["ROUND_ROBIN", "LEAST_CONNECTION", "RANDOM", "SOURCE_IP"]'
|
19
|
+
|
20
|
+
option :protocol,
|
21
|
+
short: '-p PROTOCOL',
|
22
|
+
long: '--protocol PROTOCOL',
|
23
|
+
description: 'Protocol of the balancing. One of ["HTTP"]'
|
24
|
+
|
25
|
+
option :check_timeout,
|
26
|
+
long: '--check-timeout CHECK_TIMEOUT',
|
27
|
+
description: 'It specifies the time (in milliseconds) for a target VM in this pool to answer the check. If '\
|
28
|
+
'a target VM has CheckInterval set and CheckTimeout is set too, then the smaller value of the two is used '\
|
29
|
+
'after the TCP connection is established.'
|
30
|
+
|
31
|
+
option :check_interval,
|
32
|
+
long: '--check-interval check_interval',
|
33
|
+
description: 'It specifies the maximum time (in milliseconds) to wait for a connection attempt to a target '\
|
34
|
+
'VM to succeed. If unset, the default of 5 seconds will be used.'
|
35
|
+
|
36
|
+
option :retries,
|
37
|
+
short: '-r RETRIES',
|
38
|
+
long: '--retries RETRIES',
|
39
|
+
description: 'Retries specifies the number of retries to perform on a target VM after a connection failure. '\
|
40
|
+
'If unset, the default value of 3 will be used. (valid range: [0, 65535])'
|
41
|
+
|
42
|
+
option :path,
|
43
|
+
long: '--path PATH',
|
44
|
+
description: 'The path for the HTTP health check; default: /.'
|
45
|
+
|
46
|
+
option :method,
|
47
|
+
short: '-m METHOD',
|
48
|
+
long: '--method METHOD',
|
49
|
+
description: 'The method for the HTTP health check.'
|
50
|
+
|
51
|
+
option :match_type,
|
52
|
+
long: '--match-type MATCH_TYPE',
|
53
|
+
description: 'The method for the HTTP health check. One of ["STATUS_CODE", "RESPONSE_BODY"].'
|
54
|
+
|
55
|
+
option :response,
|
56
|
+
long: '--response RESPONSE',
|
57
|
+
description: 'The response returned by the request.'
|
58
|
+
|
59
|
+
option :regex,
|
60
|
+
long: '--regex REGEX',
|
61
|
+
description: 'The regex used.'
|
62
|
+
|
63
|
+
option :negate,
|
64
|
+
long: '--negate',
|
65
|
+
description: 'Whether to negate or not.'
|
66
|
+
|
67
|
+
option :targets,
|
68
|
+
long: '--targets',
|
69
|
+
description: 'Array of TargetGroup targets.'
|
70
|
+
|
71
|
+
attr_reader :description, :required_options
|
72
|
+
|
73
|
+
def initialize(args = [])
|
74
|
+
super(args)
|
75
|
+
@description =
|
76
|
+
'Creates a new Target Group.'
|
77
|
+
@directory = 'application-loadbalancer'
|
78
|
+
@required_options = [:name, :algorithm, :protocol]
|
79
|
+
end
|
80
|
+
|
81
|
+
def run
|
82
|
+
$stdout.sync = true
|
83
|
+
handle_extra_config
|
84
|
+
validate_required_params(@required_options, config)
|
85
|
+
|
86
|
+
target_groups_api = Ionoscloud::TargetGroupsApi.new(api_client)
|
87
|
+
|
88
|
+
unless config[:targets].nil?
|
89
|
+
config[:targets] = JSON[config[:targets]] if config[:targets].instance_of?(String)
|
90
|
+
|
91
|
+
config[:targets].map! do |target|
|
92
|
+
Ionoscloud::TargetGroupTarget.new(
|
93
|
+
ip: target['ip'],
|
94
|
+
port: Integer(target['port']),
|
95
|
+
weight: Integer(target['weight']),
|
96
|
+
health_check_enabled: target['health_check_enabled'],
|
97
|
+
maintenance_enabled: target['maintenance_enabled'],
|
98
|
+
)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
send_http_health_check = config[:path] || config[:method] || config[:match_type] || config[:response] || config[:regex] || config[:negate]
|
103
|
+
|
104
|
+
target_group_properties = {
|
105
|
+
name: config[:name],
|
106
|
+
algorithm: config[:algorithm],
|
107
|
+
protocol: config[:protocol],
|
108
|
+
targets: config[:targets],
|
109
|
+
health_check: Ionoscloud::TargetGroupHealthCheck.new(
|
110
|
+
check_timeout: config[:check_timeout],
|
111
|
+
check_interval: config[:check_interval],
|
112
|
+
retries: config[:retries],
|
113
|
+
),
|
114
|
+
http_health_check: send_http_health_check ? Ionoscloud::TargetGroupHttpHealthCheck.new(
|
115
|
+
path: config[:path],
|
116
|
+
method: config[:method],
|
117
|
+
match_type: config[:match_type],
|
118
|
+
response: config[:response],
|
119
|
+
regex: config[:regex],
|
120
|
+
negate: config[:negate],
|
121
|
+
) : nil,
|
122
|
+
}
|
123
|
+
|
124
|
+
target_group = Ionoscloud::TargetGroup.new(
|
125
|
+
properties: Ionoscloud::TargetGroupProperties.new(
|
126
|
+
**target_group_properties.compact,
|
127
|
+
),
|
128
|
+
)
|
129
|
+
|
130
|
+
target_group, _, headers = target_groups_api.targetgroups_post_with_http_info(target_group)
|
131
|
+
|
132
|
+
print "#{ui.color('Creating Target Group...', :magenta)}"
|
133
|
+
dot = ui.color('.', :magenta)
|
134
|
+
api_client.wait_for { print dot; is_done? get_request_id headers }
|
135
|
+
|
136
|
+
print_target_group(target_groups_api.targetgroups_find_by_target_group_id(target_group.id))
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudTargetgroupDelete < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud targetgroup delete TARGET_GROUP_ID [TARGET_GROUP_ID]'
|
9
|
+
|
10
|
+
attr_reader :description, :required_options
|
11
|
+
|
12
|
+
def initialize(args = [])
|
13
|
+
super(args)
|
14
|
+
@description =
|
15
|
+
'Deletes a Target Group'
|
16
|
+
@directory = 'application-loadbalancer'
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
$stdout.sync = true
|
21
|
+
handle_extra_config
|
22
|
+
validate_required_params(@required_options, config)
|
23
|
+
|
24
|
+
target_group_api = Ionoscloud::TargetGroupsApi.new(api_client)
|
25
|
+
|
26
|
+
@name_args.each do |target_group_id|
|
27
|
+
begin
|
28
|
+
target_group = target_group_api.targetgroups_find_by_target_group_id(target_group_id)
|
29
|
+
rescue Ionoscloud::ApiError => err
|
30
|
+
raise err unless err.code == 404
|
31
|
+
ui.error("Target Group ID #{target_group_id} not found. Skipping.")
|
32
|
+
next
|
33
|
+
end
|
34
|
+
|
35
|
+
print_target_group(target_group)
|
36
|
+
puts "\n"
|
37
|
+
|
38
|
+
begin
|
39
|
+
confirm('Do you really want to delete this Target Group')
|
40
|
+
rescue SystemExit
|
41
|
+
next
|
42
|
+
end
|
43
|
+
|
44
|
+
_, _, headers = target_group_api.target_groups_delete_with_http_info(target_group_id)
|
45
|
+
ui.warn("Deleted Target Group #{target_group.id}. Request ID: #{get_request_id headers}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudTargetgroupGet < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud targetgroup get (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
|
+
attr_reader :description, :required_options
|
16
|
+
|
17
|
+
def initialize(args = [])
|
18
|
+
super(args)
|
19
|
+
@description =
|
20
|
+
'Gets information about a Target Group.'
|
21
|
+
@directory = 'application-loadbalancer'
|
22
|
+
@required_options = [:target_group_id]
|
23
|
+
end
|
24
|
+
|
25
|
+
def run
|
26
|
+
$stdout.sync = true
|
27
|
+
handle_extra_config
|
28
|
+
validate_required_params(@required_options, config)
|
29
|
+
|
30
|
+
print_target_group(Ionoscloud::TargetGroupsApi.new(api_client).targetgroups_find_by_target_group_id(config[:target_group_id]))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudTargetgroupList < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud targetgroup list'
|
9
|
+
|
10
|
+
attr_reader :description, :required_options
|
11
|
+
|
12
|
+
def initialize(args = [])
|
13
|
+
super(args)
|
14
|
+
@description = 'Lists all available Target Groups.'
|
15
|
+
@directory = 'application-loadbalancer'
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
$stdout.sync = true
|
20
|
+
handle_extra_config
|
21
|
+
validate_required_params(@required_options, config)
|
22
|
+
|
23
|
+
target_group_list = [
|
24
|
+
ui.color('ID', :bold),
|
25
|
+
ui.color('Name', :bold),
|
26
|
+
ui.color('Algorithm', :bold),
|
27
|
+
ui.color('Protocol', :bold),
|
28
|
+
ui.color('Targets', :bold),
|
29
|
+
]
|
30
|
+
|
31
|
+
target_group_api = Ionoscloud::TargetGroupsApi.new(api_client)
|
32
|
+
|
33
|
+
target_group_api.targetgroups_get({ depth: 1 }).items.each do |target_group|
|
34
|
+
target_group_list << target_group.id
|
35
|
+
target_group_list << target_group.properties.name
|
36
|
+
target_group_list << target_group.properties.algorithm
|
37
|
+
target_group_list << target_group.properties.protocol
|
38
|
+
target_group_list << target_group.properties.targets.nil? ? 0 : target_group.properties.targets.length
|
39
|
+
end
|
40
|
+
|
41
|
+
puts ui.list(target_group_list, :uneven_columns_across, 5)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudTargetgroupTargetAdd < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud targetgroup target add (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
|
+
option :weight,
|
25
|
+
short: '-w WEIGHT',
|
26
|
+
long: '--weight WEIGHT',
|
27
|
+
description: 'Weight parameter is used to adjust the target VM\'s weight relative to other target VMs. '\
|
28
|
+
'All target VMs will receive a load proportional to their weight relative to the sum of all weights, '\
|
29
|
+
'so the higher the weight, the higher the load. The default weight is 1, and the maximal value is 256. '\
|
30
|
+
'A value of 0 means the target VM will not participate in load-balancing but will still accept persistent '\
|
31
|
+
'connections. If this parameter is used to distribute the load according to target VM\'s capacity, it is '\
|
32
|
+
'recommended to start with values which can both grow and shrink, for instance between 10 and 100 to leave '\
|
33
|
+
'enough room above and below for later adjustments.'
|
34
|
+
|
35
|
+
option :health_check_disable,
|
36
|
+
long: '--health-check-disable',
|
37
|
+
description: 'Enabling the health check makes the target available only if it accepts periodic health check '\
|
38
|
+
'TCP connection attempts; when turned off, the target is considered always available. The health check only '\
|
39
|
+
'consists of a connection attempt to the address and port of the target. Default is having the health check enabled.',
|
40
|
+
boolean: true
|
41
|
+
|
42
|
+
option :maintenance_enabled,
|
43
|
+
long: '--maintenance',
|
44
|
+
description: 'Maintenance mode prevents the target from receiving balanced traffic.',
|
45
|
+
boolean: true
|
46
|
+
|
47
|
+
attr_reader :description, :required_options
|
48
|
+
|
49
|
+
def initialize(args = [])
|
50
|
+
super(args)
|
51
|
+
@description =
|
52
|
+
'Adds a Target to a Target Group.'
|
53
|
+
@directory = 'application-loadbalancer'
|
54
|
+
@required_options = [:target_group_id, :ip, :port, :weight]
|
55
|
+
end
|
56
|
+
|
57
|
+
def run
|
58
|
+
$stdout.sync = true
|
59
|
+
handle_extra_config
|
60
|
+
validate_required_params(@required_options, config)
|
61
|
+
|
62
|
+
target_groups_api = Ionoscloud::TargetGroupsApi.new(api_client)
|
63
|
+
|
64
|
+
target_group = target_groups_api.targetgroups_find_by_target_group_id(config[:target_group_id])
|
65
|
+
|
66
|
+
existing_target = target_group.properties.targets.find do |target|
|
67
|
+
target.ip == config[:ip] && target.port == Integer(config[:port])
|
68
|
+
end
|
69
|
+
|
70
|
+
if existing_target
|
71
|
+
ui.warn("Specified target already exists (#{existing_target}).")
|
72
|
+
else
|
73
|
+
target_group.properties.targets.append(
|
74
|
+
Ionoscloud::TargetGroupTarget.new(
|
75
|
+
ip: config[:ip],
|
76
|
+
port: Integer(config[:port]),
|
77
|
+
weight: Integer(config[:weight]),
|
78
|
+
health_check_enabled: !config[:health_check_disable],
|
79
|
+
maintenance_enabled: config[:maintenance_enabled],
|
80
|
+
),
|
81
|
+
)
|
82
|
+
|
83
|
+
_, _, headers = target_groups_api.targetgroups_patch_with_http_info(config[:target_group_id], target_group.properties)
|
84
|
+
print "#{ui.color('Adding the Target to the Target Group...', :magenta)}"
|
85
|
+
dot = ui.color('.', :magenta)
|
86
|
+
api_client.wait_for { print dot; is_done? get_request_id headers }
|
87
|
+
end
|
88
|
+
|
89
|
+
print_target_group(target_groups_api.targetgroups_find_by_target_group_id(config[:target_group_id]))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|