Sha256: 61259c1380dcc4bc43b62ffe1d1617243abf47aa61f7a2302041866578d6fbce

Contents?: true

Size: 1.87 KB

Versions: 16

Compression:

Stored size: 1.87 KB

Contents

require 'yao/resources/metadata_available'
require 'yao/resources/action'
module Yao::Resources
  class Server < Base
    friendly_attributes :addresses, :metadata, :name, :progress,
                        :status, :tenant_id, :user_id, :key_name
    map_attribute_to_attribute :hostId => :host_id
    map_attribute_to_resource  :flavor => Flavor
    map_attribute_to_resource  :image  => Image
    map_attribute_to_resources :security_groups => SecurityGroup

    map_attribute_to_attribute 'OS-EXT-AZ:availability_zone'         => :availability_zone
    map_attribute_to_attribute 'OS-DCF:diskConfig'                   => :dcf_disk_config
    map_attribute_to_attribute 'OS-EXT-SRV-ATTR:host'                => :ext_srv_attr_host
    map_attribute_to_attribute 'OS-EXT-SRV-ATTR:hypervisor_hostname' => :ext_srv_attr_hypervisor_hostname
    map_attribute_to_attribute 'OS-EXT-SRV-ATTR:instance_name'       => :ext_srv_attr_instance_name
    map_attribute_to_attribute 'OS-EXT-STS:power_state'              => :ext_sts_power_state
    map_attribute_to_attribute 'OS-EXT-STS:task_state'               => :ext_sts_task_state
    map_attribute_to_attribute 'OS-EXT-STS:vm_state'                 => :ext_sts_vm_state

    self.service        = "compute"
    self.resource_name  = "server"
    self.resources_name = "servers"

    def old_samples(counter_name: nil, query: {})
      Yao::OldSample.list(counter_name, query).select{|os| os.resource_metadata["instance_id"] == id}
    end

    def self.start(id)
      action(id, "os-start" => nil)
    end

    def self.shutoff(id)
      action(id, "os-stop" => nil)
    end

    def self.reboot(id)
      action(id,"reboot" => { "type" => "HARD" })
    end

    def self.resize(id, flavor_id)
      action(id,"resize" => { "flavorRef" => flavor_id })
    end

    class << self
      alias :stop :shutoff
    end

    extend MetadataAvailable
    extend Action
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
yao-0.3.5 lib/yao/resources/server.rb
yao-0.3.4 lib/yao/resources/server.rb
yao-0.3.3 lib/yao/resources/server.rb
yao-0.3.2 lib/yao/resources/server.rb
yao-0.3.1 lib/yao/resources/server.rb
yao-0.3.0 lib/yao/resources/server.rb
yao-0.2.13 lib/yao/resources/server.rb
yao-0.2.12 lib/yao/resources/server.rb
yao-0.2.11 lib/yao/resources/server.rb
yao-0.2.10 lib/yao/resources/server.rb
yao-0.2.9 lib/yao/resources/server.rb
yao-0.2.8 lib/yao/resources/server.rb
yao-0.2.7 lib/yao/resources/server.rb
yao-0.2.6 lib/yao/resources/server.rb
yao-0.2.5 lib/yao/resources/server.rb
yao-0.2.4 lib/yao/resources/server.rb