Class: Fog::Compute::Bluebox::Server
- Defined in:
- lib/fog/bluebox/models/compute/server.rb
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#lb_applications ⇒ Object
Returns the value of attribute lb_applications.
-
#lb_backends ⇒ Object
Returns the value of attribute lb_backends.
-
#lb_services ⇒ Object
Returns the value of attribute lb_services.
-
#password ⇒ Object
Returns the value of attribute password.
Attributes inherited from Server
#private_key, #private_key_path, #public_key, #public_key_path
Attributes inherited from Model
Instance Method Summary collapse
- #destroy ⇒ Object
- #flavor ⇒ Object
- #image ⇒ Object
-
#initialize(attributes = {}) ⇒ Server
constructor
A new instance of Server.
- #location ⇒ Object
- #private_ip_address ⇒ Object
- #public_ip_address ⇒ Object
- #ready? ⇒ Boolean
- #reboot(type = 'SOFT') ⇒ Object
- #save ⇒ Object
- #setup(credentials = {}) ⇒ Object
- #username ⇒ Object
Methods inherited from Server
#scp, #scp_download, #ssh, #ssh_port, #sshable?
Methods inherited from Model
#inspect, #reload, #symbolize_keys, #to_json, #wait_for
Methods included from Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #requires, #requires_one
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
27 28 29 30 31 32 |
# File 'lib/fog/bluebox/models/compute/server.rb', line 27 def initialize(attributes={}) self.flavor_id ||= '94fd37a7-2606-47f7-84d5-9000deda52ae' # Block 1GB Virtual Server self.image_id ||= 'a8f05200-7638-47d1-8282-2474ef57c4c3' # Scientific Linux 6 self.location_id ||= '37c2bd9a-3e81-46c9-b6e2-db44a25cc675' # Seattle, WA 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 |
Instance Method Details
#destroy ⇒ Object
34 35 36 37 38 |
# File 'lib/fog/bluebox/models/compute/server.rb', line 34 def destroy requires :id connection.destroy_block(id) true end |
#flavor ⇒ Object
40 41 42 43 |
# File 'lib/fog/bluebox/models/compute/server.rb', line 40 def flavor requires :flavor_id connection.flavors.get(flavor_id) end |
#image ⇒ Object
45 46 47 48 |
# File 'lib/fog/bluebox/models/compute/server.rb', line 45 def image requires :image_id connection.images.get(image_id) end |
#location ⇒ Object
50 51 52 53 |
# File 'lib/fog/bluebox/models/compute/server.rb', line 50 def location requires :location_id connection.locations.get(location_id) end |
#private_ip_address ⇒ Object
55 56 57 |
# File 'lib/fog/bluebox/models/compute/server.rb', line 55 def private_ip_address nil end |
#public_ip_address ⇒ Object
59 60 61 |
# File 'lib/fog/bluebox/models/compute/server.rb', line 59 def public_ip_address ips.first end |
#ready? ⇒ Boolean
63 64 65 |
# File 'lib/fog/bluebox/models/compute/server.rb', line 63 def ready? self.state == 'running' end |
#reboot(type = 'SOFT') ⇒ Object
67 68 69 70 71 |
# File 'lib/fog/bluebox/models/compute/server.rb', line 67 def reboot(type = 'SOFT') requires :id connection.reboot_block(id, type) true end |
#save ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fog/bluebox/models/compute/server.rb', line 73 def save raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity requires :flavor_id, :image_id, :location_id = {} if identity.nil? # new record raise(ArgumentError, "password or public_key is required for this operation") if !password && !public_key ['ssh_public_key'] = public_key if public_key ['password'] = password if @password end if @lb_backends ['lb_backends'] = lb_backends elsif @lb_services ['lb_services'] = lb_services elsif @lb_applications ['lb_applications'] = lb_applications end ['username'] = username ['hostname'] = hostname if @hostname data = connection.create_block(flavor_id, image_id, location_id, ) merge_attributes(data.body) true end |
#setup(credentials = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/fog/bluebox/models/compute/server.rb', line 99 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 "#{Fog::JSON.encode(attributes)}" >> ~/attributes.json} ]) rescue Errno::ECONNREFUSED sleep(1) retry end |
#username ⇒ Object
112 113 114 |
# File 'lib/fog/bluebox/models/compute/server.rb', line 112 def username @username ||= 'deploy' end |