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
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#connection, #connection=, #prepare_service_value
#_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
#add_ssh_key(username, key) ⇒ Object
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 70
def add_ssh_key username, key
if self.metadata.nil?
self.metadata = Hash.new("")
end
if !self.metadata["sshKeys"]
self.metadata["sshKeys"] = ""
end
if !self.metadata["sshKeys"].empty?
self.metadata["sshKeys"] += "\n"
end
self.metadata["sshKeys"] += "#{username}:#{key.strip}"
return self.metadata
end
|
#destroy ⇒ Object
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
|
#image ⇒ Object
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_address ⇒ Object
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_address ⇒ Object
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
56
57
58
|
# File 'lib/fog/google/models/compute/server.rb', line 56
def ready?
self.state == RUNNING
end
|
#reload ⇒ Object
91
92
93
94
|
# File 'lib/fog/google/models/compute/server.rb', line 91
def reload
data = service.get_server(self.name, self.zone).body
self.merge_attributes(data)
end
|
#save ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/fog/google/models/compute/server.rb', line 96
def save
requires :name
requires :machine_type
requires :zone_name
if not service.zones.find{ |zone| zone.name == self.zone_name }
raise ArgumentError.new "#{self.zone_name.inspect} is either down or you don't have permission to use it."
end
self.add_ssh_key(self.username, self.public_key) if self.public_key
options = {
'image' => image_name,
'machineType' => machine_type,
'networkInterfaces' => network_interfaces,
'network' => network,
'externalIp' => external_ip,
'disks' => disks,
'kernel' => kernel,
'metadata' => metadata
}.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
|
#zone ⇒ Object
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
|