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



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

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

#imageObject



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

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

#private_ip_addressObject



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

def private_ip_address
  ip = nil
  if self.network_interfaces.respond_to? :first
    ip = self.network_interfaces.first['networkIP']
  end
  ip
end

#public_ip_addressObject



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

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

  ip
end

#ready?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/fog/google/models/compute/server.rb', line 56

def ready?
  self.state == RUNNING
end

#reloadObject



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

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

#saveObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fog/google/models/compute/server.rb', line 75

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,
      'network' => network,
      'externalIp' => external_ip,
      '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



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

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