Class: Coral::Machine::Fog

Inherits:
Plugin::Machine show all
Includes:
Coral::Mixin::SubConfig
Defined in:
lib/coral/machine/fog.rb

Instance Attribute Summary

Attributes inherited from Core

#ui

Instance Method Summary collapse

Methods included from Coral::Mixin::SubConfig

#clear, #config, #config=, #defaults, #delete, #directory, #directory=, #export, #get, #import, #load, #save, #set

Methods inherited from Plugin::Machine

#provision

Methods inherited from Plugin::Base

build_info, ensure_plugin_collection, #initialize, #initialized?, #meta, #method_missing, #plugin_directory, #plugin_file, #plugin_instance_name, #plugin_parent, #plugin_parent=, #plugin_provider, #plugin_type, #set_meta, translate

Methods inherited from Core

#initialize, #inspect, #logger, logger, logger=, ui

Methods inherited from Config

#[], #[]=, array, #array, #clear, #defaults, #delete, ensure, #export, #filter, filter, #get, #get_array, #get_hash, #hash, hash, #import, init, #init, init_flat, #initialize, #set, #string, string, string_map, #string_map, #symbol, symbol, symbol_map, #symbol_map, test, #test

Methods included from Coral::Mixin::ConfigOptions

#clear_options, #contexts, #get_options, #set_options

Methods included from Coral::Mixin::ConfigCollection

#all_properties, #clear_properties, #delete_property, #get_property, #save_properties, #set_property

Methods included from Coral::Mixin::Lookup

#hiera, #hiera_config, #initialized?, #lookup, #lookup_array, #lookup_hash

Methods included from Coral::Mixin::ConfigOps

#parse

Constructor Details

This class inherits a constructor from Coral::Plugin::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Coral::Plugin::Base

Instance Method Details

#computeObject




39
40
41
# File 'lib/coral/machine/fog.rb', line 39

def compute
  return get(:compute)
end

#create(options = {}) ⇒ Object


Management



120
121
122
123
124
125
126
# File 'lib/coral/machine/fog.rb', line 120

def create(options = {})
  success = super(options)
  if success && ! created?
    set(:server, compute.servers.bootstrap(options))
  end
  return success
end

#create_image(name, options = {}) ⇒ Object




201
202
203
204
205
206
207
208
# File 'lib/coral/machine/fog.rb', line 201

def create_image(name, options = {})
  success = super(options)
  if success && created?
    image = server.create_image(name, options)
    return ( image ? image.id : false )
  end
  return success
end

#created?Boolean


Checks

Returns:

  • (Boolean)


19
20
21
# File 'lib/coral/machine/fog.rb', line 19

def created?
  return server && ! server.state != 'DELETED'
end

#destroy(options = {}) ⇒ Object




179
180
181
182
183
184
185
# File 'lib/coral/machine/fog.rb', line 179

def destroy(options = {})
  success = super(options)   
  if success && created?
    return server.destroy(options)  
  end
  return success
end

#exec(options = {}) ⇒ Object




189
190
191
192
193
194
195
196
197
# File 'lib/coral/machine/fog.rb', line 189

def exec(options = {})
  success = super(options)
  if success && running?
    if commands = options.delete(:commands)
      return server.ssh(commands, options)
    end
  end
  return success
end

#flavorObject




98
99
100
101
# File 'lib/coral/machine/fog.rb', line 98

def flavor
  return server.flavor if server
  return nil
end

#flavorsObject




91
92
93
94
# File 'lib/coral/machine/fog.rb', line 91

def flavors
  return compute.flavors if compute
  return nil
end

#hostnameObject




63
64
65
66
# File 'lib/coral/machine/fog.rb', line 63

def hostname
  return server.name if server
  return ''
end

#imageObject




112
113
114
115
# File 'lib/coral/machine/fog.rb', line 112

def image
  return server.image if server
  return nil
end

#imagesObject




105
106
107
108
# File 'lib/coral/machine/fog.rb', line 105

def images
  return compute.images if compute
  return nil
end

#nameObject




51
52
53
# File 'lib/coral/machine/fog.rb', line 51

def name
  return ( server ? server.id : '' )
end

#name=(id) ⇒ Object




57
58
59
# File 'lib/coral/machine/fog.rb', line 57

def name=id
  set(:server, compute.servers.get(id)) if id    
end

#normalizeObject


Machine plugin interface



11
12
13
14
# File 'lib/coral/machine/fog.rb', line 11

def normalize
  super
  set_connection
end

#private_ipObject




84
85
86
87
# File 'lib/coral/machine/fog.rb', line 84

def private_ip
  return server.private_ip_address if server
  return nil
end

#public_ipObject




77
78
79
80
# File 'lib/coral/machine/fog.rb', line 77

def public_ip
  return server.public_ip_address if server
  return nil
end

#reload(options = {}) ⇒ Object




168
169
170
171
172
173
174
175
# File 'lib/coral/machine/fog.rb', line 168

def reload(options = {})
  success = super(options)
  if success && created?
    # Don't quite know what this should do yet??
    return server.reboot(options)  
  end
  return success
end

#running?Boolean


Returns:

  • (Boolean)


25
26
27
# File 'lib/coral/machine/fog.rb', line 25

def running?
  return created? && server.ready?
end

#serverObject




45
46
47
# File 'lib/coral/machine/fog.rb', line 45

def server
  return get(:server)
end

#start(options = {}) ⇒ Object




130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/coral/machine/fog.rb', line 130

def start(options = {})
  success = super(options)
  if success
    unless created?
      return create(options)
    end
    unless running?
      server_info = compute.servers.create(options)
    
      Fog.wait_for do
        compute.servers.get(server_info.id).ready? ? true : false
      end      
      @server = compute.servers.get(server_info.id)
    end
  end
  return success
end

#stateObject




70
71
72
73
# File 'lib/coral/machine/fog.rb', line 70

def state
  return server.state if server
  return nil
end

#stop(options = {}) ⇒ Object




150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/coral/machine/fog.rb', line 150

def stop(options = {})
  success = super(options)
  if success && running?
    if image_id = create_image(name)
    
      Fog.wait_for do
        compute.images.get(image_id).ready? ? true : false
      end
    
      server.destroy
      return image_id
    end
  end
  return success
end