morpheus-cli 0.9.7 → 0.9.8
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/lib/morpheus/api/api_client.rb +8 -0
- data/lib/morpheus/api/deployments_interface.rb +82 -0
- data/lib/morpheus/api/groups_interface.rb +1 -1
- data/lib/morpheus/api/instances_interface.rb +2 -2
- data/lib/morpheus/api/servers_interface.rb +2 -2
- data/lib/morpheus/api/virtual_images_interface.rb +72 -0
- data/lib/morpheus/cli.rb +4 -0
- data/lib/morpheus/cli/clouds.rb +15 -3
- data/lib/morpheus/cli/deployments.rb +310 -0
- data/lib/morpheus/cli/hosts.rb +11 -8
- data/lib/morpheus/cli/instances.rb +28 -5
- data/lib/morpheus/cli/load_balancers.rb +1 -1
- data/lib/morpheus/cli/option_types.rb +3 -3
- data/lib/morpheus/cli/shell.rb +1 -1
- data/lib/morpheus/cli/tasks.rb +20 -16
- data/lib/morpheus/cli/version.rb +1 -1
- data/lib/morpheus/cli/virtual_images.rb +385 -0
- data/lib/morpheus/cli/workflows.rb +109 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59b51b98aec0f39ee6d583feb37baf4a1058daf2
|
4
|
+
data.tar.gz: b7c2a2238926e9a25ef822d5308334034091aeb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d18cff80d168bfdbd1185e26b0f11e5f56396894bb5c6f5b821b00154d1a493e55a8ab62cde09b184f30a3a59b21488fa2ed21a840460355f7f2414bd43d2797
|
7
|
+
data.tar.gz: c99accbc894044146004a77728abec3af25b9a22c1bab50e27935aa64b73b9ff71e81b4b1650907742c996a7abbf962febbcaa9ed1118e19527ed1c79f20ab55
|
@@ -51,6 +51,10 @@ class Morpheus::APIClient
|
|
51
51
|
Morpheus::TaskSetsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
|
52
52
|
end
|
53
53
|
|
54
|
+
def virtual_images
|
55
|
+
Morpheus::VirtualImagesInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
|
56
|
+
end
|
57
|
+
|
54
58
|
def apps
|
55
59
|
Morpheus::AppsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
|
56
60
|
end
|
@@ -59,6 +63,10 @@ class Morpheus::APIClient
|
|
59
63
|
Morpheus::DeployInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
|
60
64
|
end
|
61
65
|
|
66
|
+
def deployments
|
67
|
+
Morpheus::DeploymentsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
|
68
|
+
end
|
69
|
+
|
62
70
|
def security_groups
|
63
71
|
Morpheus::SecurityGroupsInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
|
64
72
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'morpheus/rest_client'
|
3
|
+
|
4
|
+
class Morpheus::DeploymentsInterface < Morpheus::APIClient
|
5
|
+
def initialize(access_token, refresh_token,expires_at = nil, base_url=nil)
|
6
|
+
@access_token = access_token
|
7
|
+
@refresh_token = refresh_token
|
8
|
+
@base_url = base_url
|
9
|
+
@expires_at = expires_at
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def get(options=nil)
|
14
|
+
url = "#{@base_url}/api/deployments"
|
15
|
+
headers = { params: {}, authorization: "Bearer #{@access_token}" }
|
16
|
+
|
17
|
+
if options.is_a?(Hash)
|
18
|
+
headers[:params].merge!(options)
|
19
|
+
elsif options.is_a?(Numeric)
|
20
|
+
url = "#{@base_url}/api/deployments/#{options}"
|
21
|
+
elsif options.is_a?(String)
|
22
|
+
headers[:params]['name'] = options
|
23
|
+
end
|
24
|
+
response = Morpheus::RestClient.execute(method: :get, url: url,
|
25
|
+
timeout: 30, headers: headers, verify_ssl:false)
|
26
|
+
JSON.parse(response.to_s)
|
27
|
+
end
|
28
|
+
|
29
|
+
def list_versions(deployment_id,options=nil)
|
30
|
+
url = "#{@base_url}/api/deployments/#{deployment_id}/versions"
|
31
|
+
headers = { params: {}, authorization: "Bearer #{@access_token}" }
|
32
|
+
|
33
|
+
if options.is_a?(Hash)
|
34
|
+
headers[:params].merge!(options)
|
35
|
+
elsif options.is_a?(Numeric)
|
36
|
+
url = "#{@base_url}/api/deployments/#{deployment_id}/versions/#{options}"
|
37
|
+
elsif options.is_a?(String)
|
38
|
+
headers[:params]['name'] = options
|
39
|
+
end
|
40
|
+
response = Morpheus::RestClient.execute(method: :get, url: url,
|
41
|
+
timeout: 30, headers: headers, verify_ssl:false)
|
42
|
+
JSON.parse(response.to_s)
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_version(deployment_id,version_id)
|
46
|
+
url = "#{@base_url}/api/deployments/#{deployment_id}/versions/#{version_id}"
|
47
|
+
headers = { params: {}, authorization: "Bearer #{@access_token}" }
|
48
|
+
|
49
|
+
response = Morpheus::RestClient.execute(method: :get, url: url,
|
50
|
+
timeout: 30, headers: headers, verify_ssl:false)
|
51
|
+
JSON.parse(response.to_s)
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
def create(options)
|
56
|
+
url = "#{@base_url}/api/deployments"
|
57
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
58
|
+
|
59
|
+
payload = options
|
60
|
+
response = Morpheus::RestClient.execute(method: :post, url: url,
|
61
|
+
timeout: 30, headers: headers, verify_ssl:false, payload: payload.to_json)
|
62
|
+
JSON.parse(response.to_s)
|
63
|
+
end
|
64
|
+
|
65
|
+
def update(id, options)
|
66
|
+
url = "#{@base_url}/api/deployments/#{id}"
|
67
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
68
|
+
|
69
|
+
payload = options
|
70
|
+
response = Morpheus::RestClient.execute(method: :put, url: url,
|
71
|
+
timeout: 10, headers: headers, payload: payload.to_json)
|
72
|
+
JSON.parse(response.to_s)
|
73
|
+
end
|
74
|
+
|
75
|
+
def destroy(id)
|
76
|
+
url = "#{@base_url}/api/deployments/#{id}"
|
77
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
78
|
+
response = Morpheus::RestClient.execute(method: :delete, url: url,
|
79
|
+
timeout: 30, headers: headers, verify_ssl:false)
|
80
|
+
JSON.parse(response.to_s)
|
81
|
+
end
|
82
|
+
end
|
@@ -15,7 +15,7 @@ class Morpheus::GroupsInterface < Morpheus::APIClient
|
|
15
15
|
headers = { params: {}, authorization: "Bearer #{@access_token}" }
|
16
16
|
|
17
17
|
if options.is_a?(Hash)
|
18
|
-
headers
|
18
|
+
headers[:params].merge!(options)
|
19
19
|
elsif options.is_a?(Numeric)
|
20
20
|
url = "#{@base_url}/api/groups/#{options}"
|
21
21
|
elsif options.is_a?(String)
|
@@ -63,9 +63,9 @@ class Morpheus::InstancesInterface < Morpheus::APIClient
|
|
63
63
|
JSON.parse(response.to_s)
|
64
64
|
end
|
65
65
|
|
66
|
-
def destroy(id)
|
66
|
+
def destroy(id, params = {})
|
67
67
|
url = "#{@base_url}/api/instances/#{id}"
|
68
|
-
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
68
|
+
headers = {:params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
69
69
|
response = Morpheus::RestClient.execute(method: :delete, url: url,
|
70
70
|
timeout: 30, headers: headers,verify_ssl: false)
|
71
71
|
JSON.parse(response.to_s)
|
@@ -100,9 +100,9 @@ class Morpheus::ServersInterface < Morpheus::APIClient
|
|
100
100
|
JSON.parse(response.to_s)
|
101
101
|
end
|
102
102
|
|
103
|
-
def destroy(id)
|
103
|
+
def destroy(id, params={})
|
104
104
|
url = "#{@base_url}/api/servers/#{id}"
|
105
|
-
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
105
|
+
headers = { :params => params,:authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
106
106
|
response = Morpheus::RestClient.execute(method: :delete, url: url,
|
107
107
|
timeout: 30, headers: headers, verify_ssl:false)
|
108
108
|
JSON.parse(response.to_s)
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
class Morpheus::VirtualImagesInterface < Morpheus::APIClient
|
5
|
+
def initialize(access_token, refresh_token,expires_at = nil, base_url=nil)
|
6
|
+
@access_token = access_token
|
7
|
+
@refresh_token = refresh_token
|
8
|
+
@base_url = base_url
|
9
|
+
@expires_at = expires_at
|
10
|
+
end
|
11
|
+
|
12
|
+
def virtual_image_types(options={})
|
13
|
+
url = "#{@base_url}/api/virtual-image-types"
|
14
|
+
headers = { params: {}, authorization: "Bearer #{@access_token}" }
|
15
|
+
|
16
|
+
if options.is_a?(Hash)
|
17
|
+
headers[:params].merge!(options)
|
18
|
+
elsif options.is_a?(Numeric)
|
19
|
+
url = "#{@base_url}/api/virtual-image-types/#{options}"
|
20
|
+
elsif options.is_a?(String)
|
21
|
+
headers[:params]['name'] = options
|
22
|
+
end
|
23
|
+
response = Morpheus::RestClient.execute(method: :get, url: url,
|
24
|
+
timeout: 30, headers: headers, verify_ssl:false)
|
25
|
+
JSON.parse(response.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def get(options=nil)
|
29
|
+
url = "#{@base_url}/api/virtual-images"
|
30
|
+
headers = { params: {}, authorization: "Bearer #{@access_token}" }
|
31
|
+
|
32
|
+
if options.is_a?(Hash)
|
33
|
+
headers[:params].merge!(options)
|
34
|
+
elsif options.is_a?(Numeric)
|
35
|
+
url = "#{@base_url}/api/virtual-images/#{options}"
|
36
|
+
elsif options.is_a?(String)
|
37
|
+
headers[:params]['name'] = options
|
38
|
+
end
|
39
|
+
response = Morpheus::RestClient.execute(method: :get, url: url,
|
40
|
+
timeout: 30, headers: headers, verify_ssl:false)
|
41
|
+
JSON.parse(response.to_s)
|
42
|
+
end
|
43
|
+
|
44
|
+
def update(id, options)
|
45
|
+
url = "#{@base_url}/api/virtual-images/#{id}"
|
46
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
47
|
+
|
48
|
+
payload = options
|
49
|
+
response = Morpheus::RestClient.execute(method: :put, url: url,
|
50
|
+
timeout: 10, headers: headers, payload: payload.to_json)
|
51
|
+
JSON.parse(response.to_s)
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
def create(options)
|
56
|
+
url = "#{@base_url}/api/virtual-images"
|
57
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
58
|
+
|
59
|
+
payload = options
|
60
|
+
response = Morpheus::RestClient.execute(method: :post, url: url,
|
61
|
+
timeout: 30, headers: headers, verify_ssl:false, payload: payload.to_json)
|
62
|
+
JSON.parse(response.to_s)
|
63
|
+
end
|
64
|
+
|
65
|
+
def destroy(id)
|
66
|
+
url = "#{@base_url}/api/virtual-images/#{id}"
|
67
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
68
|
+
response = Morpheus::RestClient.execute(method: :delete, url: url,
|
69
|
+
timeout: 30, headers: headers, verify_ssl:false)
|
70
|
+
JSON.parse(response.to_s)
|
71
|
+
end
|
72
|
+
end
|
data/lib/morpheus/cli.rb
CHANGED
@@ -11,7 +11,9 @@ module Morpheus
|
|
11
11
|
require 'morpheus/api/clouds_interface'
|
12
12
|
require 'morpheus/api/servers_interface'
|
13
13
|
require 'morpheus/api/tasks_interface'
|
14
|
+
require 'morpheus/api/deployments_interface'
|
14
15
|
require 'morpheus/api/license_interface'
|
16
|
+
require 'morpheus/api/virtual_images_interface'
|
15
17
|
require 'morpheus/api/task_sets_interface'
|
16
18
|
require 'morpheus/api/load_balancers_interface'
|
17
19
|
require 'morpheus/api/instances_interface'
|
@@ -37,6 +39,7 @@ module Morpheus
|
|
37
39
|
require 'morpheus/cli/shell'
|
38
40
|
require 'morpheus/cli/tasks'
|
39
41
|
require 'morpheus/cli/workflows'
|
42
|
+
require 'morpheus/cli/deployments'
|
40
43
|
require 'morpheus/cli/instances'
|
41
44
|
require 'morpheus/cli/apps'
|
42
45
|
require 'morpheus/cli/deploys'
|
@@ -48,6 +51,7 @@ module Morpheus
|
|
48
51
|
require 'morpheus/cli/users'
|
49
52
|
require 'morpheus/cli/roles'
|
50
53
|
require 'morpheus/cli/key_pairs'
|
54
|
+
require 'morpheus/cli/virtual_images'
|
51
55
|
# Your code goes here...
|
52
56
|
end
|
53
57
|
end
|
data/lib/morpheus/cli/clouds.rb
CHANGED
@@ -189,11 +189,23 @@ class Morpheus::Cli::Clouds
|
|
189
189
|
if clouds.empty?
|
190
190
|
puts yellow,"No clouds currently configured.",reset
|
191
191
|
else
|
192
|
-
clouds.
|
193
|
-
|
192
|
+
clouds_table =clouds.collect do |cloud|
|
193
|
+
status = nil
|
194
|
+
if cloud['status'].nil? || cloud['status'] == 'ok'
|
195
|
+
status = "#{green}OK#{cyan}"
|
196
|
+
else
|
197
|
+
status = "#{red}#{cloud['status'] ? cloud['status'].upcase : 'N/A'}#{cloud['statusMessage'] ? "#{cyan} - #{cloud['statusMessage']}" : ''}#{cyan}"
|
198
|
+
end
|
199
|
+
{id: cloud['id'], name: cloud['name'], type: cloud_type_for_id(cloud['zoneTypeId']), location: cloud['location'], status: status}
|
200
|
+
# print red, "= [#{server['id']}] #{server['name']} - #{server['computeServerType'] ? server['computeServerType']['name'] : 'unmanaged'} (#{server['status']}) Power: ", power_state, "\n"
|
194
201
|
end
|
202
|
+
print cyan
|
203
|
+
tp clouds_table, :id, :name, :type, :location, :status
|
204
|
+
print reset,"\n\n"
|
195
205
|
end
|
196
|
-
|
206
|
+
|
207
|
+
|
208
|
+
|
197
209
|
end
|
198
210
|
rescue => e
|
199
211
|
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
@@ -0,0 +1,310 @@
|
|
1
|
+
# require 'yaml'
|
2
|
+
require 'io/console'
|
3
|
+
require 'rest_client'
|
4
|
+
require 'term/ansicolor'
|
5
|
+
require 'optparse'
|
6
|
+
require 'table_print'
|
7
|
+
require 'morpheus/cli/cli_command'
|
8
|
+
|
9
|
+
class Morpheus::Cli::Deployments
|
10
|
+
include Morpheus::Cli::CliCommand
|
11
|
+
include Term::ANSIColor
|
12
|
+
def initialize()
|
13
|
+
@appliance_name, @appliance_url = Morpheus::Cli::Remote.active_appliance
|
14
|
+
end
|
15
|
+
|
16
|
+
def connect(opts)
|
17
|
+
if opts[:remote]
|
18
|
+
@appliance_url = opts[:remote]
|
19
|
+
@appliance_name = opts[:remote]
|
20
|
+
@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
|
21
|
+
else
|
22
|
+
@access_token = Morpheus::Cli::Credentials.new(@appliance_name,@appliance_url).request_credentials(opts)
|
23
|
+
end
|
24
|
+
@api_client = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url)
|
25
|
+
@deployments_interface = Morpheus::APIClient.new(@access_token,nil,nil, @appliance_url).deployments
|
26
|
+
if @access_token.empty?
|
27
|
+
print red,bold, "\nInvalid Credentials. Unable to acquire access token. Please verify your credentials and try again.\n\n",reset
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def handle(args)
|
34
|
+
if args.empty?
|
35
|
+
puts "\nUsage: morpheus deployments [list,add, update,remove, versions]\n\n"
|
36
|
+
return
|
37
|
+
end
|
38
|
+
|
39
|
+
case args[0]
|
40
|
+
when 'list'
|
41
|
+
list(args[1..-1])
|
42
|
+
when 'add'
|
43
|
+
add(args[1..-1])
|
44
|
+
when 'update'
|
45
|
+
update(args[1..-1])
|
46
|
+
when 'remove'
|
47
|
+
remove(args[1..-1])
|
48
|
+
when 'versions'
|
49
|
+
list_versions(args[1..-1])
|
50
|
+
else
|
51
|
+
puts "\nUsage: morpheus deployments [list,add, update,remove, versions]\n\n"
|
52
|
+
exit 127
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def list(args)
|
57
|
+
options = {}
|
58
|
+
optparse = OptionParser.new do|opts|
|
59
|
+
opts.banner = "Usage: morpheus deployments list [-s] [-o] [-m]"
|
60
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
61
|
+
end
|
62
|
+
optparse.parse(args)
|
63
|
+
connect(options)
|
64
|
+
begin
|
65
|
+
params = {}
|
66
|
+
[:phrase, :offset, :max, :sort, :direction].each do |k|
|
67
|
+
params[k] = options[k] unless options[k].nil?
|
68
|
+
end
|
69
|
+
json_response = @deployments_interface.get(params)
|
70
|
+
if options[:json]
|
71
|
+
puts JSON.pretty_generate(json_response)
|
72
|
+
else
|
73
|
+
deployments = json_response['deployments']
|
74
|
+
print "\n" ,cyan, bold, "Morpheus Deployments\n","====================", reset, "\n\n"
|
75
|
+
if deployments.empty?
|
76
|
+
puts yellow,"No deployments currently configured.",reset
|
77
|
+
else
|
78
|
+
print cyan
|
79
|
+
deployments_table_data = deployments.collect do |deployment|
|
80
|
+
{name: deployment['name'], id: deployment['id'], description: deployment['description'], updated: format_local_dt(deployment['lastUpdated'])}
|
81
|
+
end
|
82
|
+
tp deployments_table_data, :id, :name, :description, :updated
|
83
|
+
end
|
84
|
+
print reset,"\n\n"
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
rescue RestClient::Exception => e
|
89
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
90
|
+
exit 1
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def list_versions(args)
|
95
|
+
options = {}
|
96
|
+
optparse = OptionParser.new do|opts|
|
97
|
+
opts.banner = "Usage: morpheus deployments versions [deployment] [-s] [-o] [-m]"
|
98
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
99
|
+
end
|
100
|
+
optparse.parse(args)
|
101
|
+
if args.count < 1
|
102
|
+
puts "\n#{optparse.banner}\n\n"
|
103
|
+
exit 1
|
104
|
+
end
|
105
|
+
deployment_name = args[0]
|
106
|
+
connect(options)
|
107
|
+
begin
|
108
|
+
params = {}
|
109
|
+
[:phrase, :offset, :max, :sort, :direction].each do |k|
|
110
|
+
params[k] = options[k] unless options[k].nil?
|
111
|
+
end
|
112
|
+
deployment = find_deployment_by_name_or_code_or_id(deployment_name)
|
113
|
+
exit 1 if deployment.nil?
|
114
|
+
|
115
|
+
json_response = @deployments_interface.list_versions(deployment['id'],params)
|
116
|
+
if options[:json]
|
117
|
+
puts JSON.pretty_generate(json_response)
|
118
|
+
else
|
119
|
+
versions = json_response['versions']
|
120
|
+
print "\n" ,cyan, bold, "Morpheus Deployment Versions\n","=============================", reset, "\n\n"
|
121
|
+
if versions.empty?
|
122
|
+
puts yellow,"No deployment versions currently exist.",reset
|
123
|
+
else
|
124
|
+
print cyan
|
125
|
+
versions_table_data = versions.collect do |version|
|
126
|
+
{version: version['userVersion'], type: version['deployType'], updated: format_local_dt(version['lastUpdated'])}
|
127
|
+
end
|
128
|
+
tp versions_table_data, :version, :type, :updated
|
129
|
+
end
|
130
|
+
print reset,"\n\n"
|
131
|
+
end
|
132
|
+
rescue RestClient::Exception => e
|
133
|
+
::Morpheus::Cli::ErrorHandler.new.print_rest_exception(e)
|
134
|
+
exit 1
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def update(args)
|
139
|
+
deployment_name = args[0]
|
140
|
+
options = {}
|
141
|
+
account_name = nil
|
142
|
+
optparse = OptionParser.new do|opts|
|
143
|
+
opts.banner = "Usage: morpheus deployments update [deployment] [options]"
|
144
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
145
|
+
end
|
146
|
+
if args.count < 1
|
147
|
+
puts "\n#{optparse.banner}\n\n"
|
148
|
+
exit 1
|
149
|
+
end
|
150
|
+
optparse.parse(args)
|
151
|
+
|
152
|
+
connect(options)
|
153
|
+
|
154
|
+
begin
|
155
|
+
deployment = find_deployment_by_name_or_code_or_id(deployment_name)
|
156
|
+
exit 1 if deployment.nil?
|
157
|
+
|
158
|
+
#params = Morpheus::Cli::OptionTypes.prompt(add_user_option_types, options[:options], @api_client, options[:params]) # options[:params] is mysterious
|
159
|
+
params = options[:options] || {}
|
160
|
+
|
161
|
+
if params.empty?
|
162
|
+
puts "\n#{optparse.banner}\n\n"
|
163
|
+
option_lines = update_deployment_option_types().collect {|it| "\t-O #{it['fieldContext'] ? (it['fieldContext'] + '.') : ''}#{it['fieldName']}=\"value\"" }.join("\n")
|
164
|
+
puts "\nAvailable Options:\n#{option_lines}\n\n"
|
165
|
+
exit 1
|
166
|
+
end
|
167
|
+
|
168
|
+
#puts "parsed params is : #{params.inspect}"
|
169
|
+
deployment_keys = ['name','description']
|
170
|
+
changes_payload = (params.select {|k,v| deployment_keys.include?(k) })
|
171
|
+
deployment_payload = deployment
|
172
|
+
if changes_payload
|
173
|
+
deployment_payload.merge!(changes_payload)
|
174
|
+
end
|
175
|
+
|
176
|
+
|
177
|
+
request_payload = {deployment: deployment_payload}
|
178
|
+
response = @deployments_interface.update(deployment['id'], request_payload)
|
179
|
+
if options[:json]
|
180
|
+
print JSON.pretty_generate(json_response)
|
181
|
+
if !response['success']
|
182
|
+
exit 1
|
183
|
+
end
|
184
|
+
else
|
185
|
+
print "\n", cyan, "Deployment #{response['deployment']['name']} updated", reset, "\n\n"
|
186
|
+
end
|
187
|
+
rescue RestClient::Exception => e
|
188
|
+
if e.response.code == 400
|
189
|
+
error = JSON.parse(e.response.to_s)
|
190
|
+
::Morpheus::Cli::ErrorHandler.new.print_errors(error)
|
191
|
+
else
|
192
|
+
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
193
|
+
end
|
194
|
+
exit 1
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def add(args)
|
199
|
+
deployment_name = args[0]
|
200
|
+
options = {}
|
201
|
+
optparse = OptionParser.new do|opts|
|
202
|
+
opts.banner = "Usage: morpheus deployments add [name]"
|
203
|
+
opts.on( '-d', '--description DESCRIPTION', "Description" ) do |val|
|
204
|
+
options[:description] = val
|
205
|
+
end
|
206
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
207
|
+
end
|
208
|
+
if args.count < 1
|
209
|
+
puts "\n#{optparse.banner}\n\n"
|
210
|
+
exit 1
|
211
|
+
end
|
212
|
+
optparse.parse(args)
|
213
|
+
connect(options)
|
214
|
+
|
215
|
+
begin
|
216
|
+
payload = {deployment: {name: deployment_name, description: options[:description]}}
|
217
|
+
json_response = @deployments_interface.create(payload)
|
218
|
+
if options[:json]
|
219
|
+
print JSON.pretty_generate(json_response)
|
220
|
+
else
|
221
|
+
print "\n", cyan, "Deployment #{json_response['deployment']['name']} created successfully", reset, "\n\n"
|
222
|
+
end
|
223
|
+
rescue RestClient::Exception => e
|
224
|
+
if e.response.code == 400
|
225
|
+
error = JSON.parse(e.response.to_s)
|
226
|
+
::Morpheus::Cli::ErrorHandler.new.print_errors(error,options)
|
227
|
+
else
|
228
|
+
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
229
|
+
end
|
230
|
+
exit 1
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def remove(args)
|
235
|
+
deployment_name = args[0]
|
236
|
+
options = {}
|
237
|
+
optparse = OptionParser.new do|opts|
|
238
|
+
opts.banner = "Usage: morpheus deployments remove [deployment]"
|
239
|
+
Morpheus::Cli::CliCommand.genericOptions(opts,options)
|
240
|
+
end
|
241
|
+
if args.count < 1
|
242
|
+
puts "\n#{optparse.banner}\n\n"
|
243
|
+
exit 1
|
244
|
+
end
|
245
|
+
optparse.parse(args)
|
246
|
+
connect(options)
|
247
|
+
begin
|
248
|
+
deployment = find_deployment_by_name_or_code_or_id(deployment_name)
|
249
|
+
exit 1 if deployment.nil?
|
250
|
+
exit unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the deployment #{deployment['name']}?")
|
251
|
+
json_response = @deployments_interface.destroy(deployment['id'])
|
252
|
+
if options[:json]
|
253
|
+
print JSON.pretty_generate(json_response)
|
254
|
+
else
|
255
|
+
print "\n", cyan, "Deployment #{deployment['name']} removed", reset, "\n\n"
|
256
|
+
end
|
257
|
+
rescue RestClient::Exception => e
|
258
|
+
if e.response.code == 400
|
259
|
+
error = JSON.parse(e.response.to_s)
|
260
|
+
::Morpheus::Cli::ErrorHandler.new.print_errors(error,options)
|
261
|
+
else
|
262
|
+
puts "Error Communicating with the Appliance. Please try again later. #{e}"
|
263
|
+
end
|
264
|
+
exit 1
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
|
269
|
+
private
|
270
|
+
def find_deployment_by_name_or_code_or_id(val)
|
271
|
+
raise "find_deployment_by_name_or_code_or_id passed a bad name: #{val.inspect}" if val.to_s == ''
|
272
|
+
results = @deployments_interface.get(val)
|
273
|
+
result = nil
|
274
|
+
if !results['deployments'].nil? && !results['deployments'].empty?
|
275
|
+
result = results['deployments'][0]
|
276
|
+
elsif val.to_i.to_s == val
|
277
|
+
results = @deployments_interface.get(val.to_i)
|
278
|
+
result = results['deployment']
|
279
|
+
end
|
280
|
+
if result.nil?
|
281
|
+
print red,bold, "\nDeployment not found by '#{val}'\n\n",reset
|
282
|
+
return nil
|
283
|
+
end
|
284
|
+
return result
|
285
|
+
end
|
286
|
+
|
287
|
+
def find_deployment_type_by_name(val)
|
288
|
+
raise "find_deployment_type_by_name passed a bad name: #{val.inspect}" if val.to_s == ''
|
289
|
+
results = @deployments_interface.deployment_types(val)
|
290
|
+
result = nil
|
291
|
+
if !results['deploymentTypes'].nil? && !results['deploymentTypes'].empty?
|
292
|
+
result = results['deploymentTypes'][0]
|
293
|
+
elsif val.to_i.to_s == val
|
294
|
+
results = @deployments_interface.deployment_types(val.to_i)
|
295
|
+
result = results['deploymentType']
|
296
|
+
end
|
297
|
+
if result.nil?
|
298
|
+
print red,bold, "\nDeployment Type not found by '#{val}'\n\n",reset
|
299
|
+
return nil
|
300
|
+
end
|
301
|
+
return result
|
302
|
+
end
|
303
|
+
|
304
|
+
def update_deployment_option_types()
|
305
|
+
[
|
306
|
+
{'fieldName' => 'name', 'fieldLabel' => 'Name', 'type' => 'text', 'required' => true, 'displayOrder' => 0},
|
307
|
+
{'fieldName' => 'description', 'fieldLabel' => 'Description', 'type' => 'text', 'required' => false, 'displayOrder' => 1}
|
308
|
+
]
|
309
|
+
end
|
310
|
+
end
|