morpheus-cli 2.10.0 → 2.10.1
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/bin/morpheus +27 -32
- data/lib/morpheus/api/accounts_interface.rb +36 -47
- data/lib/morpheus/api/api_client.rb +141 -110
- data/lib/morpheus/api/app_templates_interface.rb +56 -72
- data/lib/morpheus/api/apps_interface.rb +111 -132
- data/lib/morpheus/api/auth_interface.rb +30 -0
- data/lib/morpheus/api/clouds_interface.rb +71 -76
- data/lib/morpheus/api/custom_instance_types_interface.rb +21 -46
- data/lib/morpheus/api/dashboard_interface.rb +10 -17
- data/lib/morpheus/api/deploy_interface.rb +60 -72
- data/lib/morpheus/api/deployments_interface.rb +53 -71
- data/lib/morpheus/api/groups_interface.rb +55 -45
- data/lib/morpheus/api/instance_types_interface.rb +19 -23
- data/lib/morpheus/api/instances_interface.rb +179 -177
- data/lib/morpheus/api/key_pairs_interface.rb +11 -17
- data/lib/morpheus/api/license_interface.rb +18 -23
- data/lib/morpheus/api/load_balancers_interface.rb +54 -69
- data/lib/morpheus/api/logs_interface.rb +25 -29
- data/lib/morpheus/api/options_interface.rb +13 -17
- data/lib/morpheus/api/provision_types_interface.rb +19 -22
- data/lib/morpheus/api/roles_interface.rb +75 -94
- data/lib/morpheus/api/security_group_rules_interface.rb +28 -37
- data/lib/morpheus/api/security_groups_interface.rb +39 -51
- data/lib/morpheus/api/servers_interface.rb +113 -115
- data/lib/morpheus/api/setup_interface.rb +31 -0
- data/lib/morpheus/api/task_sets_interface.rb +36 -38
- data/lib/morpheus/api/tasks_interface.rb +56 -69
- data/lib/morpheus/api/users_interface.rb +67 -76
- data/lib/morpheus/api/virtual_images_interface.rb +61 -61
- data/lib/morpheus/api/whoami_interface.rb +12 -15
- data/lib/morpheus/cli.rb +71 -60
- data/lib/morpheus/cli/accounts.rb +254 -315
- data/lib/morpheus/cli/alias_command.rb +219 -0
- data/lib/morpheus/cli/app_templates.rb +264 -272
- data/lib/morpheus/cli/apps.rb +608 -671
- data/lib/morpheus/cli/cli_command.rb +259 -21
- data/lib/morpheus/cli/cli_registry.rb +99 -14
- data/lib/morpheus/cli/clouds.rb +599 -372
- data/lib/morpheus/cli/config_file.rb +126 -0
- data/lib/morpheus/cli/credentials.rb +141 -117
- data/lib/morpheus/cli/dashboard_command.rb +48 -56
- data/lib/morpheus/cli/deployments.rb +254 -268
- data/lib/morpheus/cli/deploys.rb +150 -142
- data/lib/morpheus/cli/error_handler.rb +38 -0
- data/lib/morpheus/cli/groups.rb +551 -179
- data/lib/morpheus/cli/hosts.rb +862 -617
- data/lib/morpheus/cli/instance_types.rb +103 -95
- data/lib/morpheus/cli/instances.rb +1335 -1009
- data/lib/morpheus/cli/key_pairs.rb +82 -90
- data/lib/morpheus/cli/library.rb +498 -499
- data/lib/morpheus/cli/license.rb +83 -101
- data/lib/morpheus/cli/load_balancers.rb +314 -300
- data/lib/morpheus/cli/login.rb +66 -44
- data/lib/morpheus/cli/logout.rb +47 -46
- data/lib/morpheus/cli/mixins/accounts_helper.rb +69 -31
- data/lib/morpheus/cli/mixins/infrastructure_helper.rb +106 -0
- data/lib/morpheus/cli/mixins/print_helper.rb +181 -17
- data/lib/morpheus/cli/mixins/provisioning_helper.rb +535 -458
- data/lib/morpheus/cli/mixins/whoami_helper.rb +2 -2
- data/lib/morpheus/cli/option_parser.rb +35 -0
- data/lib/morpheus/cli/option_types.rb +232 -192
- data/lib/morpheus/cli/recent_activity_command.rb +61 -65
- data/lib/morpheus/cli/remote.rb +446 -199
- data/lib/morpheus/cli/roles.rb +884 -906
- data/lib/morpheus/cli/security_group_rules.rb +213 -203
- data/lib/morpheus/cli/security_groups.rb +237 -192
- data/lib/morpheus/cli/shell.rb +338 -231
- data/lib/morpheus/cli/tasks.rb +326 -308
- data/lib/morpheus/cli/users.rb +457 -462
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/version_command.rb +16 -18
- data/lib/morpheus/cli/virtual_images.rb +526 -345
- data/lib/morpheus/cli/whoami.rb +125 -111
- data/lib/morpheus/cli/workflows.rb +338 -185
- data/lib/morpheus/formatters.rb +8 -1
- data/lib/morpheus/logging.rb +1 -1
- data/lib/morpheus/rest_client.rb +17 -8
- metadata +9 -3
- data/lib/morpheus/api/custom_instance_types.rb +0 -55
@@ -9,210 +9,220 @@ require 'morpheus/cli/cli_command'
|
|
9
9
|
class Morpheus::Cli::SecurityGroupRules
|
10
10
|
include Morpheus::Cli::CliCommand
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
when 'list'
|
32
|
-
list(args[1..-1])
|
33
|
-
when 'add_custom_rule'
|
34
|
-
add_custom_rule(args[1..-1])
|
35
|
-
when 'add_instance_rule'
|
36
|
-
add_instance_rule(args[1..-1])
|
37
|
-
when 'remove'
|
38
|
-
remove(args[1..-1])
|
39
|
-
else
|
40
|
-
puts "\nUsage: morpheus security-group-rules [list,add_custom_rule,remove]\n\n"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def add_custom_rule(args)
|
45
|
-
usage = <<-EOT
|
46
|
-
Usage: morpheus security-group-rules add_custom_rule SOURCE_CIDR PORT_RANGE PROTOCOL [options]
|
47
|
-
SOURCE_CIDR: CIDR to white-list
|
48
|
-
PORT_RANGE: Port value (i.e. 123) or port range (i.e. 1-65535)
|
49
|
-
PROTOCOL: tcp, udp, icmp\n\n'
|
12
|
+
register_subcommands :list, :'add-custom-rule', :'add-instance-rule', :remove
|
13
|
+
set_default_subcommand :list
|
14
|
+
|
15
|
+
def connect(opts)
|
16
|
+
@api_client = establish_remote_appliance_connection(opts)
|
17
|
+
@security_group_rules_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).security_group_rules
|
18
|
+
@active_security_group = ::Morpheus::Cli::SecurityGroups.load_security_group_file
|
19
|
+
end
|
20
|
+
|
21
|
+
def handle(args)
|
22
|
+
handle_subcommand(args)
|
23
|
+
end
|
24
|
+
|
25
|
+
def add_custom_rule(args)
|
26
|
+
usage = <<-EOT
|
27
|
+
Usage: morpheus #{command_name} add-custom-rule SOURCE_CIDR PORT_RANGE PROTOCOL [options]
|
28
|
+
\tSOURCE_CIDR: CIDR to white-list
|
29
|
+
\tPORT_RANGE: Port value (i.e. 123) or port range (i.e. 1-65535)
|
30
|
+
\tPROTOCOL: tcp, udp, icmp
|
50
31
|
EOT
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
32
|
+
options = {}
|
33
|
+
security_group_id = nil
|
34
|
+
optparse = OptionParser.new do|opts|
|
35
|
+
opts.banner = usage
|
36
|
+
opts.on( '-s', '--secgroup SECGROUP', "Security Group ID (Use will use security as set with 'security-groups use id'" ) do |id|
|
37
|
+
security_group_id = id
|
38
|
+
end
|
39
|
+
build_common_options(opts, options, [:json, :dry_run])
|
40
|
+
end
|
41
|
+
optparse.parse!(args)
|
42
|
+
|
43
|
+
if args.count < 3
|
44
|
+
puts optparse.banner
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
|
48
|
+
if security_group_id.nil? && @active_security_group
|
49
|
+
security_group_id = @active_security_group[@appliance_name.to_sym]
|
50
|
+
end
|
51
|
+
|
52
|
+
if security_group_id.nil?
|
53
|
+
puts "Security Group ID must be specified with options or set using 'security-groups use id'"
|
54
|
+
exit 1
|
55
|
+
end
|
56
|
+
|
57
|
+
params = {
|
58
|
+
:rule => {
|
59
|
+
:source => args[0],
|
60
|
+
:portRange => args[1],
|
61
|
+
:protocol => args[2],
|
62
|
+
:customRule => true
|
63
|
+
}
|
64
|
+
}
|
65
|
+
connect(options)
|
66
|
+
begin
|
67
|
+
if options[:dry_run]
|
68
|
+
print_dry_run @security_group_rules_interface.dry.create(security_group_id, params)
|
69
|
+
return
|
70
|
+
end
|
71
|
+
json_response = @security_group_rules_interface.create(security_group_id, params)
|
72
|
+
if options[:json]
|
73
|
+
print JSON.pretty_generate(json_response)
|
74
|
+
print "\n"
|
75
|
+
return
|
76
|
+
end
|
77
|
+
list([security_group_id])
|
78
|
+
rescue RestClient::Exception => e
|
79
|
+
print_rest_exception(e, options)
|
80
|
+
exit 1
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def add_instance_rule(args)
|
85
|
+
usage = <<-EOT
|
86
|
+
Usage: morpheus #{command_name} add_instance_rule SOURCE_CIDR INSTANCE_TYPE_ID [options]
|
87
|
+
\tSOURCE_CIDR: CIDR to white-list
|
88
|
+
\tINSTANCE_TYPE_ID: ID of the Instance Type to access
|
99
89
|
EOT
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
90
|
+
|
91
|
+
options = {}
|
92
|
+
security_group_id = nil
|
93
|
+
optparse = OptionParser.new do|opts|
|
94
|
+
opts.banner = usage
|
95
|
+
opts.on( '-s', '--secgroup secgroup', "Security Group ID (Use will use security as set with 'security-groups use id'" ) do |id|
|
96
|
+
security_group_id = id
|
97
|
+
end
|
98
|
+
build_common_options(opts, options, [:json, :dry_run])
|
99
|
+
end
|
100
|
+
optparse.parse!(args)
|
101
|
+
if args.count < 2
|
102
|
+
puts optparse.banner
|
103
|
+
exit 1
|
104
|
+
end
|
105
|
+
if security_group_id.nil? && @active_security_group
|
106
|
+
security_group_id = @active_security_group[@appliance_name.to_sym]
|
107
|
+
end
|
108
|
+
|
109
|
+
if security_group_id.nil?
|
110
|
+
puts "Security Group ID must be specified with options or set using 'security-groups use id'"
|
111
|
+
exit
|
112
|
+
end
|
113
|
+
|
114
|
+
params = {
|
115
|
+
:rule => {
|
116
|
+
:source => args[0],
|
117
|
+
:instanceTypeId => args[1]
|
118
|
+
}
|
119
|
+
}
|
120
|
+
connect(options)
|
121
|
+
begin
|
122
|
+
if options[:dry_run]
|
123
|
+
print_dry_run @security_group_rules_interface.dry.create(security_group_id, params)
|
124
|
+
return
|
125
|
+
end
|
126
|
+
json_response = @security_group_rules_interface.create(security_group_id, params)
|
127
|
+
if options[:json]
|
128
|
+
print JSON.pretty_generate(json_response)
|
129
|
+
print "\n"
|
130
|
+
return
|
131
|
+
end
|
132
|
+
list([security_group_id])
|
133
|
+
rescue RestClient::Exception => e
|
134
|
+
print_rest_exception(e, options)
|
135
|
+
exit 1
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def list(args)
|
140
|
+
options = {}
|
141
|
+
security_group_id = nil
|
142
|
+
optparse = OptionParser.new do|opts|
|
143
|
+
opts.banner = subcommand_usage("[id]")
|
144
|
+
build_common_options(opts, options, [:json, :dry_run])
|
145
|
+
end
|
146
|
+
optparse.parse!(args)
|
147
|
+
security_group_id = args[0]
|
148
|
+
if security_group_id.nil? && @active_security_group
|
149
|
+
security_group_id = @active_security_group[@appliance_name.to_sym]
|
150
|
+
end
|
151
|
+
|
152
|
+
if security_group_id.nil?
|
153
|
+
puts "Security Group ID must be specified with options or set using 'security-groups use id'"
|
154
|
+
exit 1
|
155
|
+
end
|
156
|
+
connect(options)
|
157
|
+
begin
|
158
|
+
params = {}
|
159
|
+
if options[:dry_run]
|
160
|
+
print_dry_run @security_group_rules_interface.dry.get(security_group_id, params)
|
161
|
+
return
|
162
|
+
end
|
163
|
+
json_response = @security_group_rules_interface.get(security_group_id, params)
|
164
|
+
if options[:json]
|
165
|
+
print JSON.pretty_generate(json_response)
|
166
|
+
print "\n"
|
167
|
+
return
|
168
|
+
end
|
169
|
+
rules = json_response['rules']
|
170
|
+
print "\n" ,cyan, bold, "Morpheus Security Group Rules for Security Group ID:#{security_group_id}\n","==================", reset, "\n\n"
|
171
|
+
if rules.empty?
|
172
|
+
puts yellow,"No Security Group Rules currently configured.",reset
|
173
|
+
else
|
174
|
+
rules = rules.sort {|x,y| x["id"] <=> y["id"] }
|
175
|
+
rules.each do |rule|
|
176
|
+
print cyan, "= #{rule['id']} - (CIDR:#{rule['source']}, Port Range:#{rule['portRange']}, Protocol:#{rule['protocol']}, Custom Rule:#{rule['customRule']}, Instance Type:#{rule['instanceTypeId']})\n"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
print reset,"\n"
|
180
|
+
rescue RestClient::Exception => e
|
181
|
+
print_rest_exception(e, options)
|
182
|
+
exit 1
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def remove(args)
|
187
|
+
options = {}
|
188
|
+
security_group_id = nil
|
189
|
+
optparse = OptionParser.new do|opts|
|
190
|
+
opts.banner = subcommand_usage("[id] [options]")
|
191
|
+
opts.on( '-s', '--secgroup secgroup', "Security Group ID (Use will use security as set with 'security-groups use id'" ) do |id|
|
192
|
+
security_group_id = id
|
193
|
+
end
|
194
|
+
build_common_options(opts, options, [:json, :dry_run])
|
195
|
+
end
|
196
|
+
optparse.parse!(args)
|
197
|
+
if args.count < 1
|
198
|
+
puts optparse
|
199
|
+
exit 1
|
200
|
+
end
|
201
|
+
if security_group_id.nil? && @active_security_group
|
202
|
+
security_group_id = @active_security_group[@appliance_name.to_sym]
|
203
|
+
end
|
204
|
+
|
205
|
+
if security_group_id.nil?
|
206
|
+
puts "Security Group ID must be specified with options or set using 'security-groups use id'"
|
207
|
+
exit
|
208
|
+
end
|
209
|
+
connect(options)
|
210
|
+
begin
|
211
|
+
if options[:dry_run]
|
212
|
+
print_dry_run @security_group_rules_interface.dry.delete(security_group_id, args[0])
|
213
|
+
return
|
214
|
+
end
|
215
|
+
json_response = @security_group_rules_interface.delete(security_group_id, args[0])
|
216
|
+
if options[:json]
|
217
|
+
print JSON.pretty_generate(json_response)
|
218
|
+
print "\n"
|
219
|
+
return
|
220
|
+
end
|
221
|
+
list([security_group_id])
|
222
|
+
rescue RestClient::Exception => e
|
223
|
+
print_rest_exception(e, options)
|
224
|
+
exit 1
|
225
|
+
end
|
226
|
+
end
|
217
227
|
|
218
228
|
end
|
@@ -9,197 +9,242 @@ require 'morpheus/cli/cli_command'
|
|
9
9
|
class Morpheus::Cli::SecurityGroups
|
10
10
|
include Morpheus::Cli::CliCommand
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
12
|
+
register_subcommands :list, :get, :add, :remove, :use, :unuse
|
13
|
+
set_default_subcommand :list
|
14
|
+
|
15
|
+
def connect(opts)
|
16
|
+
@api_client = establish_remote_appliance_connection(opts)
|
17
|
+
@security_groups_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).security_groups
|
18
|
+
@active_security_group = ::Morpheus::Cli::SecurityGroups.load_security_group_file
|
19
|
+
end
|
20
|
+
|
21
|
+
def handle(args)
|
22
|
+
handle_subcommand(args)
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def list(args)
|
27
|
+
options = {}
|
28
|
+
optparse = OptionParser.new do|opts|
|
29
|
+
opts.banner = subcommand_usage()
|
30
|
+
build_common_options(opts, options, [:json, :dry_run])
|
31
|
+
end
|
32
|
+
optparse.parse!(args)
|
33
|
+
connect(options)
|
34
|
+
begin
|
35
|
+
params = {}
|
36
|
+
if options[:dry_run]
|
37
|
+
print_dry_run @security_groups_interface.dry.list(params)
|
38
|
+
return
|
39
|
+
end
|
40
|
+
json_response = @security_groups_interface.list(params)
|
41
|
+
if options[:json]
|
42
|
+
print JSON.pretty_generate(json_response)
|
43
|
+
print "\n"
|
44
|
+
return
|
45
|
+
end
|
46
|
+
security_groups = json_response['securityGroups']
|
47
|
+
print "\n" ,cyan, bold, "Morpheus Security Groups\n","==================", reset, "\n\n"
|
48
|
+
if security_groups.empty?
|
49
|
+
puts yellow,"No Security Groups currently configured.",reset
|
50
|
+
else
|
51
|
+
active_id = @active_security_group[@appliance_name.to_sym]
|
52
|
+
security_groups.each do |security_group|
|
53
|
+
if @active_security_group[@appliance_name.to_sym] == security_group['id']
|
54
|
+
print cyan, "=> #{security_group['id']}: #{security_group['name']} (#{security_group['description']})\n"
|
55
|
+
else
|
56
|
+
print cyan, " #{security_group['id']}: #{security_group['name']} (#{security_group['description']})\n"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
if active_id
|
60
|
+
print cyan, "\n\n# => - current", reset
|
61
|
+
end
|
62
|
+
end
|
63
|
+
print reset,"\n"
|
64
|
+
rescue RestClient::Exception => e
|
65
|
+
print_rest_exception(e, options)
|
66
|
+
exit 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def get(args)
|
71
|
+
options = {}
|
72
|
+
optparse = OptionParser.new do|opts|
|
73
|
+
opts.banner = subcommand_usage("[id]")
|
74
|
+
build_common_options(opts, options, [:json, :dry_run])
|
75
|
+
end
|
76
|
+
optparse.parse!(args)
|
77
|
+
if args.count < 1
|
78
|
+
puts optparse
|
79
|
+
exit 1
|
80
|
+
end
|
81
|
+
connect(options)
|
82
|
+
begin
|
83
|
+
if options[:dry_run]
|
84
|
+
print_dry_run @security_groups_interface.dry.get({id: args[0]})
|
85
|
+
return
|
86
|
+
end
|
87
|
+
json_response = @security_groups_interface.get({id: args[0]})
|
88
|
+
if options[:json]
|
89
|
+
print JSON.pretty_generate(json_response)
|
90
|
+
print "\n"
|
91
|
+
return
|
92
|
+
end
|
93
|
+
security_group = json_response['securityGroup']
|
94
|
+
print "\n" ,cyan, bold, "Morpheus Security Group\n","==================", reset, "\n\n"
|
95
|
+
if security_group.nil?
|
96
|
+
puts yellow,"Security Group not found by id #{args[0]}",reset
|
97
|
+
else
|
98
|
+
print cyan, "= #{security_group['id']}: #{security_group['name']} (#{security_group['description']})\n"
|
99
|
+
end
|
100
|
+
print reset,"\n\n"
|
101
|
+
rescue RestClient::Exception => e
|
102
|
+
print_rest_exception(e, options)
|
103
|
+
exit 1
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def add(args)
|
108
|
+
params = {:securityGroup => {}}
|
109
|
+
options = {}
|
110
|
+
optparse = OptionParser.new do|opts|
|
111
|
+
opts.banner = subcommand_usage("[name] [options]")
|
112
|
+
opts.on( '-d', '--description Description', "Description of the security group" ) do |description|
|
113
|
+
params[:securityGroup][:description] = description
|
114
|
+
end
|
115
|
+
build_common_options(opts, options, [:json, :dry_run])
|
116
|
+
end
|
117
|
+
optparse.parse!(args)
|
118
|
+
if args.count < 1
|
119
|
+
puts optparse
|
120
|
+
exit 1
|
121
|
+
end
|
122
|
+
params[:securityGroup][:name] = args[0]
|
123
|
+
connect(options)
|
124
|
+
begin
|
125
|
+
if options[:dry_run]
|
126
|
+
print_dry_run @security_groups_interface.dry.create(params)
|
127
|
+
return
|
128
|
+
end
|
129
|
+
json_response = @security_groups_interface.create(params)
|
130
|
+
if options[:json]
|
131
|
+
print JSON.pretty_generate(json_response)
|
132
|
+
print "\n"
|
133
|
+
return
|
134
|
+
end
|
135
|
+
list([])
|
136
|
+
rescue RestClient::Exception => e
|
137
|
+
print_rest_exception(e, options)
|
138
|
+
exit 1
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def remove(args)
|
143
|
+
options = {}
|
144
|
+
optparse = OptionParser.new do|opts|
|
145
|
+
opts.banner = subcommand_usage("[id]")
|
146
|
+
build_common_options(opts, options, [:json, :dry_run])
|
147
|
+
end
|
148
|
+
optparse.parse!(args)
|
149
|
+
if args.count < 1
|
150
|
+
puts optparse
|
151
|
+
return
|
152
|
+
end
|
153
|
+
connect(options)
|
154
|
+
begin
|
155
|
+
json_response = @security_groups_interface.get({id: args[0]})
|
156
|
+
security_group = json_response['securityGroup']
|
157
|
+
if security_group.nil?
|
158
|
+
puts "Security Group not found by id #{args[0]}"
|
159
|
+
return
|
160
|
+
end
|
161
|
+
if options[:dry_run]
|
162
|
+
print_dry_run @security_groups_interface.dry.delete(security_group['id'])
|
163
|
+
return
|
164
|
+
end
|
165
|
+
json_response = @security_groups_interface.delete(security_group['id'])
|
166
|
+
if options[:json]
|
167
|
+
print JSON.pretty_generate(json_response)
|
168
|
+
print "\n"
|
169
|
+
return
|
170
|
+
end
|
171
|
+
list([])
|
172
|
+
rescue RestClient::Exception => e
|
173
|
+
print_rest_exception(e, options)
|
174
|
+
exit 1
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def use(args)
|
179
|
+
options = {}
|
180
|
+
optparse = OptionParser.new do|opts|
|
181
|
+
opts.banner = subcommand_usage("[id] [--none]")
|
182
|
+
opts.on('--none','--none', "Do not use an active group.") do |json|
|
183
|
+
options[:unuse] = true
|
184
|
+
end
|
185
|
+
build_common_options(opts, options, [])
|
186
|
+
end
|
187
|
+
optparse.parse!(args)
|
188
|
+
if args.length < 1 && !options[:unuse]
|
189
|
+
puts optparse
|
190
|
+
return
|
191
|
+
end
|
192
|
+
connect(options)
|
193
|
+
begin
|
194
|
+
|
195
|
+
if options[:unuse]
|
196
|
+
if @active_security_group[@appliance_name.to_sym]
|
197
|
+
@active_security_group.delete(@appliance_name.to_sym)
|
198
|
+
end
|
199
|
+
::Morpheus::Cli::SecurityGroups.save_security_group(@active_security_group)
|
200
|
+
unless options[:quiet]
|
201
|
+
print cyan
|
202
|
+
puts "Switched to no active security group."
|
203
|
+
print reset
|
204
|
+
end
|
205
|
+
print reset
|
206
|
+
return # exit 0
|
207
|
+
end
|
208
|
+
|
209
|
+
json_response = @security_groups_interface.get({id: args[0]})
|
210
|
+
security_group = json_response['securityGroup']
|
211
|
+
if !security_group.nil?
|
212
|
+
@active_security_group[@appliance_name.to_sym] = security_group['id']
|
213
|
+
::Morpheus::Cli::SecurityGroups.save_security_group(@active_security_group)
|
214
|
+
puts cyan, "Using Security Group #{args[0]}", reset
|
215
|
+
else
|
216
|
+
puts red, "Security Group not found", reset
|
217
|
+
end
|
218
|
+
rescue RestClient::Exception => e
|
219
|
+
print_rest_exception(e, options)
|
220
|
+
exit 1
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
def unuse(args)
|
225
|
+
use(args + ['--none'])
|
226
|
+
end
|
227
|
+
|
228
|
+
def self.load_security_group_file
|
229
|
+
remote_file = security_group_file_path
|
230
|
+
if File.exist? remote_file
|
231
|
+
return YAML.load_file(remote_file)
|
232
|
+
else
|
233
|
+
{}
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def self.security_group_file_path
|
238
|
+
home_dir = Dir.home
|
239
|
+
morpheus_dir = File.join(home_dir,".morpheus")
|
240
|
+
if !Dir.exist?(morpheus_dir)
|
241
|
+
Dir.mkdir(morpheus_dir)
|
242
|
+
end
|
243
|
+
return File.join(morpheus_dir,"securitygroup")
|
244
|
+
end
|
245
|
+
|
246
|
+
def self.save_security_group(security_group_map)
|
247
|
+
File.open(security_group_file_path, 'w') {|f| f.write security_group_map.to_yaml } #Store
|
248
|
+
end
|
204
249
|
|
205
250
|
end
|