Class: Fog::Compute::Google::Server

Inherits:
Server show all
Defined in:
lib/fog/google/models/compute/server.rb

Instance Attribute Summary

Attributes inherited from Server

#private_key, #private_key_path, #public_key, #public_key_path, #ssh_port, #username

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Server

#scp, #scp_download, #ssh

Methods inherited from Model

#initialize, #inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Model

Instance Method Details

#destroyObject



18
19
20
21
# File 'lib/fog/google/models/compute/server.rb', line 18

def destroy
  requires :name
  service.delete_server(name)
end

#imageObject



23
24
25
# File 'lib/fog/google/models/compute/server.rb', line 23

def image
  service.get_image(self.image_name.split('/')[-1])
end

#public_ip_addressObject



27
28
29
30
31
32
33
# File 'lib/fog/google/models/compute/server.rb', line 27

def public_ip_address
  if self.network_interfaces.count
    self.network_interfaces[0]["networkIP"]
  else
    nil
  end
end

#ready?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
# File 'lib/fog/google/models/compute/server.rb', line 35

def ready?
  data = service.get_server(self.name, self.zone_name).body
  data['zone_name'] = self.zone_name
  self.merge_attributes(data)
  self.state == RUNNING_STATE
end

#saveObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fog/google/models/compute/server.rb', line 46

def save
  requires :name
  requires :image_name
  requires :machine_type
  requires :zone_name

  data = service.insert_server(
    name,
    image_name,
    zone_name,
    machine_type)

  data = service.get_server(self.name, self.zone_name).body
  service.servers.merge_attributes(data)
end

#setup(credentials = {}) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/fog/google/models/compute/server.rb', line 62

def setup(credentials = {})
  requires :public_ip_address, :public_key, :username
  service.(self.instance, self.zone, {'sshKeys' => self.public_key })
rescue Errno::ECONNREFUSED
  sleep(1)
  retry
end

#sshable?(options = {}) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
74
75
# File 'lib/fog/google/models/compute/server.rb', line 70

def sshable?(options={})
  service.(self.instance, self.zone, {'sshKeys' => self.public_key })
  ready? && !public_ip_address.nil? && public_key && ['sshKeys']
rescue SystemCallError, Net::SSH::AuthenticationFailed, Timeout::Error
  false
end

#zoneObject



42
43
44
# File 'lib/fog/google/models/compute/server.rb', line 42

def zone
  service.get_zone(self.zone_name.split('/')[-1])
end