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,56 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudApplicationloadbalancerList < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud applicationloadbalancer list (options)'
|
9
|
+
|
10
|
+
option :datacenter_id,
|
11
|
+
short: '-D DATACENTER_ID',
|
12
|
+
long: '--datacenter-id DATACENTER_ID',
|
13
|
+
description: 'Name of the data center'
|
14
|
+
|
15
|
+
attr_reader :description, :required_options
|
16
|
+
|
17
|
+
def initialize(args = [])
|
18
|
+
super(args)
|
19
|
+
@description =
|
20
|
+
'Retrieve a list of Application Load Balancers within the datacenter.'
|
21
|
+
@directory = 'application-loadbalancer'
|
22
|
+
@required_options = [:datacenter_id]
|
23
|
+
end
|
24
|
+
|
25
|
+
def run
|
26
|
+
$stdout.sync = true
|
27
|
+
handle_extra_config
|
28
|
+
validate_required_params(@required_options, config)
|
29
|
+
|
30
|
+
application_load_balancers_list = [
|
31
|
+
ui.color('ID', :bold),
|
32
|
+
ui.color('Name', :bold),
|
33
|
+
ui.color('Listener LAN', :bold),
|
34
|
+
ui.color('Target LAN', :bold),
|
35
|
+
ui.color('Rules', :bold),
|
36
|
+
ui.color('IPS', :bold),
|
37
|
+
ui.color('Private IPS', :bold),
|
38
|
+
]
|
39
|
+
|
40
|
+
application_load_balancers_api = Ionoscloud::ApplicationLoadBalancersApi.new(api_client)
|
41
|
+
|
42
|
+
application_load_balancers_api.datacenters_applicationloadbalancers_get(config[:datacenter_id], { depth: 2 }).items.each do |application_load_balancer|
|
43
|
+
application_load_balancers_list << application_load_balancer.id
|
44
|
+
application_load_balancers_list << application_load_balancer.properties.name
|
45
|
+
application_load_balancers_list << application_load_balancer.properties.listener_lan
|
46
|
+
application_load_balancers_list << application_load_balancer.properties.target_lan
|
47
|
+
application_load_balancers_list << application_load_balancer.entities.forwardingrules.items.length
|
48
|
+
application_load_balancers_list << application_load_balancer.properties.ips
|
49
|
+
application_load_balancers_list << application_load_balancer.properties.lb_private_ips
|
50
|
+
end
|
51
|
+
|
52
|
+
puts ui.list(application_load_balancers_list, :uneven_columns_across, 7)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudApplicationloadbalancerRuleAdd < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud applicationloadbalancer rule add (options)'
|
9
|
+
|
10
|
+
option :datacenter_id,
|
11
|
+
short: '-D DATACENTER_ID',
|
12
|
+
long: '--datacenter-id DATACENTER_ID',
|
13
|
+
description: 'Name 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: 'A name of that Application Load Balancer forwarding rule'
|
24
|
+
|
25
|
+
option :protocol,
|
26
|
+
long: '--protocol PROTOCOL',
|
27
|
+
description: 'Protocol of the balancing',
|
28
|
+
default: 'HTTP'
|
29
|
+
|
30
|
+
option :listener_ip,
|
31
|
+
short: '-i LISTENER_IP',
|
32
|
+
long: '--ip LISTENER_IP',
|
33
|
+
description: 'Listening IP. (inbound)'
|
34
|
+
|
35
|
+
option :listener_port,
|
36
|
+
short: '-p LISTENER_PORT',
|
37
|
+
long: '--port LISTENER_PORT',
|
38
|
+
description: 'Listening port number. (inbound) (range: 1 to 65535)'
|
39
|
+
|
40
|
+
option :client_timeout,
|
41
|
+
long: '--client-timeout CLIENT_TIMEOUT',
|
42
|
+
description: 'ClientTimeout is expressed in milliseconds. This inactivity timeout applies when '\
|
43
|
+
'the client is expected to acknowledge or send data. If unset the default of 50 seconds will be used.',
|
44
|
+
default: 50
|
45
|
+
|
46
|
+
option :server_certificates,
|
47
|
+
long: '--certificates SERVER_CERTIFICATES',
|
48
|
+
description: 'Array of server certificates'
|
49
|
+
|
50
|
+
option :http_rules,
|
51
|
+
long: '--http-rules HTTP_RULES',
|
52
|
+
description: 'Array of HTTP Rules'
|
53
|
+
|
54
|
+
attr_reader :description, :required_options
|
55
|
+
|
56
|
+
def initialize(args = [])
|
57
|
+
super(args)
|
58
|
+
@description =
|
59
|
+
'Adds a Forwarding Rule to a Application Load Balancer under a data center.'
|
60
|
+
@directory = 'application-loadbalancer'
|
61
|
+
@required_options = [
|
62
|
+
:datacenter_id, :application_loadbalancer_id, :name, :listener_ip, :listener_port,
|
63
|
+
]
|
64
|
+
end
|
65
|
+
|
66
|
+
def run
|
67
|
+
$stdout.sync = true
|
68
|
+
handle_extra_config
|
69
|
+
validate_required_params(@required_options, config)
|
70
|
+
|
71
|
+
application_loadbalancers_api = Ionoscloud::ApplicationLoadBalancersApi.new(api_client)
|
72
|
+
|
73
|
+
config[:server_certificates] = config[:server_certificates].split(',') if config[:server_certificates] && config[:server_certificates].instance_of?(String)
|
74
|
+
|
75
|
+
unless config[:http_rules].nil?
|
76
|
+
config[:http_rules] = JSON[config[:http_rules]] if config[:http_rules].instance_of?(String)
|
77
|
+
|
78
|
+
config[:http_rules].map! do |target|
|
79
|
+
Ionoscloud::ApplicationLoadBalancerHttpRule.new(
|
80
|
+
name: target['name'],
|
81
|
+
type: target['type'],
|
82
|
+
target_group: target['target_group'],
|
83
|
+
drop_query: target['drop_query'],
|
84
|
+
location: target['location'],
|
85
|
+
status_code: target['status_code'],
|
86
|
+
response_message: target['response_message'],
|
87
|
+
content_type: target['content_type'],
|
88
|
+
conditions: target['conditions'].nil? ? nil : target['conditions'].map do |condition|
|
89
|
+
Ionoscloud::ApplicationLoadBalancerHttpRuleCondition.new(
|
90
|
+
type: condition['type'],
|
91
|
+
condition: condition['condition'],
|
92
|
+
negate: condition['negate'],
|
93
|
+
key: condition['key'],
|
94
|
+
value: condition['value'],
|
95
|
+
)
|
96
|
+
end,
|
97
|
+
)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
application_loadbalancer_forwarding_rule = Ionoscloud::ApplicationLoadBalancerForwardingRule.new(
|
102
|
+
properties: Ionoscloud::ApplicationLoadBalancerForwardingRuleProperties.new(
|
103
|
+
name: config[:name],
|
104
|
+
protocol: config[:protocol],
|
105
|
+
listener_ip: config[:listener_ip],
|
106
|
+
listener_port: config[:listener_port],
|
107
|
+
client_timeout: config[:client_timeout],
|
108
|
+
server_certificates: config[:server_certificates],
|
109
|
+
http_rules: config[:http_rules],
|
110
|
+
),
|
111
|
+
)
|
112
|
+
|
113
|
+
_, _, headers = application_loadbalancers_api.datacenters_applicationloadbalancers_forwardingrules_post_with_http_info(
|
114
|
+
config[:datacenter_id], config[:application_loadbalancer_id], application_loadbalancer_forwarding_rule,
|
115
|
+
)
|
116
|
+
|
117
|
+
print "#{ui.color('Adding the rule to the Application Loadbalancer...', :magenta)}"
|
118
|
+
dot = ui.color('.', :magenta)
|
119
|
+
api_client.wait_for { print dot; is_done? get_request_id headers }
|
120
|
+
|
121
|
+
print_application_loadbalancer(
|
122
|
+
application_loadbalancers_api.datacenters_applicationloadbalancers_find_by_application_load_balancer_id(
|
123
|
+
config[:datacenter_id], config[:application_loadbalancer_id], depth: 2,
|
124
|
+
),
|
125
|
+
)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudApplicationloadbalancerRuleHttpruleAdd < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud applicationloadbalancer rule httprule add (options)'
|
9
|
+
|
10
|
+
option :datacenter_id,
|
11
|
+
short: '-D DATACENTER_ID',
|
12
|
+
long: '--datacenter-id DATACENTER_ID',
|
13
|
+
description: 'Name 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 :forwarding_rule_id,
|
21
|
+
short: '-R FORWARDING_RULE_ID',
|
22
|
+
long: '--forwarding-rule FORWARDING_RULE_ID',
|
23
|
+
description: 'ID of the Application Loadbalancer Forwarding Rule'
|
24
|
+
|
25
|
+
option :name,
|
26
|
+
short: '-n NAME',
|
27
|
+
long: '--name NAME',
|
28
|
+
description: 'The name of a Application Load Balancer http rule; unique per forwarding rule'
|
29
|
+
|
30
|
+
option :type,
|
31
|
+
short: '-t TYPE',
|
32
|
+
long: '--type TYPE',
|
33
|
+
description: 'Type of the Http Rule.'
|
34
|
+
|
35
|
+
option :target_group,
|
36
|
+
long: '--target-group TARGET_GROUP_ID',
|
37
|
+
description: 'The UUID of the target group; mandatory and only valid for FORWARD action.'
|
38
|
+
|
39
|
+
option :drop_query,
|
40
|
+
short: '-q QUERY',
|
41
|
+
long: '--query QUERY',
|
42
|
+
description: 'Default is false; valid only for REDIRECT action.'
|
43
|
+
|
44
|
+
option :location,
|
45
|
+
short: '-l LOCATION',
|
46
|
+
long: '--location LOCATION',
|
47
|
+
description: 'The location for redirecting; mandatory and valid only for REDIRECT action.'
|
48
|
+
|
49
|
+
option :status_code,
|
50
|
+
long: '--code STATUS_CODE',
|
51
|
+
description: 'Valid only for action REDIRECT and STATIC; on REDIRECT action default is 301 '\
|
52
|
+
'and it can take the values 301, 302, 303, 307, 308; on STATIC action default is 503 and it can take a value between 200 and 599'
|
53
|
+
|
54
|
+
option :response_message,
|
55
|
+
short: '-m MESSAGE',
|
56
|
+
long: '--message MESSAGE',
|
57
|
+
description: 'The response message of the request; mandatory for STATIC action'
|
58
|
+
|
59
|
+
option :content_type,
|
60
|
+
long: '--content-type CONTENT_TYPE',
|
61
|
+
description: 'Valid only for action STATIC'
|
62
|
+
|
63
|
+
option :conditions,
|
64
|
+
long: '--conditions CONDITIONS',
|
65
|
+
description: 'Array of conditions for the HTTP Rule'
|
66
|
+
|
67
|
+
attr_reader :description, :required_options
|
68
|
+
|
69
|
+
def initialize(args = [])
|
70
|
+
super(args)
|
71
|
+
@description =
|
72
|
+
'Adds a Http Rule to a Application Load Balancer Forwarding Rule under a data center or updates it if one already exists.'
|
73
|
+
@directory = 'application-loadbalancer'
|
74
|
+
@required_options = [
|
75
|
+
:datacenter_id, :application_loadbalancer_id, :forwarding_rule_id, :name, :type,
|
76
|
+
]
|
77
|
+
end
|
78
|
+
|
79
|
+
def run
|
80
|
+
$stdout.sync = true
|
81
|
+
handle_extra_config
|
82
|
+
validate_required_params(@required_options, config)
|
83
|
+
|
84
|
+
application_loadbalancers_api = Ionoscloud::ApplicationLoadBalancersApi.new(api_client)
|
85
|
+
|
86
|
+
application_load_balancer_rule = application_loadbalancers_api.datacenters_applicationloadbalancers_forwardingrules_find_by_forwarding_rule_id(
|
87
|
+
config[:datacenter_id], config[:application_loadbalancer_id], config[:forwarding_rule_id],
|
88
|
+
)
|
89
|
+
|
90
|
+
existing_http_rule = application_load_balancer_rule.properties.http_rules.nil? ? nil : application_load_balancer_rule.properties.http_rules.find do
|
91
|
+
|rule|
|
92
|
+
rule.name == config[:name]
|
93
|
+
end
|
94
|
+
|
95
|
+
unless config[:conditions].nil?
|
96
|
+
config[:conditions] = JSON[config[:conditions]] if config[:conditions].instance_of?(String)
|
97
|
+
|
98
|
+
config[:conditions].map! do |condition|
|
99
|
+
Ionoscloud::ApplicationLoadBalancerHttpRuleCondition.new(
|
100
|
+
type: condition['type'],
|
101
|
+
condition: condition['condition'],
|
102
|
+
negate: condition['negate'],
|
103
|
+
key: condition['key'],
|
104
|
+
value: condition['value'],
|
105
|
+
)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
if existing_http_rule
|
110
|
+
existing_http_rule.type = config[:type] || existing_http_rule.type
|
111
|
+
existing_http_rule.target_group = config[:target_group] || existing_http_rule.target_group
|
112
|
+
existing_http_rule.drop_query = config[:drop_query] || existing_http_rule.drop_query
|
113
|
+
existing_http_rule.location = config[:location] || existing_http_rule.location
|
114
|
+
existing_http_rule.status_code = config[:status_code] || existing_http_rule.status_code
|
115
|
+
existing_http_rule.response_message = config[:response_message] || existing_http_rule.response_message
|
116
|
+
existing_http_rule.content_type = config[:content_type] || existing_http_rule.content_type
|
117
|
+
existing_http_rule.conditions = config[:conditions] || existing_http_rule.conditions
|
118
|
+
else
|
119
|
+
application_loadbalancer_forwarding_rule_httprule = Ionoscloud::ApplicationLoadBalancerHttpRule.new(
|
120
|
+
name: config[:name],
|
121
|
+
type: config[:type],
|
122
|
+
target_group: config[:target_group],
|
123
|
+
drop_query: config[:drop_query],
|
124
|
+
location: config[:location],
|
125
|
+
status_code: config[:status_code],
|
126
|
+
response_message: config[:response_message],
|
127
|
+
content_type: config[:content_type],
|
128
|
+
conditions: config[:conditions],
|
129
|
+
)
|
130
|
+
|
131
|
+
if application_load_balancer_rule.properties.http_rules.nil?
|
132
|
+
application_load_balancer_rule.properties.http_rules = [application_loadbalancer_forwarding_rule_httprule]
|
133
|
+
else
|
134
|
+
application_load_balancer_rule.properties.http_rules << application_loadbalancer_forwarding_rule_httprule
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
_, _, headers = application_loadbalancers_api.datacenters_applicationloadbalancers_forwardingrules_patch_with_http_info(
|
139
|
+
config[:datacenter_id],
|
140
|
+
config[:application_loadbalancer_id],
|
141
|
+
config[:forwarding_rule_id],
|
142
|
+
Ionoscloud::ApplicationLoadBalancerForwardingRuleProperties.new({
|
143
|
+
http_rules: application_load_balancer_rule.properties.http_rules,
|
144
|
+
}),
|
145
|
+
)
|
146
|
+
|
147
|
+
print "#{ui.color('Adding the Http Rule to the Application Loadbalancer Forwarding Rule...', :magenta)}"
|
148
|
+
dot = ui.color('.', :magenta)
|
149
|
+
api_client.wait_for { print dot; is_done? get_request_id headers }
|
150
|
+
|
151
|
+
print_application_loadbalancer(
|
152
|
+
application_loadbalancers_api.datacenters_applicationloadbalancers_find_by_application_load_balancer_id(
|
153
|
+
config[:datacenter_id], config[:application_loadbalancer_id], depth: 2,
|
154
|
+
),
|
155
|
+
)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudApplicationloadbalancerRuleHttpruleRemove < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud applicationloadbalancer rule httprule remove HTTP_RULE_NAME [HTTP_RULE_NAME] (options)'
|
9
|
+
|
10
|
+
option :datacenter_id,
|
11
|
+
short: '-D DATACENTER_ID',
|
12
|
+
long: '--datacenter-id DATACENTER_ID',
|
13
|
+
description: 'Name 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 :forwarding_rule_id,
|
21
|
+
short: '-R FORWARDING_RULE_ID',
|
22
|
+
long: '--forwarding-rule FORWARDING_RULE_ID',
|
23
|
+
description: 'ID of the Application Loadbalancer Forwarding Rule'
|
24
|
+
|
25
|
+
attr_reader :description, :required_options
|
26
|
+
|
27
|
+
def initialize(args = [])
|
28
|
+
super(args)
|
29
|
+
@description =
|
30
|
+
'Removes a Http Rule from a Application Load Balancer Forwarding Rule.'
|
31
|
+
@directory = 'application-loadbalancer'
|
32
|
+
@required_options = [
|
33
|
+
:datacenter_id, :application_loadbalancer_id, :forwarding_rule_id,
|
34
|
+
]
|
35
|
+
end
|
36
|
+
|
37
|
+
def run
|
38
|
+
$stdout.sync = true
|
39
|
+
handle_extra_config
|
40
|
+
validate_required_params(@required_options, config)
|
41
|
+
|
42
|
+
application_loadbalancers_api = Ionoscloud::ApplicationLoadBalancersApi.new(api_client)
|
43
|
+
|
44
|
+
application_load_balancer_rule = application_loadbalancers_api.datacenters_applicationloadbalancers_forwardingrules_find_by_forwarding_rule_id(
|
45
|
+
config[:datacenter_id], config[:application_loadbalancer_id], config[:forwarding_rule_id],
|
46
|
+
)
|
47
|
+
|
48
|
+
if application_load_balancer_rule.properties.http_rules.nil?
|
49
|
+
ui.warn("The Forwarding Rule #{config[:forwarding_rule_id]} has no Http Rules.")
|
50
|
+
else
|
51
|
+
|
52
|
+
existing_http_rules_names = application_load_balancer_rule.properties.http_rules.map { |rule| rule.name }
|
53
|
+
|
54
|
+
valid_names = @name_args.select do |http_rule_name|
|
55
|
+
existing_http_rules_names.include? http_rule_name
|
56
|
+
end
|
57
|
+
|
58
|
+
if valid_names.empty?
|
59
|
+
ui.warn('No name of an existing Http Rule was given.')
|
60
|
+
else
|
61
|
+
application_load_balancer_rule.properties.http_rules = application_load_balancer_rule.properties.http_rules.reject do
|
62
|
+
|rule|
|
63
|
+
valid_names.include? rule.name
|
64
|
+
end
|
65
|
+
|
66
|
+
_, _, headers = application_loadbalancers_api.datacenters_applicationloadbalancers_forwardingrules_patch_with_http_info(
|
67
|
+
config[:datacenter_id],
|
68
|
+
config[:application_loadbalancer_id],
|
69
|
+
config[:forwarding_rule_id],
|
70
|
+
Ionoscloud::ApplicationLoadBalancerForwardingRuleProperties.new({
|
71
|
+
http_rules: application_load_balancer_rule.properties.http_rules,
|
72
|
+
}),
|
73
|
+
)
|
74
|
+
|
75
|
+
print "#{ui.color("Removing the Http Rules #{valid_names} from the Application Loadbalancer Forwarding Rule...", :magenta)}"
|
76
|
+
dot = ui.color('.', :magenta)
|
77
|
+
api_client.wait_for { print dot; is_done? get_request_id headers }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
print_application_loadbalancer(
|
82
|
+
application_loadbalancers_api.datacenters_applicationloadbalancers_find_by_application_load_balancer_id(
|
83
|
+
config[:datacenter_id], config[:application_loadbalancer_id], depth: 2,
|
84
|
+
),
|
85
|
+
)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudApplicationloadbalancerRuleRemove < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud applicationloadbalancer rule remove RULE_ID [RULE_ID] (options)'
|
9
|
+
|
10
|
+
option :datacenter_id,
|
11
|
+
short: '-D DATACENTER_ID',
|
12
|
+
long: '--datacenter-id DATACENTER_ID',
|
13
|
+
description: 'The 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
|
+
attr_reader :description, :required_options
|
21
|
+
|
22
|
+
def initialize(args = [])
|
23
|
+
super(args)
|
24
|
+
@description =
|
25
|
+
'Removes the specified rules from a Application Loadbalancer under a data center.'
|
26
|
+
@directory = 'application-loadbalancer'
|
27
|
+
@required_options = [:datacenter_id, :application_loadbalancer_id]
|
28
|
+
end
|
29
|
+
|
30
|
+
def run
|
31
|
+
$stdout.sync = true
|
32
|
+
handle_extra_config
|
33
|
+
validate_required_params(@required_options, config)
|
34
|
+
|
35
|
+
return unless @name_args.length > 0
|
36
|
+
|
37
|
+
application_loadbalancers_api = Ionoscloud::ApplicationLoadBalancersApi.new(api_client)
|
38
|
+
|
39
|
+
headers_to_wait = []
|
40
|
+
removed_rules = []
|
41
|
+
@name_args.each do |rule_id|
|
42
|
+
begin
|
43
|
+
_, _, headers = application_loadbalancers_api.datacenters_applicationloadbalancers_forwardingrules_delete_with_http_info(
|
44
|
+
config[:datacenter_id], config[:application_loadbalancer_id], rule_id,
|
45
|
+
)
|
46
|
+
headers_to_wait << headers
|
47
|
+
removed_rules << rule_id
|
48
|
+
rescue
|
49
|
+
ui.warn("Error removing Forwarding Rule #{rule_id}. Skipping.")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
if removed_rules.empty?
|
54
|
+
ui.warn('No valid rules to remove.')
|
55
|
+
else
|
56
|
+
print "#{ui.color("Removing rules #{removed_rules} from the Application Loadbalancer...", :magenta)}"
|
57
|
+
dot = ui.color('.', :magenta)
|
58
|
+
|
59
|
+
headers_to_wait.each { |headers| api_client.wait_for { print dot; is_done? get_request_id headers } }
|
60
|
+
end
|
61
|
+
|
62
|
+
print_application_loadbalancer(
|
63
|
+
application_loadbalancers_api.datacenters_applicationloadbalancers_find_by_application_load_balancer_id(
|
64
|
+
config[:datacenter_id], config[:application_loadbalancer_id], depth: 2,
|
65
|
+
),
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require_relative 'ionoscloud_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class IonoscloudApplicationloadbalancerRuleUpdate < Knife
|
6
|
+
include Knife::IonoscloudBase
|
7
|
+
|
8
|
+
banner 'knife ionoscloud applicationloadbalancer rule 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 :forwarding_rule_id,
|
21
|
+
short: '-R FORWARDING_RULE_ID',
|
22
|
+
long: '--forwarding-rule FORWARDING_RULE_ID',
|
23
|
+
description: 'ID of the Application Loadbalancer Forwarding Rule'
|
24
|
+
|
25
|
+
option :name,
|
26
|
+
short: '-n NAME',
|
27
|
+
long: '--name NAME',
|
28
|
+
description: 'A name of that Application Load Balancer forwarding rule'
|
29
|
+
|
30
|
+
option :protocol,
|
31
|
+
long: '--protocol PROTOCOL',
|
32
|
+
description: 'Protocol of the balancing',
|
33
|
+
default: 'HTTP'
|
34
|
+
|
35
|
+
option :listener_ip,
|
36
|
+
short: '-i LISTENER_IP',
|
37
|
+
long: '--ip LISTENER_IP',
|
38
|
+
description: 'Listening IP. (inbound)'
|
39
|
+
|
40
|
+
option :listener_port,
|
41
|
+
short: '-p LISTENER_PORT',
|
42
|
+
long: '--port LISTENER_PORT',
|
43
|
+
description: 'Listening port number. (inbound) (range: 1 to 65535)'
|
44
|
+
|
45
|
+
option :client_timeout,
|
46
|
+
long: '--client-timeout CLIENT_TIMEOUT',
|
47
|
+
description: 'ClientTimeout is expressed in milliseconds. This inactivity timeout applies when '\
|
48
|
+
'the client is expected to acknowledge or send data. If unset the default of 50 seconds will be used.',
|
49
|
+
default: 50
|
50
|
+
|
51
|
+
option :server_certificates,
|
52
|
+
long: '--certificates SERVER_CERTIFICATES',
|
53
|
+
description: 'Array of server certificates'
|
54
|
+
|
55
|
+
option :http_rules,
|
56
|
+
long: '--http-rules HTTP_RULES',
|
57
|
+
description: 'Array of HTTP Rules'
|
58
|
+
|
59
|
+
attr_reader :description, :required_options
|
60
|
+
|
61
|
+
def initialize(args = [])
|
62
|
+
super(args)
|
63
|
+
@description =
|
64
|
+
'Updates information about a Ionoscloud Application LoadBalancer Forwarding Rule.'
|
65
|
+
@directory = 'application-loadbalancer'
|
66
|
+
@required_options = [:datacenter_id, :application_loadbalancer_id, :forwarding_rule_id]
|
67
|
+
@updatable_fields = [:name, :protocol, :listener_ip, :listener_port, :client_timeout, :server_certificates, :http_rules]
|
68
|
+
end
|
69
|
+
|
70
|
+
def run
|
71
|
+
$stdout.sync = true
|
72
|
+
handle_extra_config
|
73
|
+
validate_required_params(@required_options, config)
|
74
|
+
|
75
|
+
application_load_balancers_api = Ionoscloud::ApplicationLoadBalancersApi.new(api_client)
|
76
|
+
|
77
|
+
if @updatable_fields.map { |el| config[el] }.any?
|
78
|
+
print "#{ui.color('Updating Application LoadBalancer Forwarding Rule...', :magenta)}"
|
79
|
+
|
80
|
+
config[:server_certificates] = config[:server_certificates].split(',') if config[:server_certificates] && config[:server_certificates].instance_of?(String)
|
81
|
+
|
82
|
+
unless config[:http_rules].nil?
|
83
|
+
config[:http_rules] = JSON[config[:http_rules]] if config[:http_rules].instance_of?(String)
|
84
|
+
|
85
|
+
config[:http_rules].map! do |target|
|
86
|
+
Ionoscloud::ApplicationLoadBalancerHttpRule.new(
|
87
|
+
name: target['name'],
|
88
|
+
type: target['type'],
|
89
|
+
target_group: target['target_group'],
|
90
|
+
drop_query: target['drop_query'],
|
91
|
+
location: target['location'],
|
92
|
+
status_code: target['status_code'],
|
93
|
+
response_message: target['response_message'],
|
94
|
+
content_type: target['content_type'],
|
95
|
+
conditions: target['conditions'].nil? ? nil : target['conditions'].map do |condition|
|
96
|
+
Ionoscloud::ApplicationLoadBalancerHttpRuleCondition.new(
|
97
|
+
type: condition['type'],
|
98
|
+
condition: condition['condition'],
|
99
|
+
negate: condition['negate'],
|
100
|
+
key: condition['key'],
|
101
|
+
value: condition['value'],
|
102
|
+
)
|
103
|
+
end,
|
104
|
+
)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
_, _, headers = application_load_balancers_api.datacenters_applicationloadbalancers_forwardingrules_patch_with_http_info(
|
109
|
+
config[:datacenter_id],
|
110
|
+
config[:application_loadbalancer_id],
|
111
|
+
config[:forwarding_rule_id],
|
112
|
+
Ionoscloud::ApplicationLoadBalancerForwardingRuleProperties.new(
|
113
|
+
name: config[:name],
|
114
|
+
protocol: config[:protocol],
|
115
|
+
listener_ip: config[:listener_ip],
|
116
|
+
listener_port: config[:listener_port],
|
117
|
+
client_timeout: config[:client_timeout],
|
118
|
+
server_certificates: config[:server_certificates],
|
119
|
+
http_rules: config[:http_rules],
|
120
|
+
),
|
121
|
+
)
|
122
|
+
|
123
|
+
dot = ui.color('.', :magenta)
|
124
|
+
api_client.wait_for { print dot; is_done? get_request_id headers }
|
125
|
+
else
|
126
|
+
ui.warn("Nothing to update, please set one of the attributes #{@updatable_fields}.")
|
127
|
+
end
|
128
|
+
|
129
|
+
print_application_loadbalancer(
|
130
|
+
application_load_balancers_api.datacenters_applicationloadbalancers_find_by_application_load_balancer_id(
|
131
|
+
config[:datacenter_id], config[:application_loadbalancer_id], depth: 2,
|
132
|
+
),
|
133
|
+
)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|