mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[openstack|compute] Added list/get support for /os-hosts
This commit is contained in:
parent
eaa96b314f
commit
34e3b78123
5 changed files with 173 additions and 0 deletions
|
@ -37,6 +37,8 @@ module Fog
|
||||||
collection :networks
|
collection :networks
|
||||||
model :snapshot
|
model :snapshot
|
||||||
collection :snapshots
|
collection :snapshots
|
||||||
|
model :host
|
||||||
|
collection :hosts
|
||||||
|
|
||||||
## REQUESTS
|
## REQUESTS
|
||||||
#
|
#
|
||||||
|
@ -148,6 +150,11 @@ module Fog
|
||||||
request :get_quota_defaults
|
request :get_quota_defaults
|
||||||
request :update_quota
|
request :update_quota
|
||||||
|
|
||||||
|
# Hosts
|
||||||
|
request :list_hosts
|
||||||
|
request :get_host_details
|
||||||
|
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def self.data
|
def self.data
|
||||||
|
|
28
lib/fog/openstack/models/compute/host.rb
Normal file
28
lib/fog/openstack/models/compute/host.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
require 'fog/compute/models/server'
|
||||||
|
require 'fog/openstack/models/compute/metadata'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class OpenStack
|
||||||
|
|
||||||
|
class Host < Fog::Model
|
||||||
|
|
||||||
|
attribute :host_name
|
||||||
|
attribute :service
|
||||||
|
attribute :details
|
||||||
|
|
||||||
|
def initialize(attributes)
|
||||||
|
@connection = attributes[:connection]
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def details
|
||||||
|
connection.get_host_details(self.host_name).body['host']
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
32
lib/fog/openstack/models/compute/hosts.rb
Normal file
32
lib/fog/openstack/models/compute/hosts.rb
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
require 'fog/core/collection'
|
||||||
|
require 'fog/openstack/models/compute/host'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class OpenStack
|
||||||
|
|
||||||
|
class Hosts < Fog::Collection
|
||||||
|
|
||||||
|
model Fog::Compute::OpenStack::Host
|
||||||
|
|
||||||
|
def all
|
||||||
|
data = connection.list_hosts.body['hosts']
|
||||||
|
load(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(host_name)
|
||||||
|
if host = connection.get_host_details(host_name).body['host']
|
||||||
|
new({
|
||||||
|
'host_name' => host_name,
|
||||||
|
'details' => host}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
rescue Fog::Compute::OpenStack::NotFound
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
74
lib/fog/openstack/requests/compute/get_host_details.rb
Normal file
74
lib/fog/openstack/requests/compute/get_host_details.rb
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class OpenStack
|
||||||
|
class Real
|
||||||
|
|
||||||
|
def get_host_details(host)
|
||||||
|
request(
|
||||||
|
:expects => [200, 203],
|
||||||
|
:method => 'GET',
|
||||||
|
:path => "os-hosts/#{host}.json"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
|
||||||
|
def get_host_details(host)
|
||||||
|
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
response.body = { "host" => [
|
||||||
|
{ "resource" => {
|
||||||
|
"project" => "(total)",
|
||||||
|
"memory_mb" => 64427,
|
||||||
|
"host" => "cn28.la-1-3.morphcloud.net",
|
||||||
|
"cpu" => 12,
|
||||||
|
"disk_gb" => 1608
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ "resource" => {
|
||||||
|
"project" => "(used_now)",
|
||||||
|
"memory_mb" => 1753,
|
||||||
|
"host" => "cn28.la-1-3.morphcloud.net",
|
||||||
|
"cpu" => 3,
|
||||||
|
"disk_gb" => 33
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ "resource" => {
|
||||||
|
"project" => "(used_max)",
|
||||||
|
"memory_mb" => 7168,
|
||||||
|
"host" => "cn28.la-1-3.morphcloud.net",
|
||||||
|
"cpu" => 3,
|
||||||
|
"disk_gb" => 45
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ "resource" => {
|
||||||
|
"project" => "bf8301f5164f4790889a1bc2bfb16d99",
|
||||||
|
"memory_mb" => 5120,
|
||||||
|
"host" => "cn28.la-1-3.morphcloud.net",
|
||||||
|
"cpu" => 2,
|
||||||
|
"disk_gb" => 35
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ "resource" => {
|
||||||
|
"project" => "3bb4d0301c5f47d5b4d96a361fcf96f4",
|
||||||
|
"memory_mb" => 2048,
|
||||||
|
"host" => "cn28.la-1-3.morphcloud.net",
|
||||||
|
"cpu" => 1,
|
||||||
|
"disk_gb" => 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
response
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end # mock
|
||||||
|
end # openstack
|
||||||
|
end # compute
|
||||||
|
end # fog
|
32
lib/fog/openstack/requests/compute/list_hosts.rb
Normal file
32
lib/fog/openstack/requests/compute/list_hosts.rb
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class OpenStack
|
||||||
|
class Real
|
||||||
|
|
||||||
|
def list_hosts
|
||||||
|
request(
|
||||||
|
:expects => [200, 203],
|
||||||
|
:method => 'GET',
|
||||||
|
:path => 'os-hosts.json'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
|
||||||
|
def list_hosts
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
response.body = { "hosts" => [
|
||||||
|
{"host_name" => "host.test.net", "service"=>"compute"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
response
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end # mock
|
||||||
|
end # openstack
|
||||||
|
end # compute
|
||||||
|
end # fog
|
Loading…
Add table
Reference in a new issue