Class: NCC::Connection
- Inherits:
-
Object
- Object
- NCC::Connection
- Defined in:
- lib/ncc/connection.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#fog ⇒ Object
readonly
Returns the value of attribute fog.
Class Method Summary collapse
Instance Method Summary collapse
- #collection(type, key = nil) ⇒ Object
- #communication_error(message) ⇒ Object
- #connection_params ⇒ Object
- #console(instance_id) ⇒ Object
- #console_log(instance_id) ⇒ Object
- #create_instance(instance_spec, wait_for_ip = nil) ⇒ Object
- #current? ⇒ Boolean
- #debug(msg = nil) ⇒ Object
- #delete(instance_id) ⇒ Object
- #do_connect ⇒ Object
- #do_fog ⇒ Object
- #fields(obj, *flist) ⇒ Object
- #generic_provider_request(instance) ⇒ Object
- #generic_translate(abstract_object_type, provider_object) ⇒ Object
- #get_provider_object(provider_object_spec) ⇒ Object
- #get_provider_objects(type) ⇒ Object
- #host_fqdn(host) ⇒ Object
- #id_field(abstract_object_type) ⇒ Object
- #id_map(type) ⇒ Object
-
#id_map_hash(h) ⇒ Object
Something like “images” => { “$abstract_id” => x } can have an x where it’s the provider id, or an x which is a hash.
- #id_of(abstract_object_type, obj) ⇒ Object
- #ids(a) ⇒ Object
- #images(image_id = nil) ⇒ Object
- #info(msg) ⇒ Object
-
#initialize(ncc, cloud, opt = {}) ⇒ Connection
constructor
A new instance of Connection.
- #instance_for(server) ⇒ Object
- #instance_host(server) ⇒ Object
- #instance_image(server) ⇒ Object
- #instance_ip_address(server) ⇒ Object
- #instance_name(server) ⇒ Object
- #instance_not_found(instance_id) ⇒ Object
- #instance_size(server) ⇒ Object
- #instance_status(server) ⇒ Object
- #instances(instance_id = nil) ⇒ Object
- #inventory_request(instance) ⇒ Object
- #keyintern(h) ⇒ Object
- #keyname_for(type) ⇒ Object
-
#map_from_raw_provider_id(type, raw_provider_id) ⇒ Object
raw meaning not using “our” notion of id_field.
- #map_to_id(type, provider_id) ⇒ Object
- #map_to_provider_id(type, abstract_id) ⇒ Object
- #map_to_provider_status(abstract_status) ⇒ Object
- #map_to_status(provider_status) ⇒ Object
- #maybe_invalidate(type) ⇒ Object
- #me ⇒ Object
- #merge_configured(abstract_object, data) ⇒ Object
- #modify_instance_request(instance) ⇒ Object
- #notice(msg) ⇒ Object
- #object_of(abstract_object_type, provider_object) ⇒ Object
- #provider ⇒ Object
- #provider_id_map(type) ⇒ Object
- #provider_request(instance) ⇒ Object
- #provider_request_of(instance) ⇒ Object
- #reboot(instance_id) ⇒ Object
- #sizes(size_id = nil) ⇒ Object
- #to_s ⇒ Object
- #translate(abstract_object_type, provider_object) ⇒ Object
- #translated_id_of(abstract_object_type, obj) ⇒ Object
-
#use_only_mapped(type) ⇒ Object
Warning.
- #warn(msg) ⇒ Object
Constructor Details
#initialize(ncc, cloud, opt = {}) ⇒ Connection
Returns a new instance of Connection.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ncc/connection.rb', line 46 def initialize(ncc, cloud, opt={}) @ncc = ncc @cache = { } @cfg = ncc.config @cfg_mtime = @cfg[:clouds][cloud].mtime @cloud = cloud @logger = opt[:logger] if opt.has_key? :logger @cache_timeout = opt[:cache_timeout] || 600 @auth_retry_limit = opt[:auth_retry_limit] || 1 @create_timeout = opt[:create_timeout] || 160 do_connect end |
Instance Attribute Details
#fog ⇒ Object (readonly)
Returns the value of attribute fog.
31 32 33 |
# File 'lib/ncc/connection.rb', line 31 def fog @fog end |
Class Method Details
.connect(ncc, cloud = :default, opt = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ncc/connection.rb', line 33 def self.connect(ncc, cloud=:default, opt={}) cfg = ncc.config provider = cfg[:clouds][cloud]['provider'] case provider when 'aws' require 'ncc/connection/aws' NCC::Connection::AWS.new(ncc, cloud, opt) when 'openstack' require 'ncc/connection/openstack' NCC::Connection::OpenStack.new(ncc, cloud, opt) end end |
Instance Method Details
#collection(type, key = nil) ⇒ Object
299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/ncc/connection.rb', line 299 def collection(type, key=nil) maybe_invalidate type @cache[type] ||= { :timestamp => Time.now, :data => Hash[get_provider_objects(type).map { |o| [o.id, o] }] } if key.nil? @cache[type][:data].values else @cache[type][:data][key] end end |
#communication_error(message) ⇒ Object
566 567 568 569 570 |
# File 'lib/ncc/connection.rb', line 566 def communication_error() = "Error communicating with #{provider} cloud #{@cloud}: " + unless /Error .*communicating with/.match() raise NCC::Error::Cloud, end |
#connection_params ⇒ Object
104 105 106 |
# File 'lib/ncc/connection.rb', line 104 def connection_params [] end |
#console(instance_id) ⇒ Object
595 596 597 598 |
# File 'lib/ncc/connection.rb', line 595 def console(instance_id) raise NCC::Error::NotFound, "Cloud #{@cloud} provider " + "#{provider} does not support interactive console" end |
#console_log(instance_id) ⇒ Object
590 591 592 593 |
# File 'lib/ncc/connection.rb', line 590 def console_log(instance_id) raise NCC::Error::NotFound, "Cloud #{@cloud} provider " + "#{provider} does not support console logs" end |
#create_instance(instance_spec, wait_for_ip = nil) ⇒ Object
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'lib/ncc/connection.rb', line 498 def create_instance(instance_spec, wait_for_ip=nil) wait_for_ip ||= @create_timeout if ! instance_spec.kind_of? NCC::Instance instance_spec = NCC::Instance.new(@cfg, instance_spec) end req_id = ['ncc', @cloud, UUIDTools::UUID.random_create.to_s].join('-') begin info "#{@cloud} requesting name from inventory using #{req_id}" fqdn = @ncc.inventory.get_or_assign_system_name(req_id)['fqdn'] rescue StandardError => e raise NCC::Error::Cloud, "Error [#{e.class}] " + "communicating with inventory to " + "assign name using (ncc_req_id=#{req_id}): #{e.}" end instance_spec.name = fqdn begin req = provider_request(instance_spec) t0 = Time.now info "#{@cloud} sending request: #{req.inspect}" server = do_fog { |fog| fog.servers.create(req) } # The reason we wait for an IP is so we can add it to # inventory, which then calculates the datacenter if wait_for_ip > 0 and instance_ip_address(server).nil? info "#{@cloud} waiting for ip on #{server.id}" this = self server.wait_for(wait_for_ip) { ready? and this.instance_ip_address(server) } end rescue StandardError => err debug "Error [#{err.class}]: #{err.} #{err.backtrace.join("\n ")}" inv_update = { 'fqdn' => fqdn, 'status' => 'decommissioned' } if ! server.nil? and server.id inv_update['uuid'] = server.id inv_update['serial_number'] = server.id end @ncc.inventory.update('system', inv_update, fqdn) server_id = (server.nil? ? 'nil' : server.id) communication_error "[#{err.class}] (ncc_req_id=#{req_id} " + "instance_id=#{server_id}): #{err.}" end elapsed = Time.now - t0 info "Created instance instance_id=#{server.id} at #{provider} cloud #{@cloud} in #{elapsed}s" instance = instance_for server instance_spec.id = instance.id instance_spec.ip_address = instance.ip_address instance_spec.host = instance.host inv_req = inventory_request(instance_spec) inv_req['cloud'] = @cloud inv_req['status'] = 'building' begin info "#{@cloud} updating inventory #{fqdn}/#{req_id} -> #{inv_req.inspect}" @ncc.inventory.update('system', inv_req, fqdn) rescue StandardError => e raise NCC::Error::Cloud, "Error [#{e.class}] updating inventory " + "system #{fqdn} " + "(cloud=#{@cloud} ncc_req_id=#{req_id} " + "instance_id=#{server.id}): " + e. end instance end |
#current? ⇒ Boolean
59 60 61 62 |
# File 'lib/ncc/connection.rb', line 59 def current? provider == @cfg[:clouds][@cloud]['provider'] and @cfg_mtime == @cfg[:clouds][@cloud].mtime end |
#debug(msg = nil) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/ncc/connection.rb', line 85 def debug(msg=nil) msg ||= yield if block_given? if @logger and @logger.respond_to? :debug @logger.debug "#{self} #{msg}" end end |
#delete(instance_id) ⇒ Object
572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
# File 'lib/ncc/connection.rb', line 572 def delete(instance_id) server = do_fog { |fog| fog.servers.get(instance_id) } if server.nil? instance_not_found instance_id else begin instance = instance_for server server.destroy inv_update = { 'fqdn' => instance.name, 'status' => 'decommissioned' } @ncc.inventory.update('system', inv_update, instance.name) rescue StandardError => e communication_error "deleting fqdn=#{instance.name} " + "instance_id=#{server.id}: #{e.}" end end end |
#do_connect ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/ncc/connection.rb', line 108 def do_connect cloud_config = @cfg[:clouds][@cloud] pnames = connection_params + ['provider'] params = Hash[cloud_config.to_hash(*pnames).map do |k, v| [k.intern, v] end ] @fog = Fog::Compute.new(params) end |
#do_fog ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ncc/connection.rb', line 117 def do_fog remaining_tries = @auth_retry_limit begin unless @fog debug "do_fog: connecting because @fog is nil (@auth_retry_limit=#{@auth_retry_limit})" do_connect end debug "do_fog: beginning fog operation" yield @fog rescue Excon::Errors::Unauthorized => err # might be an expired auth token, retry if remaining_tries > 0 do_connect remaining_tries -= 1 retry else @fog = nil raise NCC::Error::Cloud, "Error communicating with #{provider} " + "cloud #{@cloud} (#{e.class}): #{e.}" end rescue NCC::Error::Cloud => err @fog = nil raise err rescue NCC::Error => err raise err rescue StandardError => err debug "Unknown error [#{err.class}]: #{err.} #{err.backtrace.join("\n ")}" @fog = nil raise NCC::Error::Cloud, "Error communicating with #{provider} " + "cloud #{@cloud} [#{err.class}]: #{err.}" end end |
#fields(obj, *flist) ⇒ Object
156 157 158 |
# File 'lib/ncc/connection.rb', line 156 def fields(obj, *flist) Hash[flist.map { |f| [f, obj.send(f)] }] end |
#generic_provider_request(instance) ⇒ Object
454 455 456 457 458 459 460 |
# File 'lib/ncc/connection.rb', line 454 def generic_provider_request(instance) { :name => instance.name, :flavor => map_to_provider_id(:size, instance.size), :size => map_to_provider_id(:image, instance.image), }.merge(instance.extra provider) end |
#generic_translate(abstract_object_type, provider_object) ⇒ Object
380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/ncc/connection.rb', line 380 def generic_translate(abstract_object_type, provider_object) abstract_object = { 'id' => id_of(abstract_object_type, provider_object), 'provider_id' => provider_object.id } [:name, :description].each do |field| abstract_object[field.to_s] = provider_object.send(field) if provider_object.respond_to? field end abstract_object end |
#get_provider_object(provider_object_spec) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/ncc/connection.rb', line 328 def get_provider_object(provider_object_spec) abstract_object_type, abstract_object_id = provider_object_spec.first if id_field(abstract_object_type) != :id collection(abstract_object_type).find do |provider_object| id_of(abstract_object_type, provider_object) == abstract_object_id end else provider_object_id = map_to_provider_id(abstract_object_type, abstract_object_id) collection(abstract_object_type, provider_object_id) end end |
#get_provider_objects(type) ⇒ Object
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/ncc/connection.rb', line 312 def get_provider_objects(type) enum = case type when :size :flavors when :image :images end if use_only_mapped(type) and id_field(type) == :id id_map(type).values.map do |id| do_fog { |fog| fog.send(enum).get(id) } end else do_fog { |fog| fog.send(enum).map { |e| e } } end end |
#host_fqdn(host) ⇒ Object
486 487 488 489 490 491 492 |
# File 'lib/ncc/connection.rb', line 486 def host_fqdn(host) if @cfg[:clouds][@cloud].has_key? 'host_domain' host + '.' + @cfg[:clouds][@cloud]['host_domain'] else host end end |
#id_field(abstract_object_type) ⇒ Object
274 275 276 277 278 279 280 281 |
# File 'lib/ncc/connection.rb', line 274 def id_field(abstract_object_type) methodname = abstract_object_type.to_s + '_id_field' if self.respond_to? methodname self.send methodname else :id end end |
#id_map(type) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/ncc/connection.rb', line 196 def id_map(type) debug "making id_map for #{type.inspect}" keyname = keyname_for(type) r = { } debug "keyname = #{keyname} (for #{type.inspect})" debug "provider map: #{@cfg[:providers][provider].to_hash.inspect}" r.update(id_map_hash(@cfg[:providers][provider][keyname].to_hash)) if @cfg[:providers][provider].has_key? keyname #debug "cloud map: #{@cfg[:clouds][@cloud][keyname].to_hash}" r.update(id_map_hash(@cfg[:clouds][@cloud][keyname].to_hash)) if @cfg[:clouds][@cloud].has_key? keyname debug " >> #{r.inspect}" r end |
#id_map_hash(h) ⇒ Object
Something like “images” => { “$abstract_id” => x } can have an x where it’s the provider id, or an x which is a hash. If the hash has an id key, than that is used as a mapped id, if it doesn’t, it’s ignored (for the purposes of id mapping) -jbrinkley/20130410
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/ncc/connection.rb', line 182 def id_map_hash(h) Hash[ h.map do |k, v| if v.respond_to? :has_key? if v.has_key? 'id' [k, v['id']] end else [k, v] end end.reject { |p| p.nil? } ] end |
#id_of(abstract_object_type, obj) ⇒ Object
283 284 285 286 |
# File 'lib/ncc/connection.rb', line 283 def id_of(abstract_object_type, obj) map_to_id(abstract_object_type, translated_id_of(abstract_object_type, obj)) end |
#ids(a) ⇒ Object
160 161 162 |
# File 'lib/ncc/connection.rb', line 160 def ids(a) Hash[a.map { |e| [e['id'], e] }] end |
#images(image_id = nil) ⇒ Object
263 264 265 266 267 268 269 270 271 272 |
# File 'lib/ncc/connection.rb', line 263 def images(image_id=nil) if image_id.nil? collection(:image).find_all do |provider_image| @cfg[:images].has_key? id_of(:image, provider_image) end.map { |i| object_of(:image, i) } else object_of(:image, get_provider_object(:image => image_id)) end end |
#info(msg) ⇒ Object
98 99 100 101 102 |
# File 'lib/ncc/connection.rb', line 98 def info(msg) if @logger and @logger.respond_to? :info @logger.info "#{self} #{msg}" end end |
#instance_for(server) ⇒ Object
392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/ncc/connection.rb', line 392 def instance_for(server) instance = NCC::Instance.new(@cfg, :logger => @logger) instance.set_without_validation(:id => server.id) instance.set_without_validation(:name => instance_name(server)) instance.set_without_validation(:size => instance_size(server)) instance.set_without_validation(:image => instance_image(server)) instance.set_without_validation(:ip_address => instance_ip_address(server)) instance.set_without_validation(:host => instance_host(server)) instance.set_without_validation(:status => instance_status(server)) instance end |
#instance_host(server) ⇒ Object
421 422 423 |
# File 'lib/ncc/connection.rb', line 421 def instance_host(server) nil end |
#instance_image(server) ⇒ Object
413 414 415 |
# File 'lib/ncc/connection.rb', line 413 def instance_image(server) map_to_id(:image, server.image) end |
#instance_ip_address(server) ⇒ Object
425 426 427 |
# File 'lib/ncc/connection.rb', line 425 def instance_ip_address(server) server.ip_address.to_s end |
#instance_name(server) ⇒ Object
405 406 407 |
# File 'lib/ncc/connection.rb', line 405 def instance_name(server) server.name end |
#instance_not_found(instance_id) ⇒ Object
561 562 563 564 |
# File 'lib/ncc/connection.rb', line 561 def instance_not_found(instance_id) raise NCC::Error::NotFound, "Instance #{instance_id.inspect} not " + "found in #{provider} cloud #{@cloud}" end |
#instance_size(server) ⇒ Object
409 410 411 |
# File 'lib/ncc/connection.rb', line 409 def instance_size(server) map_to_id(:size, server.size) end |
#instance_status(server) ⇒ Object
417 418 419 |
# File 'lib/ncc/connection.rb', line 417 def instance_status(server) map_to_status(server.status) end |
#instances(instance_id = nil) ⇒ Object
429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/ncc/connection.rb', line 429 def instances(instance_id=nil) debug "instances(#{instance_id.inspect})" if instance_id.nil? do_fog { |fog| fog.servers.map { |server| instance_for server } } else server = do_fog { |fog| fog.servers.get instance_id } if server.nil? instance_not_found instance_id end instance_for server end end |
#inventory_request(instance) ⇒ Object
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'lib/ncc/connection.rb', line 470 def inventory_request(instance) i = instance.with_defaults(@cfg[:clouds][@cloud]['defaults'], @cfg[:providers][provider]['defaults']) { 'fqdn' => i.name, 'size' => i.size, 'image' => i.image, 'serial_number' => i.id, 'uuid' => i.id, 'roles' => i.role.sort.join(','), 'ipaddress' => i.ip_address, 'host_fqdn' => host_fqdn(i.host), 'environment_name' => i.environment }.merge(instance.extra 'inventory') end |
#keyintern(h) ⇒ Object
462 463 464 465 466 467 468 |
# File 'lib/ncc/connection.rb', line 462 def (h) Hash[h.map do |k, v| [k.to_sym, ((v.is_a? Hash and (k.to_sym != :tags)) ? (v) : v)] end] end |
#keyname_for(type) ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/ncc/connection.rb', line 168 def keyname_for(type) case type when :size 'sizes' when :image 'images' end end |
#map_from_raw_provider_id(type, raw_provider_id) ⇒ Object
raw meaning not using “our” notion of id_field
235 236 237 238 239 240 241 |
# File 'lib/ncc/connection.rb', line 235 def map_from_raw_provider_id(type, raw_provider_id) # Using collection here for cache provider_object = collection(type).find do |item| item.id == raw_provider_id end id_of(type, provider_object) end |
#map_to_id(type, provider_id) ⇒ Object
225 226 227 228 |
# File 'lib/ncc/connection.rb', line 225 def map_to_id(type, provider_id) debug "provider_id_map = #{provider_id_map(type).inspect}" provider_id_map(type)[provider_id] || provider_id end |
#map_to_provider_id(type, abstract_id) ⇒ Object
230 231 232 |
# File 'lib/ncc/connection.rb', line 230 def map_to_provider_id(type, abstract_id) id_map(type)[abstract_id] || abstract_id end |
#map_to_provider_status(abstract_status) ⇒ Object
247 248 249 |
# File 'lib/ncc/connection.rb', line 247 def map_to_provider_status(abstract_status) abstract_status end |
#map_to_status(provider_status) ⇒ Object
243 244 245 |
# File 'lib/ncc/connection.rb', line 243 def map_to_status(provider_status) provider_status end |
#maybe_invalidate(type) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/ncc/connection.rb', line 64 def maybe_invalidate(type) if @cache.has_key? type @cache.delete(type) if (Time.now - @cache[type][:timestamp]) > @cache_timeout end end |
#me ⇒ Object
71 72 73 |
# File 'lib/ncc/connection.rb', line 71 def me [self.class, provider, @cloud].join(' ') end |
#merge_configured(abstract_object, data) ⇒ Object
352 353 354 355 356 357 358 |
# File 'lib/ncc/connection.rb', line 352 def merge_configured(abstract_object, data) if data.respond_to? :each_pair data.each_pair { |k, v| abstract_object[k] ||= v } else abstract_object['provider_id'] ||= data end end |
#modify_instance_request(instance) ⇒ Object
494 495 496 |
# File 'lib/ncc/connection.rb', line 494 def modify_instance_request(instance) instance end |
#notice(msg) ⇒ Object
92 93 94 95 96 |
# File 'lib/ncc/connection.rb', line 92 def notice(msg) if @logger and @logger.respond_to? :notice @logger.notice "#{self} #{msg}" end end |
#object_of(abstract_object_type, provider_object) ⇒ Object
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/ncc/connection.rb', line 360 def object_of(abstract_object_type, provider_object) debug "object_of(#{abstract_object_type.inspect}, #{provider_object})" abstract_object = translate(abstract_object_type, provider_object) keyname = keyname_for abstract_object_type id = abstract_object['id'] [@cfg[:clouds][@cloud], @cfg[:providers][provider]].each do |cfg| if cfg.has_key? keyname and cfg[keyname].has_key? id debug "merging cloud/provider data: cfg[#{keyname}][#{id}]" merge_configured(abstract_object, cfg[keyname][id]) end end if @cfg.has_key? keyname.intern and @cfg[keyname.intern].has_key? id debug "merging abstract data: " + "@cfg[#{keyname.intern.inspect}][#{id}]" merge_configured(abstract_object, @cfg[keyname.intern][id].to_hash) end debug "object_of returns: #{abstract_object.inspect}" abstract_object end |
#provider ⇒ Object
164 165 166 |
# File 'lib/ncc/connection.rb', line 164 def provider generic end |
#provider_id_map(type) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/ncc/connection.rb', line 211 def provider_id_map(type) debug "making provider_id_map for #{type.inspect}" keyname = keyname_for(type) r = { } r.update(id_map_hash(@cfg[:providers][provider][keyname]. to_hash).invert) if @cfg[:providers][provider].has_key? keyname r.update(id_map_hash(@cfg[:clouds][@cloud][keyname]. to_hash).invert) if @cfg[:clouds][@cloud].has_key? keyname debug " >>> #{r.inspect}" r end |
#provider_request(instance) ⇒ Object
442 443 444 445 446 447 448 |
# File 'lib/ncc/connection.rb', line 442 def provider_request(instance) ( provider_request_of(instance. with_defaults(@cfg[:clouds][@cloud]['defaults'], @cfg[:providers][provider]['defaults'])) ) end |
#provider_request_of(instance) ⇒ Object
450 451 452 |
# File 'lib/ncc/connection.rb', line 450 def provider_request_of(instance) generic_provider_request(instance) end |
#reboot(instance_id) ⇒ Object
600 601 602 603 604 605 606 607 |
# File 'lib/ncc/connection.rb', line 600 def reboot(instance_id) server = do_fog { |fog| fog.servers.get(instance_id) } if server.nil? instance_not_found instance_id else server.reboot end end |
#sizes(size_id = nil) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/ncc/connection.rb', line 251 def sizes(size_id=nil) debug "sizes(#{size_id.inspect})" if size_id.nil? collection(:size).find_all do |flavor| @cfg[:sizes].has_key? id_of(:size, flavor) end.map { |f| object_of(:size, f) } else object_of(:size, get_provider_object(:size => size_id)) end end |
#to_s ⇒ Object
75 76 77 |
# File 'lib/ncc/connection.rb', line 75 def to_s '#<' + me + '>' end |
#translate(abstract_object_type, provider_object) ⇒ Object
342 343 344 345 346 347 348 349 350 |
# File 'lib/ncc/connection.rb', line 342 def translate(abstract_object_type, provider_object) debug "translate(#{abstract_object_type.inspect}, #{provider_object})" methodname = 'translate_' + abstract_object_type.to_s if self.respond_to? methodname self.send(methodname, provider_object) else generic_translate(abstract_object_type, provider_object) end end |
#translated_id_of(abstract_object_type, obj) ⇒ Object
288 289 290 291 292 293 294 295 296 297 |
# File 'lib/ncc/connection.rb', line 288 def translated_id_of(abstract_object_type, obj) id_fielder = id_field abstract_object_type if id_fielder.kind_of? Proc id_fielder.call obj elsif obj.nil? nil else obj.send id_fielder end end |
#use_only_mapped(type) ⇒ Object
Warning. use_only_mapped is ignored for types with alternate id fields
152 153 154 |
# File 'lib/ncc/connection.rb', line 152 def use_only_mapped(type) false end |
#warn(msg) ⇒ Object
79 80 81 82 83 |
# File 'lib/ncc/connection.rb', line 79 def warn(msg) if @logger and @logger.respond_to? :warn @logger.warn "#{self} #{msg}" end end |