Class: Misty::Cloud

Inherits:
Object
  • Object
show all
Defined in:
lib/misty/cloud.rb

Defined Under Namespace

Classes: Config

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Cloud

=> {})



16
17
18
19
20
# File 'lib/misty/cloud.rb', line 16

def initialize(params)# = {:auth => {}})
  @params = params
  @config = self.class.set_configuration(params)
  @auth = Misty::Auth.factory(params[:auth], @config)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object (private)



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/misty/cloud.rb', line 139

def method_missing(method_name)
  services_avail = []
  Misty.services.names.each do |service_name|
    services_avail << service_name if /#{method_name}/.match(service_name)
  end

  if services_avail.size == 1
    self.send(services_avail[0])
    return self.instance_variable_get("@#{services_avail[0]}")
  elsif services_avail.size > 1
    raise NoMethodError, "Ambiguous Cloud Service: #{method_name}"
  else
    raise NoMethodError, "No such Cloud Service: #{method_name}"
  end
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



10
11
12
# File 'lib/misty/cloud.rb', line 10

def auth
  @auth
end

Class Method Details

.dot_to_underscore(val) ⇒ Object



12
13
14
# File 'lib/misty/cloud.rb', line 12

def self.dot_to_underscore(val)
  val.gsub(/\./,'_')
end

.set_configuration(params) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/misty/cloud.rb', line 22

def self.set_configuration(params)
  config = Config.new
  config.content_type = params[:content_type] ? params[:content_type] : Misty::CONTENT_TYPE
  config.interface = params[:interface] ? params[:interface] : Misty::INTERFACE
  config.log = Logger.new(params[:log_file] ? params[:log_file] : Misty::LOG_FILE)
  config.log.level = params[:log_level] ? params[:log_level] : Misty::LOG_LEVEL
  config.region_id = params[:region_id] ? params[:region_id] : Misty::REGION_ID
  config.ssl_verify_mode = params.key?(:ssl_verify_mode) ? params[:ssl_verify_mode] : Misty::SSL_VERIFY_MODE
  config.headers = params[:headers]
  config
end

Instance Method Details

#alarmingObject



46
47
48
# File 'lib/misty/cloud.rb', line 46

def alarming
  @alarming ||= build_service(:alarming)
end

#application_catalogObject



42
43
44
# File 'lib/misty/cloud.rb', line 42

def application_catalog
  @application_catalog ||= build_service(:application_catalog)
end

#backupObject



50
51
52
# File 'lib/misty/cloud.rb', line 50

def backup
  @backup ||= build_service(:backup)
end

#baremetalObject



54
55
56
# File 'lib/misty/cloud.rb', line 54

def baremetal
  @baremetal ||= build_service(:baremetal)
end

#block_storageObject Also known as: volume



58
59
60
# File 'lib/misty/cloud.rb', line 58

def block_storage
  @block_storage ||= build_service(:block_storage)
end

#build_service(service_name) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/misty/cloud.rb', line 34

def build_service(service_name)
  service = Misty.services.find {|service| service.name == service_name}
  options = @params[service.name] ? @params[service.name] : {}
  version = self.class.dot_to_underscore(service.version(options[:api_version]))
  klass = Object.const_get("Misty::Openstack::#{service.project.capitalize}::#{version.capitalize}")
  klass.new(@auth, @config, options)
end

#clusteringObject



62
63
64
# File 'lib/misty/cloud.rb', line 62

def clustering
  @clustering ||= build_service(:clustering)
end

#computeObject



66
67
68
# File 'lib/misty/cloud.rb', line 66

def compute
  @compute ||= build_service(:compute)
end

#container_infrastructure_managementObject



70
71
72
# File 'lib/misty/cloud.rb', line 70

def container_infrastructure_management
  @container_infrastructure_management ||= build_service(:container_infrastructure_management)
end

#data_processingObject



74
75
76
# File 'lib/misty/cloud.rb', line 74

def data_processing
  @data_processing ||= build_service(:data_processing)
end

#data_protection_orchestrationObject



78
79
80
# File 'lib/misty/cloud.rb', line 78

def data_protection_orchestration
  @data_protection_orchestration ||= build_service(:data_protection_orchestration)
end

#databaseObject



82
83
84
# File 'lib/misty/cloud.rb', line 82

def database
  @database ||= build_service(:database)
end

#domain_name_serverObject Also known as: dns



86
87
88
# File 'lib/misty/cloud.rb', line 86

def domain_name_server
  @domain_name_server ||= build_service(:domain_name_server)
end

#identityObject



90
91
92
# File 'lib/misty/cloud.rb', line 90

def identity
  @identity ||= build_service(:identity)
end

#imageObject



94
95
96
# File 'lib/misty/cloud.rb', line 94

def image
  @image ||= build_service(:image)
end

#load_balancerObject



98
99
100
# File 'lib/misty/cloud.rb', line 98

def load_balancer
  @load_balancer ||= build_service(:load_balancer)
end

#messagingObject



102
103
104
# File 'lib/misty/cloud.rb', line 102

def messaging
  @messaging ||= build_service(:messaging)
end

#meteringObject



106
107
108
# File 'lib/misty/cloud.rb', line 106

def metering
  @metering ||= build_service(:metering)
end

#networkingObject



110
111
112
# File 'lib/misty/cloud.rb', line 110

def networking
  @networking ||= build_service(:networking)
end

#nfv_orchestrationObject



114
115
116
# File 'lib/misty/cloud.rb', line 114

def nfv_orchestration
  @nfv_orchestration ||= build_service(:nfv_orchestration)
end

#object_storageObject



118
119
120
# File 'lib/misty/cloud.rb', line 118

def object_storage
  @object_storage ||= build_service(:object_storage)
end

#orchestrationObject



122
123
124
# File 'lib/misty/cloud.rb', line 122

def orchestration
  @orchestration ||= build_service(:orchestration)
end

#searchObject



126
127
128
# File 'lib/misty/cloud.rb', line 126

def search
  @search ||= build_service(:search)
end

#shared_file_systemsObject



130
131
132
# File 'lib/misty/cloud.rb', line 130

def shared_file_systems
  @shared_file_systems ||= build_service(:shared_file_systems)
end