Skip to content

Instantly share code, notes, and snippets.

@relaxdiego
Last active December 22, 2015 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save relaxdiego/6410222 to your computer and use it in GitHub Desktop.
Save relaxdiego/6410222 to your computer and use it in GitHub Desktop.
module Aviator
define_request :create_tenant do
meta :provider, :openstack
meta :service, :identity
meta :api_version, :v2
meta :endpoint_type, :admin
link 'documentation',
'http://docs.openstack.org/api/openstack-identity-service/2.0/content/'
param :name, required: true
param :description, required: true
param :enabled, required: true
def http_method
:post
end
def url
service_spec = session_data[:access][:serviceCatalog].find{|s| s[:type] == 'identity' }
"#{ service_spec[:endpoints][0][:adminURL] }/tenants"
end
def headers
h = {}
unless self.anonymous?
h['X-Auth-Token'] = session_data[:access][:token][:id]
end
h
end
def body
{
tenant: {
name: params[:name],
description: params[:description],
enabled: params[:enabled]
}
}
end
end
end
module Aviator
define_request :create_token do
meta :anonymous, true
meta :provider, :openstack
meta :service, :identity
meta :api_version, :v2
meta :endpoint_type, :public
link 'documentation',
'http://docs.openstack.org/api/openstack-identity-service/2.0/content/POST_authenticate_v2.0_tokens_.html'
link 'documentation bug',
'https://bugs.launchpad.net/keystone/+bug/1208607'
param :username, required_with: :password
param :password, required_with: :username
param :tokenId, required: false
param :tenantName, required: false
param :tenantId, required: false
def http_method
:post
end
def url
url = session_data[:auth_service][:host_uri]
url += '/v2.0' if (URI(url).path =~ /^\/?\w+/).nil?
url += "/tokens"
url
end
def body
p = if params[:tokenId]
{
auth: {
token: {
id: params[:tokenId]
}
}
}
else
{
auth: {
passwordCredentials: {
username: params[:username],
password: params[:password]
}
}
}
end
p[:auth][:tenantName] = params[:tenantName] if params[:tenantName]
p[:auth][:tenantId] = params[:tenantId] if params[:tenantId]
p
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment