Class: Fog::Bluebox::Compute::Server
- Inherits:
-
Model
- Object
- Model
- Fog::Bluebox::Compute::Server
show all
- Defined in:
- lib/fog/compute/models/bluebox/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.
27
28
29
30
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 27
def initialize(attributes={})
self.flavor_id ||= '94fd37a7-2606-47f7-84d5-9000deda52ae'
super
end
|
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
24
25
26
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 24
def password
@password
end
|
#private_key ⇒ Object
57
58
59
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 57
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
|
#private_key_path ⇒ Object
52
53
54
55
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 52
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
70
71
72
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 70
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
|
#public_key_path ⇒ Object
65
66
67
68
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 65
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
|
#username ⇒ Object
130
131
132
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 130
def username
@username ||= 'deploy'
end
|
Instance Method Details
#destroy ⇒ Object
32
33
34
35
36
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 32
def destroy
requires :id
connection.destroy_block(id)
true
end
|
#flavor ⇒ Object
38
39
40
41
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 38
def flavor
requires :flavor_id
connection.flavors.get(flavor_id)
end
|
#image ⇒ Object
43
44
45
46
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 43
def image
requires :image_id
connection.images.get(image_id)
end
|
#private_ip_address ⇒ Object
48
49
50
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 48
def private_ip_address
nil
end
|
#public_ip_address ⇒ Object
61
62
63
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 61
def public_ip_address
ips.first
end
|
#ready? ⇒ Boolean
74
75
76
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 74
def ready?
status == 'running'
end
|
#reboot(type = 'SOFT') ⇒ Object
78
79
80
81
82
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 78
def reboot(type = 'SOFT')
requires :id
connection.reboot_block(id, type)
true
end
|
#save ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 84
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :flavor_id, :image_id
options = {}
if identity.nil? raise(ArgumentError, "password or public_key is required for this operation") if !password && !public_key
options['ssh_public_key'] = public_key if @public_key
options['password'] = password if @password
end
options['username'] = username
data = connection.create_block(flavor_id, image_id, options)
merge_attributes(data.body)
true
end
|
#scp(local_path, remote_path) ⇒ Object
122
123
124
125
126
127
128
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 122
def scp(local_path, remote_path)
requires :ips, :username
options = {}
options[:key_data] = [private_key] if private_key
Fog::SCP.new(ips.first['address'], username, options).upload(local_path, remote_path)
end
|
#setup(credentials = {}) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 101
def setup(credentials = {})
requires :identity, :ips, :public_key, :username
Fog::SSH.new(ips.first['address'], username, credentials).run([
%{mkdir .ssh},
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
%{passwd -l #{username}},
%{echo "#{attributes.to_json}" >> ~/attributes.json}
])
rescue Errno::ECONNREFUSED
sleep(1)
retry
end
|
#ssh(commands) ⇒ Object
114
115
116
117
118
119
120
|
# File 'lib/fog/compute/models/bluebox/server.rb', line 114
def ssh(commands)
requires :identity, :ips, :username
options = {}
options[:key_data] = [private_key] if private_key
Fog::SSH.new(ips.first['address'], username, options).run(commands)
end
|