Class: Fog::Compute::QingCloud::Server
- Inherits:
-
Server
- Object
- Server
- Fog::Compute::QingCloud::Server
- Extended by:
- Deprecation
- Defined in:
- lib/fog/qingcloud/models/compute/server.rb
Instance Method Summary collapse
- #addresses ⇒ Object
- #changing? ⇒ Boolean
- #destroy ⇒ Object
- #flavor ⇒ Object
- #flavor=(new_flavor) ⇒ Object
- #flavor_id ⇒ Object (also: #instance_type)
- #image ⇒ Object
-
#initialize(attributes = {}) ⇒ Server
constructor
A new instance of Server.
- #join_vxnet(vxnet) ⇒ Object
- #key_pair ⇒ Object
- #key_pair=(key_id) ⇒ Object
- #leave_vxnet(vxnet) ⇒ Object
- #mac_addresses ⇒ Object
- #modify_attributes(name, description) ⇒ Object
- #nics ⇒ Object
- #private_ips ⇒ Object
- #ready? ⇒ Boolean
- #reboot(wait = false) ⇒ Object
- #reset ⇒ Object
- #resize(target_instance_type = nil, cpu = nil, memory = nil) ⇒ Object
- #save ⇒ Object
- #security_groups ⇒ Object
- #setup(credentials = {}) ⇒ Object
- #start(wait = false) ⇒ Object
- #stop(wait = false, force = false) ⇒ Object
- #volumes ⇒ Object
- #wait_for(&block) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Server
Returns a new instance of Server.
33 34 35 36 37 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 33 def initialize(attributes={}) prepare_service_value(attributes) self.image_id ||= 'centos64x64a' super end |
Instance Method Details
#addresses ⇒ Object
39 40 41 42 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 39 def addresses requires :id service.addresses(:server => self) end |
#changing? ⇒ Boolean
82 83 84 85 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 82 def changing? respond_to?(:transition_status) && transition_status && !transition_status.empty? end |
#destroy ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 44 def destroy requires :id service.terminate_instances(id) true rescue Fog::QingCloud::Errors::PermissionDenied => e raise e unless e. =~ /has already been deleted/i true end |
#flavor ⇒ Object
65 66 67 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 65 def flavor @flavor ||= service.flavors.all.detect {|flavor| flavor.id == flavor_id} end |
#flavor=(new_flavor) ⇒ Object
58 59 60 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 58 def flavor=(new_flavor) @flavor = new_flavor end |
#flavor_id ⇒ Object Also known as: instance_type
54 55 56 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 54 def flavor_id @flavor && @flavor.id || attributes[:flavor_id] end |
#image ⇒ Object
206 207 208 209 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 206 def image requires :id service.images.get(image_id) end |
#join_vxnet(vxnet) ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 130 def join_vxnet(vxnet) vxnet_id = vxnet.respond_to?(:id) ? vxnet : service.vxnets.get(vxnet) vxnet_ids ||= [] if persisted? service.join_vxnet(vxnet_id, id) @modified = true end vxnet_ids |= [vxnet_id] end |
#key_pair ⇒ Object
69 70 71 72 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 69 def key_pair requires :keypair_ids service.key_pairs.all(keypair_ids).first end |
#key_pair=(key_id) ⇒ Object
74 75 76 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 74 def key_pair=(key_id) keypair_ids << key_id end |
#leave_vxnet(vxnet) ⇒ Object
140 141 142 143 144 145 146 147 148 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 140 def leave_vxnet(vxnet) vxnet_id = vxnet.respond_to?(:id) ? vxnet.id : vxnet vxnet_ids ||= [] if persisted? service.leave_vxnet(vxnet_id, id) @modified = true end vxnet_ids.delete(vxnet_id) end |
#mac_addresses ⇒ Object
217 218 219 220 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 217 def mac_addresses requires :id nics.map { |x| x.nic_id } end |
#modify_attributes(name, description) ⇒ Object
232 233 234 235 236 237 238 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 232 def modify_attributes(name, description) requires :id raise Fog::QingCloud::Errors::CommonClientError, "name or description must be specified" unless name || description service.modify_resource_attributes(id, 'instance', name, description) merge_attributes('instance_name' => name, 'description' => description) true end |
#nics ⇒ Object
211 212 213 214 215 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 211 def nics requires :id reload if @modified vxnets.map {|x| OpenStruct.new(x)} end |
#private_ips ⇒ Object
222 223 224 225 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 222 def private_ips requires :id nics.map{|x| x.private_ip} end |
#ready? ⇒ Boolean
78 79 80 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 78 def ready? status == 'running' end |
#reboot(wait = false) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 87 def reboot(wait = false) requires :id service.reboot_instances(id) wait_for { status == 'running' and !changing? } if wait true end |
#reset ⇒ Object
157 158 159 160 161 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 157 def reset requires :id service.reset_instances(id) true end |
#resize(target_instance_type = nil, cpu = nil, memory = nil) ⇒ Object
150 151 152 153 154 155 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 150 def resize(target_instance_type = nil, cpu = nil, memory = nil) requires :id service.resize_instances(id, target_instance_type, cpu, memory) reload true end |
#save ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 94 def save if persisted? modify_attributes(name, description) else requires :image_id requires :flavor_id = { 'instance_type' => flavor_id, 'login_keypair' => [*keypair_ids].first, 'login_mode' => 'keypair', 'security_group' => security_group, 'instance_name' => name, 'vxnets' => vxnet_ids } if userdata_value if userdata_type == 'plain' ['userdata_value'] = Base64.encode64(userdata_value) elsif userdata_type == 'tar' = service.( 'attachment_content' => Base64.encode64(userdata_value), 'attachment_name' => 'userdata-tar' ).body['attachment_id'] ['userdata_value'] = end ['need_userdata'] = 1 ['userdata_type'] = userdata_type end self.id = service.run_instances(image_id, 1, ).body['instances'].first wait_for {ready?} end true end |
#security_groups ⇒ Object
201 202 203 204 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 201 def security_groups requires :id service.security_groups(:server => self) end |
#setup(credentials = {}) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 163 def setup(credentials = {}) requires :ssh_ip_address, :username require 'net/ssh' commands = [ %{mkdir .ssh}, %{passwd -l #{username}}, %{echo "#{Fog::JSON.encode(Fog::JSON.sanitize(attributes))}" >> ~/attributes.json} ] if public_key commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys} end # wait for qingcloud to be ready wait_for { sshable?(credentials) } Fog::SSH.new(ssh_ip_address, username, credentials).run(commands) end |
#start(wait = false) ⇒ Object
182 183 184 185 186 187 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 182 def start(wait = false) requires :id service.start_instances(id) wait_for { status == 'running' and !changing? } if wait true end |
#stop(wait = false, force = false) ⇒ Object
189 190 191 192 193 194 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 189 def stop(wait = false, force = false) requires :id service.stop_instances(id, force) wait_for { status == 'stopped' and !changing? } if wait true end |
#volumes ⇒ Object
196 197 198 199 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 196 def volumes requires :id service.volumes(:server => self) end |
#wait_for(&block) ⇒ Object
227 228 229 230 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 227 def wait_for(&block) wait_policy = lambda { |retries| retries < 8 ? 9 - retries : 1 } super(Fog::QingCloud.wait_timeout, wait_policy, &block) end |