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.
@@ -44,6 +44,8 @@ class Morpheus::Cli::Workflows
44
44
  add(args[1..-1])
45
45
  when 'remove'
46
46
  remove(args[1..-1])
47
+ when 'update'
48
+ update(args[1..-1])
47
49
  else
48
50
  puts "\nUsage: morpheus workflows [list,add,remove]\n\n"
49
51
  exit 127
@@ -93,8 +95,115 @@ class Morpheus::Cli::Workflows
93
95
  end
94
96
 
95
97
  def add(args)
98
+ workflow_name = args[0]
99
+ options = {}
100
+ optparse = OptionParser.new do|opts|
101
+ opts.banner = "Usage: morpheus workflows add [name] "
102
+ opts.on("--tasks x,y,z", Array, "List of tasks to run in order") do |list|
103
+ options[:task_names]= list
104
+ end
105
+ Morpheus::Cli::CliCommand.genericOptions(opts,options)
106
+ end
107
+ if args.count < 1
108
+ puts "\n#{optparse.banner}\n\n"
109
+ exit 1
110
+ end
111
+ optparse.parse(args)
112
+ connect(options)
113
+ begin
114
+ tasks = []
115
+ options[:task_names].each do |task_name|
116
+ tasks << find_task_by_name_or_code_or_id(task_name)['id']
117
+ end
118
+
119
+ payload = {taskSet: {name: workflow_name, tasks: tasks}}
120
+ json_response = @task_sets_interface.create(payload)
121
+ if options[:json]
122
+ print JSON.pretty_generate(json_response)
123
+ else
124
+ print "\n", cyan, "Workflow #{json_response['taskSet']['name']} created successfully", reset, "\n\n"
125
+ end
126
+ rescue RestClient::Exception => e
127
+ if e.response.code == 400
128
+ error = JSON.parse(e.response.to_s)
129
+ ::Morpheus::Cli::ErrorHandler.new.print_errors(error,options)
130
+ else
131
+ puts "Error Communicating with the Appliance. Please try again later. #{e}"
132
+ end
133
+ exit 1
134
+ end
135
+ end
136
+
137
+ def update(args)
96
138
  end
97
139
 
98
140
  def remove(args)
141
+ workflow_name = args[0]
142
+ options = {}
143
+ optparse = OptionParser.new do|opts|
144
+ opts.banner = "Usage: morpheus workflows remove [name]"
145
+ Morpheus::Cli::CliCommand.genericOptions(opts,options)
146
+ end
147
+ if args.count < 1
148
+ puts "\n#{optparse.banner}\n\n"
149
+ exit 1
150
+ end
151
+ optparse.parse(args)
152
+ connect(options)
153
+ begin
154
+ workflow = find_workflow_by_name_or_code_or_id(workflow_name)
155
+ exit 1 if workflow.nil?
156
+ exit unless Morpheus::Cli::OptionTypes.confirm("Are you sure you want to delete the workflow #{workflow['name']}?")
157
+ json_response = @tasks_interface.destroy(task['id'])
158
+ if options[:json]
159
+ print JSON.pretty_generate(json_response)
160
+ else
161
+ print "\n", cyan, "Workflow #{workflow['name']} removed", reset, "\n\n"
162
+ end
163
+ rescue RestClient::Exception => e
164
+ if e.response.code == 400
165
+ error = JSON.parse(e.response.to_s)
166
+ ::Morpheus::Cli::ErrorHandler.new.print_errors(error,options)
167
+ else
168
+ puts "Error Communicating with the Appliance. Please try again later. #{e}"
169
+ end
170
+ exit 1
171
+ end
172
+ end
173
+
174
+
175
+ private
176
+ def find_workflow_by_name_or_code_or_id(val)
177
+ raise "find_workflow_by_name_or_code_or_id passed a bad name: #{val.inspect}" if val.to_s == ''
178
+ results = @task_sets_interface.get(val)
179
+ result = nil
180
+ if !results['taskSets'].nil? && !results['taskSets'].empty?
181
+ result = results['taskSets'][0]
182
+ elsif val.to_i.to_s == val
183
+ results = @task_sets_interface.get(val.to_i)
184
+ result = results['taskSet']
185
+ end
186
+ if result.nil?
187
+ print red,bold, "\nWorkflow not found by '#{val}'\n\n",reset
188
+ return nil
189
+ end
190
+ return result
191
+ end
192
+
193
+ def find_task_by_name_or_code_or_id(val)
194
+ raise "find_task_by_name_or_code_or_id passed a bad name: #{val.inspect}" if val.to_s == ''
195
+ results = @tasks_interface.get(val)
196
+ result = nil
197
+ if !results['tasks'].nil? && !results['tasks'].empty?
198
+ result = results['tasks'][0]
199
+ elsif val.to_i.to_s == val
200
+ results = @tasks_interface.get(val.to_i)
201
+ result = results['task']
202
+ end
203
+ if result.nil?
204
+ print red,bold, "\nTask not found by '#{val}'\n\n",reset
205
+ return nil
206
+ end
207
+ return result
99
208
  end
100
209
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morpheus-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Estes
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-09-01 00:00:00.000000000 Z
13
+ date: 2016-09-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -144,6 +144,7 @@ files:
144
144
  - lib/morpheus/api/apps_interface.rb
145
145
  - lib/morpheus/api/clouds_interface.rb
146
146
  - lib/morpheus/api/deploy_interface.rb
147
+ - lib/morpheus/api/deployments_interface.rb
147
148
  - lib/morpheus/api/groups_interface.rb
148
149
  - lib/morpheus/api/instance_types_interface.rb
149
150
  - lib/morpheus/api/instances_interface.rb
@@ -160,6 +161,7 @@ files:
160
161
  - lib/morpheus/api/task_sets_interface.rb
161
162
  - lib/morpheus/api/tasks_interface.rb
162
163
  - lib/morpheus/api/users_interface.rb
164
+ - lib/morpheus/api/virtual_images_interface.rb
163
165
  - lib/morpheus/cli.rb
164
166
  - lib/morpheus/cli/accounts.rb
165
167
  - lib/morpheus/cli/apps.rb
@@ -167,6 +169,7 @@ files:
167
169
  - lib/morpheus/cli/cli_registry.rb
168
170
  - lib/morpheus/cli/clouds.rb
169
171
  - lib/morpheus/cli/credentials.rb
172
+ - lib/morpheus/cli/deployments.rb
170
173
  - lib/morpheus/cli/deploys.rb
171
174
  - lib/morpheus/cli/error_handler.rb
172
175
  - lib/morpheus/cli/groups.rb
@@ -186,6 +189,7 @@ files:
186
189
  - lib/morpheus/cli/tasks.rb
187
190
  - lib/morpheus/cli/users.rb
188
191
  - lib/morpheus/cli/version.rb
192
+ - lib/morpheus/cli/virtual_images.rb
189
193
  - lib/morpheus/cli/workflows.rb
190
194
  - lib/morpheus/formatters.rb
191
195
  - lib/morpheus/rest_client.rb
@@ -210,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
214
  version: '0'
211
215
  requirements: []
212
216
  rubyforge_project:
213
- rubygems_version: 2.5.1
217
+ rubygems_version: 2.2.2
214
218
  signing_key:
215
219
  specification_version: 4
216
220
  summary: Provides CLI Interface to the Morpheus Public/Private Cloud Appliance