Moved #endpoint_uri to #endpoint
This commit is contained in:
@@ -20,24 +20,16 @@
|
|||||||
require "uri"
|
require "uri"
|
||||||
|
|
||||||
module ::Openstack
|
module ::Openstack
|
||||||
# Instead of specifying the verbose node["openstack"]["endpoints"][name],
|
|
||||||
# this shortcut allows the simpler and shorter endpoint(name)
|
|
||||||
def endpoint name
|
|
||||||
@node['openstack']['endpoints'][name]
|
|
||||||
rescue
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
# Shortcut to get the full URI for an endpoint. If the "uri" key isn't
|
# Shortcut to get the full URI for an endpoint. If the "uri" key isn't
|
||||||
# set in the endpoint hash, we use the ::Openstack.get_uri_from_mash
|
# set in the endpoint hash, we use the ::Openstack.get_uri_from_mash
|
||||||
# library routine from the openstack-utils cookbook to grab a URI object
|
# library routine from the openstack-utils cookbook to grab a URI object
|
||||||
# and construct the URI object from the endpoint parts.
|
# and construct the URI object from the endpoint parts.
|
||||||
def endpoint_uri name
|
def endpoint name
|
||||||
ep = endpoint(name)
|
ep = endpoint_for name
|
||||||
if ep && ep.has_key?("uri")
|
if ep && ep.has_key?("uri")
|
||||||
::URI.parse ep["uri"]
|
::URI.parse ep["uri"]
|
||||||
elsif ep
|
elsif ep
|
||||||
uri_from_hash(ep)
|
uri_from_hash ep
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -153,4 +145,13 @@ module ::Openstack
|
|||||||
end
|
end
|
||||||
info
|
info
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
# Instead of specifying the verbose node["openstack"]["endpoints"][name],
|
||||||
|
# this shortcut allows the simpler and shorter endpoint(name)
|
||||||
|
def endpoint_for name
|
||||||
|
@node['openstack']['endpoints'][name]
|
||||||
|
rescue
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ maintainer_email "jaypipes@gmail.com"
|
|||||||
license "Apache 2.0"
|
license "Apache 2.0"
|
||||||
description "Common OpenStack attributes, libraries and recipes."
|
description "Common OpenStack attributes, libraries and recipes."
|
||||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||||
version "0.0.1"
|
version "0.1.0"
|
||||||
depends "database"
|
depends "database"
|
||||||
depends "openstack-utils"
|
depends "openstack-utils"
|
||||||
|
|||||||
@@ -20,22 +20,6 @@ describe ::Openstack do
|
|||||||
@subject.instance_variable_set :@node, @chef_run.node
|
@subject.instance_variable_set :@node, @chef_run.node
|
||||||
@subject.endpoint("nonexisting").should be_nil
|
@subject.endpoint("nonexisting").should be_nil
|
||||||
end
|
end
|
||||||
it "returns endpoint hash when found" do
|
|
||||||
@subject.instance_variable_set :@node, @chef_run.node
|
|
||||||
@subject.endpoint("compute-api")['host'].should == "127.0.0.1"
|
|
||||||
@subject.endpoint("compute-api").has_key?("uri").should be_false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#endpoint_uri" do
|
|
||||||
it "returns nil when no openstack.endpoints not in node attrs" do
|
|
||||||
@subject.instance_variable_set :@node, {}
|
|
||||||
@subject.endpoint_uri("nonexisting").should be_nil
|
|
||||||
end
|
|
||||||
it "returns nil when no such endpoint was found" do
|
|
||||||
@subject.instance_variable_set :@node, @chef_run.node
|
|
||||||
@subject.endpoint_uri("nonexisting").should be_nil
|
|
||||||
end
|
|
||||||
it "returns endpoint URI object when uri key in endpoint hash" do
|
it "returns endpoint URI object when uri key in endpoint hash" do
|
||||||
uri_hash = {
|
uri_hash = {
|
||||||
"openstack" => {
|
"openstack" => {
|
||||||
@@ -47,7 +31,7 @@ describe ::Openstack do
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@subject.instance_variable_set :@node, uri_hash
|
@subject.instance_variable_set :@node, uri_hash
|
||||||
result = @subject.endpoint_uri("compute-api")
|
result = @subject.endpoint "compute-api"
|
||||||
result.port.should == 8080
|
result.port.should == 8080
|
||||||
end
|
end
|
||||||
it "returns endpoint URI string when uri key in endpoint hash and host also in hash" do
|
it "returns endpoint URI string when uri key in endpoint hash and host also in hash" do
|
||||||
@@ -62,7 +46,7 @@ describe ::Openstack do
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@subject.instance_variable_set :@node, uri_hash
|
@subject.instance_variable_set :@node, uri_hash
|
||||||
@subject.endpoint_uri("compute-api").to_s.should eq "http://localhost"
|
@subject.endpoint("compute-api").to_s.should eq "http://localhost"
|
||||||
end
|
end
|
||||||
it "returns endpoint URI object when uri key not in endpoint hash but host is in hash" do
|
it "returns endpoint URI object when uri key not in endpoint hash but host is in hash" do
|
||||||
uri_hash = {
|
uri_hash = {
|
||||||
@@ -76,7 +60,7 @@ describe ::Openstack do
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@subject.instance_variable_set :@node, uri_hash
|
@subject.instance_variable_set :@node, uri_hash
|
||||||
result = @subject.endpoint_uri("compute-api")
|
result = @subject.endpoint "compute-api"
|
||||||
result.port.should == 8080
|
result.port.should == 8080
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user