Class: Morpheus::Cli::Deploys

Inherits:
Object
  • Object
show all
Includes:
CliCommand, DeploymentsHelper
Defined in:
lib/morpheus/cli/deploys.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from DeploymentsHelper

#deployment_list_key, #deployment_object_key, #deployment_version_list_key, #deployment_version_object_key, #deployments_interface, #find_deployment_by_id, #find_deployment_by_name, #find_deployment_by_name_or_id, #find_deployment_type_by_name, #find_deployment_version_by_id, #find_deployment_version_by_name, #find_deployment_version_by_name_or_id, included

Methods included from CliCommand

#apply_options, #build_common_options, #build_option_type_options, #build_standard_add_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_name, #default_refresh_interval, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #get_subcommand_description, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_bytes_param, #parse_id_list, #parse_list_options, #parse_list_subtitles, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands

Instance Method Details

#_get(id, params, options) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/morpheus/cli/deploys.rb', line 88

def _get(id, params, options)
  @deploy_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @deploy_interface.dry.get(id, params)
    return 0
  end
  json_response = @deploy_interface.get(id, params)
  app_deploy = json_response[app_deploy_object_key]
  render_response(json_response, options, app_deploy_object_key) do
    print_h1 "Deploy Details", [], options
    print cyan
    print_description_list(app_deploy_column_definitions, app_deploy)
    print reset,"\n"
  end
  return 0, nil
end

#add(args) ⇒ Object



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
# File 'lib/morpheus/cli/deploys.rb', line 105

def add(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[instance] [deployment] [version] [options]")
    build_option_type_options(opts, options, add_app_deploy_option_types)
    build_option_type_options(opts, options, add_app_deploy_advanced_option_types)
    build_standard_add_options(opts, options)
    opts.footer = "Create a new instance deploy.\n"
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, min:0, max:3)
  options[:options]['instance'] = args[0] if args[0]
  options[:options]['deployment'] = args[1] if args[1]
  options[:options]['version'] = args[2] if args[2]
  connect(options)
  payload = {}
  if options[:payload]
    payload = options[:payload]
    payload.deep_merge!({app_deploy_object_key => parse_passed_options(options)})
  else
    payload.deep_merge!({app_deploy_object_key => parse_passed_options(options)})
    v_prompt = Morpheus::Cli::OptionTypes.prompt(add_app_deploy_option_types, options[:options], @api_client, options[:params])
    params.deep_merge!(v_prompt)
    advanced_config = Morpheus::Cli::OptionTypes.no_prompt(add_app_deploy_advanced_option_types, options[:options], @api_client, options[:params])
    advanced_config.deep_compact!
    params.deep_merge!(advanced_config)
    payload[app_deploy_object_key].deep_merge!(params)
  end
  @deploy_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @deploy_interface.dry.create(payload)
    return 0, nil
  end
  json_response = @deploy_interface.create(payload)
  app_deploy = json_response[app_deploy_object_key]
  render_response(json_response, options, app_deploy_object_key) do
    print_green_success "Deploying..."
    return _get(app_deploy["id"], {}, options)
  end
  return 0, nil
end

#connect(opts) ⇒ Object



15
16
17
18
19
20
# File 'lib/morpheus/cli/deploys.rb', line 15

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @instances_interface = @api_client.instances
  @deploy_interface = @api_client.deploy
  @deployments_interface = @api_client.deployments
end

#deploy(args) ⇒ Object



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
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/morpheus/cli/deploys.rb', line 178

def deploy(args)
  options = {}
  params = {}
  payload = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[id] [options]")
    build_option_type_options(opts, options, update_app_deploy_option_types)
    build_option_type_options(opts, options, update_app_deploy_advanced_option_types)
    build_standard_update_options(opts, options)
    opts.footer = "Update an instance deploy.\n[id] is required. This is the name or id of an instance deploy.\n"
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count:1)
  connect(options)
  app_deploy = find_app_deploy_by_id(args[0])
  return 1 if app_deploy.nil?
  payload = {}
  if options[:payload]
    payload = options[:payload]
    payload.deep_merge!({app_deploy_object_key => parse_passed_options(options)})
  else
    payload.deep_merge!({app_deploy_object_key => parse_passed_options(options)})
    # do not prompt on update
    v_prompt = Morpheus::Cli::OptionTypes.no_prompt(update_app_deploy_option_types, options[:options], @api_client, options[:params])
    v_prompt.deep_compact!
    params.deep_merge!(v_prompt)
    advanced_config = Morpheus::Cli::OptionTypes.no_prompt(update_app_deploy_advanced_option_types, options[:options], @api_client, options[:params])
    advanced_config.deep_compact!
    params.deep_merge!(advanced_config)
    payload.deep_merge!({app_deploy_object_key => params})
    if payload[app_deploy_object_key].empty? # || options[:no_prompt]
      raise_command_error "Specify at least one option to update.\n#{optparse}"
    end
  end
  @deploy_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @deploy_interface.dry.update(app_deploy['id'], payload)
    return
  end
  json_response = @deploy_interface.update(app_deploy['id'], payload)
  app_deploy = json_response[app_deploy_object_key]
  render_response(json_response, options, app_deploy_object_key) do
    print_green_success "Deploying..."
    return _get(app_deploy["id"], {}, options)
  end
  return 0, nil
end

#get(args) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/morpheus/cli/deploys.rb', line 68

def get(args)
  params = {}
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[id]")
    build_standard_get_options(opts, options)
    opts.footer = "Get details about a specific instance deploy.\n[id] is required. This is the name or id of a deployment.\n"
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, min:1)
  connect(options)
  id_list = parse_id_list(args)
  return run_command_for_each_arg(id_list) do |arg|
    _get(arg, params, options)
  end
end

#handle(args) ⇒ Object



22
23
24
# File 'lib/morpheus/cli/deploys.rb', line 22

def handle(args)
  handle_subcommand(args)
end

#list(args) ⇒ Object



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
# File 'lib/morpheus/cli/deploys.rb', line 26

def list(args)
  options = {}
  params = {}
  ref_ids = []
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[search]")
    build_standard_list_options(opts, options)
    opts.footer = "List deploys.\n"
  end
  optparse.parse!(args)
  connect(options)
  # verify_args!(args:args, optparse:optparse, count:0)
  if args.count > 0
    options[:phrase] = args.join(" ")
  end
  params.merge!(parse_list_options(options))
  @deploy_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @deploy_interface.dry.list(params)
    return
  end
  json_response = @deploy_interface.list(params)
  app_deploys = json_response[app_deploy_list_key]
  render_response(json_response, options, app_deploy_list_key) do
    print_h1 "Morpheus Deploys", parse_list_subtitles(options), options
    if app_deploys.empty?
      print cyan,"No deploys found.",reset,"\n"
    else
      print as_pretty_table(app_deploys, app_deploy_column_definitions.upcase_keys!, options)
      print_results_pagination(json_response)
    end
    print reset,"\n"
  end
  if app_deploys.empty?
    return 1, "no deploys found"
  else
    return 0, nil
  end
end

#remove(args) ⇒ Object



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
# File 'lib/morpheus/cli/deploys.rb', line 150

def remove(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[id] [options]")
    build_standard_remove_options(opts, options)
    opts.footer = "Delete an instance deploy.\n[id] is required. This is the name or id of a deploy.\n"
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count:1)
  connect(options)
  app_deploy = find_app_deploy_by_id(args[0])
  return 1 if app_deploy.nil?
  @deploy_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @deploy_interface.dry.destroy(app_deploy['id'], params)
    return
  end
  json_response = @deploy_interface.destroy(app_deploy['id'], params)
  render_response(json_response, options) do
    print_green_success "Removed deploy #{app_deploy['name']}"
  end
  return 0, nil
end