Class: Fog::AWS::Compute::Server
- Inherits:
-
Model
- Object
- Model
- Fog::AWS::Compute::Server
show all
- Defined in:
- lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb
Instance Attribute Summary collapse
Attributes inherited from Model
#collection, #connection
Instance Method Summary
collapse
Methods inherited from Model
#inspect, #reload, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#_dump, #attributes, #identity, #identity=, #merge_attributes, #new_record?, #requires
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
42
43
44
45
46
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 42
def initialize(attributes={})
self.groups ||= ["default"] unless attributes[:subnet_id]
self.flavor_id ||= 'm1.small'
super
end
|
Instance Attribute Details
#architecture ⇒ Object
Returns the value of attribute architecture.
11
12
13
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 11
def architecture
@architecture
end
|
#instance_initiated_shutdown_behavior ⇒ Object
Returns the value of attribute instance_initiated_shutdown_behavior.
20
21
22
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 20
def instance_initiated_shutdown_behavior
@instance_initiated_shutdown_behavior
end
|
#password ⇒ Object
Returns the value of attribute password.
39
40
41
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 39
def password
@password
end
|
#private_key ⇒ Object
95
96
97
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 95
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
|
#private_key_path ⇒ Object
90
91
92
93
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 90
def private_key_path
@private_key_path ||= Fog.credentials[:private_key_path]
@private_key_path &&= File.expand_path(@private_key_path)
end
|
#public_key ⇒ Object
104
105
106
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 104
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
|
#public_key_path ⇒ Object
99
100
101
102
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 99
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
|
#username ⇒ Object
186
187
188
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 186
def username
@username ||= 'root'
end
|
Instance Method Details
#addresses ⇒ Object
48
49
50
51
52
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 48
def addresses
requires :id
connection.addresses(:server => self)
end
|
#console_output ⇒ Object
54
55
56
57
58
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 54
def console_output
requires :id
connection.get_console_output(id)
end
|
#destroy ⇒ Object
60
61
62
63
64
65
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 60
def destroy
requires :id
connection.terminate_instances(id)
true
end
|
#flavor ⇒ Object
76
77
78
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 76
def flavor
@flavor ||= connection.flavors.all.detect {|flavor| flavor.id == flavor_id}
end
|
#flavor=(new_flavor) ⇒ Object
72
73
74
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 72
def flavor=(new_flavor)
@flavor = new_flavor
end
|
#flavor_id ⇒ Object
68
69
70
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 68
def flavor_id
@flavor && @flavor.id || attributes[:flavor_id]
end
|
#key_pair ⇒ Object
80
81
82
83
84
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 80
def key_pair
requires :key_name
connection.keypairs.all(key_name).first
end
|
#key_pair=(new_keypair) ⇒ Object
86
87
88
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 86
def key_pair=(new_keypair)
key_name = new_keypair && new_keypair.name
end
|
#ready? ⇒ Boolean
108
109
110
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 108
def ready?
state == 'running'
end
|
#reboot ⇒ Object
112
113
114
115
116
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 112
def reboot
requires :id
connection.reboot_instances(id)
true
end
|
#save ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 118
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :image_id
options = {
'BlockDeviceMapping' => block_device_mapping,
'ClientToken' => client_token,
'InstanceInitiatedShutdownBehavior' => instance_initiated_shutdown_behavior,
'InstanceType' => flavor_id,
'KernelId' => kernel_id,
'KeyName' => key_name,
'Monitoring.Enabled' => monitoring,
'Placement.AvailabilityZone' => availability_zone,
'RamdiskId' => ramdisk_id,
'SecurityGroup' => groups,
'SubnetId' => subnet_id,
'UserData' => user_data
}
options.delete_if {|key, value| value.nil?}
if subnet_id
options.delete('SecurityGroup')
else
options.delete('SubnetId')
end
data = connection.run_instances(image_id, 1, 1, options)
merge_attributes(data.body['instancesSet'].first)
true
end
|
#setup(credentials = {}) ⇒ Object
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 152
def setup(credentials = {})
requires :identity, :ip_address, :username
sleep(10)
commands = [
%{mkdir .ssh},
%{passwd -l root},
%{echo "#{attributes.to_json}" >> ~/attributes.json}
]
if public_key
commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys}
end
Fog::SSH.new(ip_address, username, credentials).run(commands)
rescue Errno::ECONNREFUSED => e
sleep(1)
retry
end
|
#ssh(commands) ⇒ Object
169
170
171
172
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 169
def ssh(commands)
requires :identity, :ip_address, :private_key, :username
Fog::SSH.new(ip_address, username, :key_data => [private_key]).run(commands)
end
|
#start ⇒ Object
174
175
176
177
178
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 174
def start
requires :id
connection.start_instances(id)
true
end
|
#stop ⇒ Object
180
181
182
183
184
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 180
def stop
requires :id
connection.stop_instances(id)
true
end
|
#volumes ⇒ Object
190
191
192
193
|
# File 'lib/bbcloud/vendor/fog-0.3.23/lib/fog/aws/models/compute/server.rb', line 190
def volumes
requires :id
connection.volumes(:server => self)
end
|