2012-02-10 10:10:49 -05:00
|
|
|
require 'fog/compute/models/server'
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Joyent
|
|
|
|
|
|
|
|
class Server < Fog::Compute::Server
|
|
|
|
identity :id
|
|
|
|
|
|
|
|
attribute :name
|
|
|
|
attribute :state
|
|
|
|
attribute :type
|
|
|
|
attribute :dataset
|
|
|
|
attribute :ips
|
|
|
|
attribute :memory
|
|
|
|
attribute :disk
|
|
|
|
attribute :metadata
|
2013-05-19 06:35:55 -04:00
|
|
|
attribute :tags
|
2012-02-10 10:10:49 -05:00
|
|
|
|
|
|
|
attribute :created, :type => :time
|
|
|
|
attribute :updated, :type => :time
|
|
|
|
|
2012-10-03 06:49:55 -04:00
|
|
|
def public_ip_address
|
|
|
|
ips.empty? ? nil : ips.first
|
|
|
|
end
|
|
|
|
|
2012-02-10 10:10:49 -05:00
|
|
|
def ready?
|
|
|
|
self.state == 'running'
|
|
|
|
end
|
|
|
|
|
|
|
|
def stopped?
|
|
|
|
requires :id
|
|
|
|
self.state == 'stopped'
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
requires :id
|
2012-12-22 18:25:50 -05:00
|
|
|
service.delete_machine(id)
|
2012-02-10 10:10:49 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def start
|
|
|
|
requires :id
|
2012-12-22 18:25:50 -05:00
|
|
|
service.start_machine(id)
|
2012-02-10 10:10:49 -05:00
|
|
|
self.wait_for { ready? }
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop
|
|
|
|
requires :id
|
2012-12-22 18:25:50 -05:00
|
|
|
service.stop_machine(id)
|
2012-02-10 10:10:49 -05:00
|
|
|
self.wait_for { stopped? }
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def resize(flavor)
|
|
|
|
requires :id
|
2013-02-21 17:09:18 -05:00
|
|
|
service.resize_machine(id, flavor.name)
|
2012-02-10 10:10:49 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def reboot
|
|
|
|
requires :id
|
2012-12-22 18:25:50 -05:00
|
|
|
service.reboot_machine(id)
|
2012-02-10 10:10:49 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def snapshots
|
|
|
|
requires :id
|
2012-12-22 18:25:50 -05:00
|
|
|
service.snapshots.all(id)
|
2012-02-10 10:10:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def update_metadata(data = {})
|
|
|
|
requires :id
|
2012-12-22 18:25:50 -05:00
|
|
|
service.update_machine_metadata(self.id, data)
|
2012-02-10 10:10:49 -05:00
|
|
|
self.reload
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_metadata(keyname)
|
|
|
|
raise ArgumentError, "Must provide a key name to delete" if keyname.nil? || keyname.empty?
|
|
|
|
requires :id
|
|
|
|
|
2012-12-22 18:25:50 -05:00
|
|
|
service.delete_machine_metadata(self.id, keyname)
|
2012-02-10 10:10:49 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_all_metadata
|
|
|
|
requires :id
|
2012-12-22 18:25:50 -05:00
|
|
|
service.delete_all_machine_metadata(self.id)
|
2012-02-10 10:10:49 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2013-05-19 06:35:55 -04:00
|
|
|
def list_tags
|
2012-02-10 10:10:49 -05:00
|
|
|
requires :id
|
2012-12-22 18:25:50 -05:00
|
|
|
service.list_machine_tags(id).body
|
2012-02-10 10:10:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_tags(tags_hash = {})
|
|
|
|
requires :id
|
2012-12-22 18:25:50 -05:00
|
|
|
service.add_machine_tags(self.id, tags_hash).body
|
2012-02-10 10:10:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def delete_tag(tagname)
|
|
|
|
requires :id
|
|
|
|
|
|
|
|
raise ArgumentError, "Must provide a tag name to delete" if tagname.nil? || tagname.empty?
|
2012-12-22 18:25:50 -05:00
|
|
|
service.delete_machine_tag(self.id, tagname)
|
2012-02-10 10:10:49 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_all_tags
|
|
|
|
requires :id
|
|
|
|
|
2012-12-22 18:25:50 -05:00
|
|
|
service.delete_all_machine_tags(self.id)
|
2012-02-10 10:10:49 -05:00
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|