-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request fog#3567 from Ladas/openstack_add_nova_service_sup…
…port OpenStack add nova service support
- Loading branch information
Showing
9 changed files
with
327 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'fog/core/model' | ||
|
||
module Fog | ||
module Compute | ||
class OpenStack | ||
class Service < Fog::Model | ||
identity :id | ||
|
||
attribute :binary | ||
attribute :host | ||
attribute :state | ||
attribute :status | ||
attribute :updated_at | ||
attribute :zone | ||
|
||
#detailed | ||
attribute :disabled_reason | ||
|
||
def initialize(attributes) | ||
# Old 'connection' is renamed as service and should be used instead | ||
prepare_service_value(attributes) | ||
super | ||
end | ||
|
||
def enable | ||
requires :binary, :host | ||
service.enable_service(self.host, self.binary) | ||
end | ||
|
||
def disable | ||
requires :binary, :host | ||
service.disable_service(self.host, self.binary) | ||
end | ||
|
||
def disable_and_log_reason | ||
requires :binary, :host, :disabled_reason | ||
service.disable_service_log_reason(self.host, self.binary, self.disabled_reason) | ||
end | ||
|
||
def destroy | ||
requires :id | ||
service.delete_service(self.id) | ||
true | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'fog/core/collection' | ||
require 'fog/openstack/models/compute/service' | ||
|
||
module Fog | ||
module Compute | ||
class OpenStack | ||
class Services < Fog::Collection | ||
model Fog::Compute::OpenStack::Service | ||
|
||
def all(parameters=nil) | ||
load(service.list_services(parameters).body['services']) | ||
end | ||
|
||
def details(parameters=nil) | ||
load(service.list_services(parameters).body['services']) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Fog | ||
module Compute | ||
class OpenStack | ||
class Real | ||
def delete_service(uuid, optional_params = nil) | ||
# Encode all params | ||
optional_params = optional_params.each { |k, v| optional_params[k] = URI::encode(v) } if optional_params | ||
|
||
request( | ||
:expects => [202, 204], | ||
:method => 'DELETE', | ||
:path => "os-services/#{uuid}", | ||
:query => optional_params | ||
) | ||
end | ||
end | ||
|
||
class Mock | ||
def delete_service(host, binary, optional_params = nil) | ||
response = Excon::Response.new | ||
response.status = 204 | ||
response.headers = { | ||
"Content-Type" => "text/html; charset=UTF-8", | ||
"Content-Length" => "0", | ||
"Date" => Date.new | ||
} | ||
response | ||
end | ||
end # mock | ||
end # openstack | ||
end # compute | ||
end # fog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Fog | ||
module Compute | ||
class OpenStack | ||
class Real | ||
def disable_service(host, binary, optional_params = nil) | ||
data = {"host" => host, "binary" => binary} | ||
|
||
# Encode all params | ||
optional_params = optional_params.each { |k, v| optional_params[k] = URI::encode(v) } if optional_params | ||
|
||
request( | ||
:body => Fog::JSON.encode(data), | ||
:expects => 200, | ||
:method => 'PUT', | ||
:path => "os-services/disable", | ||
:query => optional_params | ||
) | ||
end | ||
end | ||
|
||
class Mock | ||
def disable_service(host, binary, optional_params = nil) | ||
response = Excon::Response.new | ||
response.status = 200 | ||
response.body = { | ||
"service" => { | ||
"host" => "host1", | ||
"binary" => "nova-compute", | ||
"status" => "disabled" | ||
} | ||
} | ||
response | ||
end | ||
end # mock | ||
end # openstack | ||
end # compute | ||
end # fog |
38 changes: 38 additions & 0 deletions
38
lib/fog/openstack/requests/compute/disable_service_log_reason.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Fog | ||
module Compute | ||
class OpenStack | ||
class Real | ||
def disable_service_log_reason(host, binary, disabled_reason, optional_params = nil) | ||
data = {"host" => host, "binary" => binary, "disabled_reason" => disabled_reason} | ||
|
||
# Encode all params | ||
optional_params = optional_params.each { |k, v| optional_params[k] = URI::encode(v) } if optional_params | ||
|
||
request( | ||
:body => Fog::JSON.encode(data), | ||
:expects => 200, | ||
:method => 'PUT', | ||
:path => "os-services/disable-log-reason", | ||
:query => optional_params | ||
) | ||
end | ||
end | ||
|
||
class Mock | ||
def disable_service_log_reason(host, binary, disabled_reason, optional_params = nil) | ||
response = Excon::Response.new | ||
response.status = 200 | ||
response.body = { | ||
"service" => { | ||
"host" => "host1", | ||
"binary" => "nova-compute", | ||
"status" => "disabled", | ||
"disabled_reason" => "test2" | ||
} | ||
} | ||
response | ||
end | ||
end # mock | ||
end # openstack | ||
end # compute | ||
end # fog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Fog | ||
module Compute | ||
class OpenStack | ||
class Real | ||
def enable_service(host, binary, optional_params = nil) | ||
data = {"host" => host, "binary" => binary} | ||
|
||
# Encode all params | ||
optional_params = optional_params.each { |k, v| optional_params[k] = URI::encode(v) } if optional_params | ||
|
||
|
||
request( | ||
:body => Fog::JSON.encode(data), | ||
:expects => 200, | ||
:method => 'PUT', | ||
:path => "os-services/enable", | ||
:query => optional_params | ||
) | ||
end | ||
end | ||
|
||
class Mock | ||
def enable_service(host, binary, optional_params = nil) | ||
response = Excon::Response.new | ||
response.status = 200 | ||
response.body = { | ||
"service" => { | ||
"host" => "host1", | ||
"binary" => "nova-compute", | ||
"status" => "enabled" | ||
} | ||
} | ||
response | ||
end | ||
end # mock | ||
end # openstack | ||
end # compute | ||
end # fog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
module Fog | ||
module Compute | ||
class OpenStack | ||
class Real | ||
def list_services(parameters=nil) | ||
if parameters | ||
query = parameters.each { |k, v| parameters[k] = URI::encode(v) } | ||
else | ||
query = {} | ||
end | ||
|
||
request( | ||
:expects => [200, 203], | ||
:method => 'GET', | ||
:path => 'os-services', | ||
:query => query | ||
) | ||
end | ||
end | ||
|
||
class Mock | ||
def list_services(parameters=nil) | ||
response = Excon::Response.new | ||
response.status = 200 | ||
response.body = { | ||
"services" => [{ | ||
"id" => 1, | ||
"binary" => "nova-scheduler", | ||
"host" => "host1", | ||
"state" => "up", | ||
"status" => "disabled", | ||
"updated_at" => "2012-10-29T13:42:02.000000", | ||
"zone" => "internal", | ||
"disabled_reason" => "test2" | ||
}, | ||
{ | ||
"id" => 2, | ||
"binary" => "nova-compute", | ||
"host" => "host1", | ||
"state" => "up", | ||
"status" => "disabled", | ||
"updated_at" => "2012-10-29T13:42:05.000000", | ||
"zone" => "nova", | ||
"disabled_reason" => "test2" | ||
}, | ||
{ | ||
"id" => 3, | ||
"binary" => "nova-scheduler", | ||
"host" => "host2", | ||
"state" => "down", | ||
"status" => "enabled", | ||
"updated_at" => "2012-09-19T06:55:34.000000", | ||
"zone" => "internal", | ||
"disabled_reason" => "nil" | ||
}, | ||
{ | ||
"id" => 4, | ||
"binary" => "nova-compute", | ||
"host" => "host2", | ||
"state" => "down", | ||
"status" => "disabled", | ||
"updated_at" => "2012-09-18T08:03:38.000000", | ||
"zone" => "nova", | ||
"disabled_reason" => "test2" | ||
}] | ||
} | ||
response | ||
end | ||
end # mock | ||
end # openstack | ||
end # compute | ||
end # fog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Shindo.tests('Fog::Compute[:openstack] | service requests', ['openstack']) do | ||
|
||
@service_format = { | ||
"id" => Integer, | ||
"binary" => String, | ||
"host" => String, | ||
"state" => String, | ||
"status" => String, | ||
"updated_at" => String, | ||
"zone" => String, | ||
'disabled_reason' => Fog::Nullable::String | ||
} | ||
|
||
tests('success') do | ||
tests('#list_services').data_matches_schema({'services' => [@service_format]}) do | ||
services = Fog::Compute[:openstack].list_services.body | ||
@service = services['services'].last | ||
services | ||
end | ||
|
||
tests('#disable_service').succeeds do | ||
Fog::Compute[:openstack].disable_service(@service['host'], @service['binary']) | ||
end | ||
|
||
tests('#disable_service_log_reason').succeeds do | ||
Fog::Compute[:openstack].disable_service_log_reason(@service['host'], @service['binary'], 'reason') | ||
end | ||
|
||
tests('#enable_service').succeeds do | ||
Fog::Compute[:openstack].enable_service(@service['host'], @service['binary']) | ||
end | ||
end | ||
end |