Module: Morpheus::Cli::StorageServersHelper

Included in:
StorageServerTypes, StorageServers
Defined in:
lib/morpheus/cli/mixins/storage_servers_helper.rb

Overview

including storage servers and storage server types

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



9
10
11
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 9

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

Instance Method Details

#find_storage_server_by_id(id) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 65

def find_storage_server_by_id(id)
  begin
    json_response = storage_servers_interface.get(id.to_i)
    return json_response[storage_server_object_key]
  rescue RestClient::Exception => e
    if e.response && e.response.code == 404
      print_red_alert "Storage Server not found by id #{id}"
    else
      raise e
    end
  end
end

#find_storage_server_by_name(name) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 78

def find_storage_server_by_name(name)
  lbs = storage_servers_interface.list({name: name.to_s})[storage_server_list_key]
  if lbs.empty?
    print_red_alert "Storage Server not found by name #{name}"
    return nil
  elsif lbs.size > 1
    print_red_alert "#{lbs.size} storage servers found by name #{name}"
    #print_lbs_table(lbs, {color: red})
    print reset,"\n\n"
    return nil
  else
    return lbs[0]
  end
end

#find_storage_server_by_name_or_id(val) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 57

def find_storage_server_by_name_or_id(val)
  if val.to_s =~ /\A\d{1,}\Z/
    return find_storage_server_by_id(val)
  else
    return find_storage_server_by_name(val)
  end
end

#storage_server_labelObject



33
34
35
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 33

def storage_server_label
  'Storage Server'
end

#storage_server_label_pluralObject



37
38
39
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 37

def storage_server_label_plural
  'Storage Server'
end

#storage_server_list_keyObject



29
30
31
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 29

def storage_server_list_key
  'storageServers'
end

#storage_server_object_keyObject



25
26
27
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 25

def storage_server_object_key
  'storageServer'
end

#storage_server_type_labelObject



49
50
51
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 49

def storage_server_type_label
  'Storage Server Type'
end

#storage_server_type_label_pluralObject



53
54
55
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 53

def storage_server_type_label_plural
  'Storage Server Types'
end

#storage_server_type_list_keyObject



45
46
47
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 45

def storage_server_type_list_key
  'storageServerTypes'
end

#storage_server_type_object_keyObject



41
42
43
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 41

def storage_server_type_object_key
  'storageServerType'
end

#storage_server_types_interfaceObject



19
20
21
22
23
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 19

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

#storage_servers_interfaceObject



13
14
15
16
17
# File 'lib/morpheus/cli/mixins/storage_servers_helper.rb', line 13

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