Class: Coral::Plugin::Node

Inherits:
Base show all
Defined in:
lib/coral_core/plugin/node.rb

Direct Known Subclasses

Node::Rackspace

Instance Attribute Summary

Attributes inherited from Core

#ui

Instance Method Summary collapse

Methods inherited from Base

build_info, ensure_plugin_collection, #initialize, #initialized?, #meta, #method_missing, #name, #name=, #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 Mixin::ConfigOptions

#clear_options, #contexts, #get_options, #set_options

Methods included from Mixin::ConfigCollection

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

Methods included from Mixin::Lookup

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

Methods included from 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

#create_image(options = {}) ⇒ Object




174
175
176
177
# File 'lib/coral_core/plugin/node.rb', line 174

def create_image(options = {})
  return true unless machine && machine.running?    
  return machine.create_image(options)  
end

#create_machine(provider, options = {}) ⇒ Object




70
71
72
73
74
75
# File 'lib/coral_core/plugin/node.rb', line 70

def create_machine(provider, options = {})
  if provider.is_a?(String) || provider.is_a?(Symbol)
    set(:machine, Coral.machine(options, provider))
  end
  return self
end

#delete_setting(property) ⇒ Object




51
52
53
54
# File 'lib/coral_core/plugin/node.rb', line 51

def delete_setting(property)
  network.delete_node_setting(plugin_provider, name, property)
  return self
end

#destroy(options = {}) ⇒ Object




129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/coral_core/plugin/node.rb', line 129

def destroy(options = {})    
  return true unless machine
  
  config = Config.ensure(options)
  
  if machine.created?
    run = false

    if config[:force]
      run = true
    else
      choice = nil
      begin
        choice = ui.ask("Are you sure you want to remove: #{name}?")
        run    = choice.upcase == "Y"
      rescue Errors::UIExpectsTTY
        run = false
      end        
    end

    if run
      return machine.destroy(config)
    end
  end
  return true    
end

#exec(commands, options = {}) ⇒ Object




158
159
160
161
162
163
# File 'lib/coral_core/plugin/node.rb', line 158

def exec(commands, options = {})
  return true unless machine && machine.running?
  
  config = Config.ensure(options)        
  return machine.exec(config.import({ :commands => commands }))  
end

#hostnameObject




93
94
95
96
# File 'lib/coral_core/plugin/node.rb', line 93

def hostname # Must be set at machine level
  return machine.hostname if machine
  return ''
end

#machineObject




58
59
60
# File 'lib/coral_core/plugin/node.rb', line 58

def machine
  return get(:machine, nil)
end

#machine=(machine) ⇒ Object




64
65
66
# File 'lib/coral_core/plugin/node.rb', line 64

def machine=machine
  set(:machine, machine)  
end

#networkObject


Property accessors / modifiers



20
21
22
# File 'lib/coral_core/plugin/node.rb', line 20

def network
  return plugin_parent
end

#network=(network) ⇒ Object




26
27
28
# File 'lib/coral_core/plugin/node.rb', line 26

def network=network
  self.plugin_parent = network
end

#normalizeObject


Node plugin interface



9
10
11
# File 'lib/coral_core/plugin/node.rb', line 9

def normalize
  super
end

#private_ipObject




86
87
88
89
# File 'lib/coral_core/plugin/node.rb', line 86

def private_ip # Must be set at machine level
  return machine.private_ip if machine
  return nil
end

#provision(options = {}) ⇒ Object




167
168
169
170
# File 'lib/coral_core/plugin/node.rb', line 167

def provision(options = {})
  return true unless machine && machine.running?    
  return machine.provision(options)  
end

#public_ipObject




79
80
81
82
# File 'lib/coral_core/plugin/node.rb', line 79

def public_ip # Must be set at machine level
  return machine.public_ip if machine
  return nil
end

#reload(options = {}) ⇒ Object




122
123
124
125
# File 'lib/coral_core/plugin/node.rb', line 122

def reload(options = {})
  return true unless machine && machine.created?    
  return machine.reload(options)
end

#search(property, default = nil, format = false) ⇒ Object




38
39
40
# File 'lib/coral_core/plugin/node.rb', line 38

def search(property, default = nil, format = false)
  return network.search_node(plugin_provider, name, property, default, format)
end

#set_setting(property, value = nil) ⇒ Object




44
45
46
47
# File 'lib/coral_core/plugin/node.rb', line 44

def set_setting(property, value = nil)
  network.set_node_setting(plugin_provider, name, property, value)
  return self
end

#setting(property, default = nil, format = false) ⇒ Object




32
33
34
# File 'lib/coral_core/plugin/node.rb', line 32

def setting(property, default = nil, format = false)
  return network.node_setting(plugin_provider, name, property, default, format)
end

#start(options = {}) ⇒ Object


Machine operations



108
109
110
111
# File 'lib/coral_core/plugin/node.rb', line 108

def start(options = {})
  return true unless machine
  return machine.start(options)
end

#stateObject




100
101
102
103
# File 'lib/coral_core/plugin/node.rb', line 100

def state # Must be set at machine level
  return machine.state if machine
  return nil
end

#stop(options = {}) ⇒ Object




115
116
117
118
# File 'lib/coral_core/plugin/node.rb', line 115

def stop(options = {})
  return true unless machine && machine.running?    
  return machine.stop(options)
end