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.
34 35 36 37 38 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 34 def initialize(attributes={}) prepare_service_value(attributes) self.image_id ||= 'centos64x64a' super end |
Instance Method Details
#addresses ⇒ Object
40 41 42 43 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 40 def addresses requires :id service.addresses(:server => self) end |
#changing? ⇒ Boolean
83 84 85 86 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 83 def changing? respond_to?(:transition_status) && transition_status && !transition_status.empty? end |
#destroy ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 45 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
66 67 68 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 66 def flavor @flavor ||= service.flavors.all.detect {|flavor| flavor.id == flavor_id} end |
#flavor=(new_flavor) ⇒ Object
59 60 61 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 59 def flavor=(new_flavor) @flavor = new_flavor end |
#flavor_id ⇒ Object Also known as: instance_type
55 56 57 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 55 def flavor_id @flavor && @flavor.id || attributes[:flavor_id] end |
#image ⇒ Object
207 208 209 210 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 207 def image requires :id service.images.get(image_id) end |
#join_vxnet(vxnet) ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 131 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
70 71 72 73 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 70 def key_pair requires :keypair_ids service.key_pairs.all(keypair_ids).first end |
#key_pair=(key_id) ⇒ Object
75 76 77 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 75 def key_pair=(key_id) keypair_ids << key_id end |
#leave_vxnet(vxnet) ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 141 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
218 219 220 221 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 218 def mac_addresses requires :id nics.map { |x| x.nic_id } end |
#modify_attributes(name, description) ⇒ Object
233 234 235 236 237 238 239 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 233 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
212 213 214 215 216 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 212 def nics requires :id reload if @modified vxnets.map {|x| OpenStruct.new(x)} end |
#private_ips ⇒ Object
223 224 225 226 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 223 def private_ips requires :id nics.map{|x| x.private_ip} end |
#ready? ⇒ Boolean
79 80 81 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 79 def ready? status == 'running' end |
#reboot(wait = false) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 88 def reboot(wait = false) requires :id service.reboot_instances(id) wait_for { status == 'running' and !changing? } if wait true end |
#reset ⇒ Object
158 159 160 161 162 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 158 def reset requires :id service.reset_instances(id) true end |
#resize(target_instance_type = nil, cpu = nil, memory = nil) ⇒ Object
151 152 153 154 155 156 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 151 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
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 129 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 95 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
202 203 204 205 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 202 def security_groups requires :id service.security_groups(:server => self) end |
#setup(credentials = {}) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 164 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
183 184 185 186 187 188 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 183 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
190 191 192 193 194 195 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 190 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
197 198 199 200 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 197 def volumes requires :id service.volumes(:server => self) end |
#wait_for(&block) ⇒ Object
228 229 230 231 |
# File 'lib/fog/qingcloud/models/compute/server.rb', line 228 def wait_for(&block) wait_policy = lambda { |retries| retries < 8 ? 9 - retries : 1 } super(Fog::QingCloud.wait_timeout, wait_policy, &block) end |