Class: Fog::Compute::Ninefold::Server
- Inherits:
-
Server
- Object
- Server
- Fog::Compute::Ninefold::Server
- Extended by:
- Deprecation
- Defined in:
- lib/fog/ninefold/models/compute/server.rb
Instance Method Summary collapse
- #destroy ⇒ Object
- #flavor ⇒ Object
- #image ⇒ Object
-
#initialize(attributes = {}) ⇒ Server
constructor
attribute :account_id, :aliases => “account”, :squash => “id” attribute :image_id, :aliases => “image”, :squash => “id” attribute :flavor_id, :aliases => “server_type”, :squash => “id” attribute :zone_id, :aliases => “zone”, :squash => “id”.
-
#ipaddress ⇒ Object
This is temporary - we need to model nics.
- #ready? ⇒ Boolean
- #reboot ⇒ Object
- #save ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Server
attribute :account_id, :aliases => “account”, :squash => “id” attribute :image_id, :aliases => “image”, :squash => “id” attribute :flavor_id, :aliases => “server_type”, :squash => “id” attribute :zone_id, :aliases => “zone”, :squash => “id”
68 69 70 71 72 73 74 |
# File 'lib/fog/ninefold/models/compute/server.rb', line 68 def initialize(attributes={}) merge_attributes({ :flavor_id => 105, # '1CPU, 384MB, 80GB HDD' :image_id => 421 # 'XEN Basic Ubuntu 10.04 Server x64 PV r2.0' }) super end |
Instance Method Details
#destroy ⇒ Object
100 101 102 103 104 |
# File 'lib/fog/ninefold/models/compute/server.rb', line 100 def destroy requires :identity self.jobid = extract_job_id(service.destroy_virtual_machine(:id => identity)) true end |
#flavor ⇒ Object
106 107 108 109 |
# File 'lib/fog/ninefold/models/compute/server.rb', line 106 def flavor requires :flavor_id service.flavors.get(flavor_id) end |
#image ⇒ Object
111 112 113 114 |
# File 'lib/fog/ninefold/models/compute/server.rb', line 111 def image requires :image_id service.images.get(image_id) end |
#ipaddress ⇒ Object
This is temporary - we need to model nics.
77 78 79 |
# File 'lib/fog/ninefold/models/compute/server.rb', line 77 def ipaddress nic[0] ? nic[0]['ipaddress'] : nil end |
#ready? ⇒ Boolean
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/fog/ninefold/models/compute/server.rb', line 116 def ready? if jobid # we do this by polling the last job id status. res = service.query_async_job_result(:jobid => jobid) if res['jobstatus'] == 0 false else # update with new values. merge_attributes(res['jobresult']['virtualmachine']) true end else # No running job, we are ready. Refresh data. reload true end end |
#reboot ⇒ Object
81 82 83 84 85 86 |
# File 'lib/fog/ninefold/models/compute/server.rb', line 81 def reboot requires :identity self.jobid = extract_job_id(service.reboot_virtual_machine(:id => identity)) puts "jobid: " + jobid.to_s true end |
#save ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/fog/ninefold/models/compute/server.rb', line 133 def save raise "Operation not supported" if self.identity requires :flavor_id, :image_id, :zoneid unless networkids # No network specified, use first in this zone. networks = service.list_networks(:zoneid => zoneid) if networks.empty? raise "No networks. Please create one, or specify a network ID" else # use the network with the lowest ID - the safe default self.networkids = networks.sort {|x,y| x['id'] <=> y['id']}[0]['id'] end end = { :serviceofferingid => flavor_id, :templateid => image_id, :name => name, :zoneid => zoneid, :networkids => networkids, :account => account, :diskofferingid => diskofferingid, :displayname => displayname, :domainid => domainid, :group => group, :hypervisor => hypervisor, :keypair => keypair, :securitygroupids => securitygroupids, :size => size, :userdata => userdata }.delete_if {|k,v| v.nil? || v == "" } data = service.deploy_virtual_machine() merge_attributes(data) true end |
#start ⇒ Object
88 89 90 91 92 |
# File 'lib/fog/ninefold/models/compute/server.rb', line 88 def start requires :identity self.jobid = extract_job_id(service.start_virtual_machine(:id => identity)) true end |
#stop ⇒ Object
94 95 96 97 98 |
# File 'lib/fog/ninefold/models/compute/server.rb', line 94 def stop requires :identity self.jobid = extract_job_id(service.stop_virtual_machine(:id => identity)) true end |