Module: Morpheus::Cli::DeploymentsHelper

Included in:
Deploy, Deployments, Deploys, Instances
Defined in:
lib/morpheus/cli/mixins/deployments_helper.rb

Overview

Provides common methods for infrastructure management

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



6
7
8
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 6

def self.included(klass)
  klass.send :include, Morpheus::Cli::PrintHelper
end

Instance Method Details

#deployment_list_keyObject



21
22
23
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 21

def deployment_list_key
  'deployments'
end

#deployment_object_keyObject



17
18
19
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 17

def deployment_object_key
  'deployment'
end

#deployment_version_list_keyObject



92
93
94
95
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 92

def deployment_version_list_key
  # 'deploymentVersions'
  'versions'
end

#deployment_version_object_keyObject

Deployment Versions



87
88
89
90
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 87

def deployment_version_object_key
  # 'deploymentVersion'
  'version'
end

#deployments_interfaceObject

Deployments



12
13
14
15
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 12

def deployments_interface
  raise "#{self.class} has not defined @deployments_interface" if @deployments_interface.nil?
  @deployments_interface
end

#find_deployment_by_id(id) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 33

def find_deployment_by_id(id)
  begin
    json_response = deployments_interface.get(id.to_i)
    return json_response[deployment_object_key]
  rescue RestClient::Exception => e
    if e.response && e.response.code == 404
      print_red_alert "Deployment not found by id '#{id}'"
    else
      raise e
    end
  end
end

#find_deployment_by_name(name) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 46

def find_deployment_by_name(name)
  json_response = deployments_interface.list({name: name.to_s})
  deployments = json_response[deployment_list_key]
  if deployments.empty?
    print_red_alert "Deployment not found by name '#{name}'"
    return nil
  elsif deployments.size > 1
    print_red_alert "#{deployments.size} deployments found by name '#{name}'"
    print_error "\n"
    puts_error as_pretty_table(deployments, [:id, :name], {color:red})
    print_red_alert "Try using ID instead"
    print_error reset,"\n"
    return nil
  else
    return deployments[0]
  end
end

#find_deployment_by_name_or_id(val) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 25

def find_deployment_by_name_or_id(val)
  if val.to_s =~ /\A\d{1,}\Z/
    return find_deployment_by_id(val)
  else
    return find_deployment_by_name(val)
  end
end

#find_deployment_type_by_name(val) ⇒ Object

unused?



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

def find_deployment_type_by_name(val)
  raise "find_deployment_type_by_name passed a bad name: #{val.inspect}" if val.to_s == ''
  results = @deployments_interface.deployment_types(val)
  result = nil
  if !results['deploymentTypes'].nil? && !results['deploymentTypes'].empty?
    result = results['deploymentTypes'][0]
  elsif val.to_i.to_s == val
    results = @deployments_interface.deployment_types(val.to_i)
    result = results['deploymentType']
  end
  if result.nil?
    print_red_alert "Deployment Type not found by '#{val}'"
    return nil
  end
  return result
end

#find_deployment_version_by_id(deployment_id, id) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 105

def find_deployment_version_by_id(deployment_id, id)
  begin
    json_response = deployments_interface.get_version(deployment_id, id.to_i)
    return json_response[deployment_version_object_key]
  rescue RestClient::Exception => e
    if e.response && e.response.code == 404
      print_red_alert "Deployment version not found by id '#{id}'"
    else
      raise e
    end
  end
end

#find_deployment_version_by_name(deployment_id, name) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 118

def find_deployment_version_by_name(deployment_id, name)
  json_response = deployments_interface.list_versions(deployment_id, {userVersion: name.to_s})
  deployment_versions = json_response[deployment_version_list_key]
  if deployment_versions.empty?
    print_red_alert "Deployment version not found by version '#{name}'"
    return nil
  elsif deployment_versions.size > 1
    print_red_alert "#{deployment_versions.size} deployment versions found by version '#{name}'"
    print_error "\n"
    puts_error as_pretty_table(deployment_versions, {"ID" => 'id', "VERSION" => 'userVersion'}, {color:red})
    print_red_alert "Try using ID instead"
    print_error reset,"\n"
    return nil
  else
    return deployment_versions[0]
  end
end

#find_deployment_version_by_name_or_id(deployment_id, val) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 97

def find_deployment_version_by_name_or_id(deployment_id, val)
  if val.to_s =~ /\A\d{1,}\Z/
    return find_deployment_version_by_id(deployment_id, val)
  else
    return find_deployment_version_by_name(deployment_id, val)
  end
end

#format_app_deploy_status(status, return_color = cyan) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 144

def format_app_deploy_status(status, return_color=cyan)
  out = ""
  s = status.to_s.downcase
  if s == 'deployed' || s == 'committed'
    out << "#{green}#{s.upcase}#{return_color}"
  elsif s == 'open' || s == 'archived'
    out << "#{cyan}#{s.upcase}#{return_color}"
  elsif s == 'failed'
    out << "#{red}#{s.upcase}#{return_color}"
  else
    out << "#{yellow}#{s.upcase}#{return_color}"
  end
  out
end

#format_deploy_type(val) ⇒ Object



159
160
161
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 159

def format_deploy_type(val)
  return val
end

#format_deployment_version_number(deployment_version) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/morpheus/cli/mixins/deployments_helper.rb', line 136

def format_deployment_version_number(deployment_version)
  if deployment_version
    deployment_version['userVersion'] || deployment_version['version'] || ''
  else
    ''
  end
end