Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[openstack|compute] Added list/get support for /os-hosts

  • Loading branch information...
commit 34e3b781234be6eb9c348e63056835e87377eea9 1 parent eaa96b3
@hunter hunter authored Keoven committed
View
7 lib/fog/openstack/compute.rb
@@ -37,6 +37,8 @@ class OpenStack < Fog::Service
collection :networks
model :snapshot
collection :snapshots
+ model :host
+ collection :hosts
## REQUESTS
#
@@ -148,6 +150,11 @@ class OpenStack < Fog::Service
request :get_quota_defaults
request :update_quota
+ # Hosts
+ request :list_hosts
+ request :get_host_details
+
+
class Mock
def self.data
View
28 lib/fog/openstack/models/compute/host.rb
@@ -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
View
32 lib/fog/openstack/models/compute/hosts.rb
@@ -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
View
74 lib/fog/openstack/requests/compute/get_host_details.rb
@@ -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
View
32 lib/fog/openstack/requests/compute/list_hosts.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.