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_options, #ssh_port, #username

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Server

#scp, #scp_download, #ssh, #sshable?

Methods inherited from Model

#initialize, #inspect, #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



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

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

#imageObject



25
26
27
# File 'lib/fog/google/models/compute/server.rb', line 25

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

#public_ip_addressObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fog/google/models/compute/server.rb', line 29

def public_ip_address
  ip = nil
  if self.network_interfaces
    self.network_interfaces.each do |netif|
      netif["accessConfigs"].each do |access_config|
        if access_config["name"] == "External NAT"
          ip = access_config['natIP']
        end
      end
    end
  end

  ip
end

#ready?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/fog/google/models/compute/server.rb', line 44

def ready?
  self.state == RUNNING
end

#reloadObject



58
59
60
61
# File 'lib/fog/google/models/compute/server.rb', line 58

def reload
  data = service.get_server(self.name, self.zone).body
  self.merge_attributes(data)
end

#saveObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/fog/google/models/compute/server.rb', line 63

def save
  requires :name
  requires :machine_type
  requires :zone_name

  if self..nil?
    self. = {}
  end

  self..merge!({
    "sshKeys" => "#{username}:#{public_key.strip}"
  }) if public_key

  options = {
      'image' => image_name,
      'machineType' => machine_type,
      'networkInterfaces' => network_interfaces,
      'disks' => disks,
      'kernel' => kernel,
      'metadata' => 
  }
  options.delete_if {|key, value| value.nil?}
  service.insert_server(name, zone_name, options)
  data = service.backoff_if_unfound {service.get_server(self.name, self.zone_name).body}
  service.servers.merge_attributes(data)
end

#zoneObject



48
49
50
51
52
53
54
55
56
# File 'lib/fog/google/models/compute/server.rb', line 48

def zone
  if self.zone_name.is_a? String
    service.get_zone(self.zone_name.split('/')[-1]).body["name"]
  elsif zone_name.is_a? Excon::Response
    service.get_zone(zone_name.body["name"]).body["name"]
  else
    self.zone_name
  end
end