Module: Morpheus::Cli::CatalogHelper

Included in:
CatalogCommand
Defined in:
lib/morpheus/cli/mixins/catalog_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/catalog_helper.rb', line 6

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

Instance Method Details

#catalog_item_type_list_key ⇒ Object



24
25
26
# File 'lib/morpheus/cli/mixins/catalog_helper.rb', line 24

def catalog_item_type_list_key
  'catalogItemTypes'
end

#catalog_item_type_object_key ⇒ Object

def service_catalog_interface raise "#Morpheus::Cli::CatalogHelper.selfself.class has not defined @service_catalog_interface" if @service_catalog_interface.nil? @service_catalog_interface end



20
21
22
# File 'lib/morpheus/cli/mixins/catalog_helper.rb', line 20

def catalog_item_type_object_key
  'catalogItemType'
end

#catalog_item_types_interface ⇒ Object



10
11
12
13
# File 'lib/morpheus/cli/mixins/catalog_helper.rb', line 10

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

#find_catalog_item_type_by_id(id) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/morpheus/cli/mixins/catalog_helper.rb', line 36

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

#find_catalog_item_type_by_name(name) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/morpheus/cli/mixins/catalog_helper.rb', line 49

def find_catalog_item_type_by_name(name)
  json_response = catalog_item_types_interface.list({name: name.to_s})
  catalog_item_types = json_response[catalog_item_type_list_key]
  if catalog_item_types.empty?
    print_red_alert "catalog_item_type not found by name '#{name}'"
    return nil
  elsif catalog_item_types.size > 1
    print_red_alert "#{catalog_item_types.size} catalog_item_types found by name '#{name}'"
    puts_error as_pretty_table(catalog_item_types, [:id, :name], {color:red})
    print_red_alert "Try using ID instead"
    print reset,"\n"
    return nil
  else
    return catalog_item_types[0]
  end
end

#find_catalog_item_type_by_name_or_id(val) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/morpheus/cli/mixins/catalog_helper.rb', line 28

def find_catalog_item_type_by_name_or_id(val)
  if val.to_s =~ /\A\d{1,}\Z/
    return find_catalog_item_type_by_id(val)
  else
    return find_catalog_item_type_by_name(val)
  end
end