Class: Fog::Compute::Bluebox::Server
- Inherits:
-
Server
show all
- Defined in:
- lib/fog/bluebox/models/compute/server.rb
Instance Attribute Summary collapse
Attributes inherited from Model
#collection, #connection
Instance Method Summary
collapse
Methods inherited from Server
#scp, #scp_download, #ssh
Methods inherited from Model
#inspect, #reload, #symbolize_keys, #to_json, #wait_for
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
28
29
30
31
32
33
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 28
def initialize(attributes={})
self.flavor_id ||= '94fd37a7-2606-47f7-84d5-9000deda52ae' self.image_id ||= 'a8f05200-7638-47d1-8282-2474ef57c4c3' self.location_id ||= '37c2bd9a-3e81-46c9-b6e2-db44a25cc675' super
end
|
Instance Attribute Details
#hostname ⇒ Object
Returns the value of attribute hostname.
25
26
27
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 25
def hostname
@hostname
end
|
#lb_applications ⇒ Object
Returns the value of attribute lb_applications.
25
26
27
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 25
def lb_applications
@lb_applications
end
|
#lb_backends ⇒ Object
Returns the value of attribute lb_backends.
25
26
27
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 25
def lb_backends
@lb_backends
end
|
#lb_services ⇒ Object
Returns the value of attribute lb_services.
25
26
27
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 25
def lb_services
@lb_services
end
|
#password ⇒ Object
Returns the value of attribute password.
25
26
27
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 25
def password
@password
end
|
#private_key ⇒ Object
65
66
67
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 65
def private_key
@private_key ||= private_key_path && File.read(private_key_path)
end
|
#private_key_path ⇒ Object
60
61
62
63
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 60
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
78
79
80
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 78
def public_key
@public_key ||= public_key_path && File.read(public_key_path)
end
|
#public_key_path ⇒ Object
73
74
75
76
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 73
def public_key_path
@public_key_path ||= Fog.credentials[:public_key_path]
@public_key_path &&= File.expand_path(@public_key_path)
end
|
#username ⇒ Object
131
132
133
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 131
def username
@username ||= 'deploy'
end
|
Instance Method Details
#destroy ⇒ Object
35
36
37
38
39
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 35
def destroy
requires :id
connection.destroy_block(id)
true
end
|
#flavor ⇒ Object
41
42
43
44
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 41
def flavor
requires :flavor_id
connection.flavors.get(flavor_id)
end
|
#image ⇒ Object
46
47
48
49
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 46
def image
requires :image_id
connection.images.get(image_id)
end
|
#location ⇒ Object
51
52
53
54
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 51
def location
requires :location_id
connection.locations.get(location_id)
end
|
#private_ip_address ⇒ Object
56
57
58
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 56
def private_ip_address
nil
end
|
#public_ip_address ⇒ Object
69
70
71
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 69
def public_ip_address
ips.first
end
|
#ready? ⇒ Boolean
82
83
84
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 82
def ready?
self.state == 'running'
end
|
#reboot(type = 'SOFT') ⇒ Object
86
87
88
89
90
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 86
def reboot(type = 'SOFT')
requires :id
connection.reboot_block(id, type)
true
end
|
#save ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 92
def save
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
requires :flavor_id, :image_id, :location_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
if @lb_backends
options['lb_backends'] = lb_backends
elsif @lb_services
options['lb_services'] = lb_services
elsif @lb_applications
options['lb_applications'] = lb_applications
end
options['username'] = username
options['hostname'] = hostname if @hostname
data = connection.create_block(flavor_id, image_id, location_id, options)
merge_attributes(data.body)
true
end
|
#setup(credentials = {}) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/fog/bluebox/models/compute/server.rb', line 118
def setup(credentials = {})
requires :identity, :ips, :public_key, :username
Fog::SSH.new(public_ip_address, username, credentials).run([
%{mkdir .ssh},
%{echo "#{public_key}" >> ~/.ssh/authorized_keys},
%{passwd -l #{username}},
%{echo "#{MultiJson.encode(attributes)}" >> ~/attributes.json}
])
rescue Errno::ECONNREFUSED
sleep(1)
retry
end
|