Class: Hazetug::Haze

Inherits:
Object
  • Object
show all
Includes:
NetSSH::Mixin, UI::Mixin
Defined in:
lib/hazetug/haze.rb,
lib/hazetug/haze/linode.rb,
lib/hazetug/haze/cloud_server.rb,
lib/hazetug/haze/digital_ocean.rb

Direct Known Subclasses

DigitalOcean, Linode

Defined Under Namespace

Modules: CloudServer Classes: DigitalOcean, Linode

Constant Summary collapse

RE_BITS =
/-?x(32)$|-?x(64)$|(32)bit|(64)bit/i

Constants included from NetSSH::Mixin

NetSSH::Mixin::NET_SSH_OPTIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UI::Mixin

included

Constructor Details

#initialize(config = {}) ⇒ Haze

Returns a new instance of Haze.



17
18
19
20
21
22
23
# File 'lib/hazetug/haze.rb', line 17

def initialize(config={})
  @compute_name = Hazetug.leaf_klass_name(self.class)
  @compute = Hazetug::Compute.const_get(compute_name).new
  @config  = configure(config)
  @server  = nil
  @ready   = false
end

Instance Attribute Details

#compute_nameObject (readonly)

Returns the value of attribute compute_name.



13
14
15
# File 'lib/hazetug/haze.rb', line 13

def compute_name
  @compute_name
end

#configObject (readonly)

Returns the value of attribute config.



13
14
15
# File 'lib/hazetug/haze.rb', line 13

def config
  @config
end

Class Method Details

.[](haze_name) ⇒ Object



70
71
72
73
# File 'lib/hazetug/haze.rb', line 70

def [](haze_name)
  klass = Hazetug.camel_case_name(haze_name)
  Hazetug::Haze.const_get(klass)
end

.defaults(hash = nil) ⇒ Object



66
67
68
# File 'lib/hazetug/haze.rb', line 66

def defaults(hash=nil)
  hash.nil? ? @defaults : @defaults = hash
end

.requires(*args) ⇒ Object



62
63
64
# File 'lib/hazetug/haze.rb', line 62

def requires(*args)
  args.empty? ? @requires : @requires = args.flatten.dup
end

Instance Method Details

#private_ip_addressObject



45
46
# File 'lib/hazetug/haze.rb', line 45

def private_ip_address
end

#provisionObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hazetug/haze.rb', line 25

def provision
  provision_server
  wait_for_ssh
rescue Fog::Errors::Error
  # Catch fog errors, don't abort further execution
  ui.error "[#{compute_name}] #{$!.inspect}"
rescue
  # For unknown exceptions, notify and exit
  ui.error "[#{compute_name}] #{$!.inspect}"
  ui.msg $@
  exit(1)
end

#public_ip_addressObject



42
43
# File 'lib/hazetug/haze.rb', line 42

def public_ip_address
end

#ready?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/hazetug/haze.rb', line 38

def ready?
  @ready
end

#update_access_settings(hash) ⇒ Object

Update hash with haze access settings only if any available



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/hazetug/haze.rb', line 49

def update_access_settings(hash)
  {
    compute_name: compute_name.downcase,
    public_ip_address: (public_ip_address || 
        (server and server.ssh_ip_address)),
    private_ip_address: private_ip_address
  }.inject(hash) do |hsh, (k, v)|
    hsh[k] = v if v
    hsh
  end
end