1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[hp|network] Add request method for create_network.

This commit is contained in:
Rupak Ganguly 2013-03-21 16:06:58 -04:00
parent 24c7d7e407
commit a6033464fe
3 changed files with 77 additions and 1 deletions

View file

@ -259,6 +259,14 @@ module Fog
ip.join('.')
end
def self.uuid
# pattern of 8-4-4-4-12 hexadecimal digits
uuid = []
[8,4,4,4,12].each do |x|
uuid << Fog::Mock.random_hex(x)
end
uuid.join('-')
end
end
end

View file

@ -13,7 +13,7 @@ module Fog
secrets :hp_secret_key
request_path 'fog/hp/requests/network'
#request :create_network
request :create_network
#request :delete_network
request :get_network
request :list_networks

View file

@ -0,0 +1,68 @@
module Fog
module HP
class Network
class Real
# Create a new server
#
# ==== Parameters
# * options<~Hash>:
# * 'name'<~String> - Name of the network
# * 'admin_state_up'<~Boolean> - The administrative state of the network, true or false
# * 'shared'<~Boolean> - true or false
# * 'tenant_id'<~String> - TenantId different than the current user, that should own the network. Only allowed if user has 'admin' role.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * network<~Hash>:
# * 'id'<~String>: - UUId for the network
# * 'name'<~String>: - Name of the network
# * 'tenant_id'<~String>: - TenantId that owns the network
# * 'status'<~String>: - Status of the network i.e. "ACTIVE"
# * 'subnets'<~Array>: - Subnets for the network
# * 'id'<~Integer>: - UUId for the subnet
# * 'router:external'<~Boolean>: - true or false
# * 'admin_state_up'<~Boolean>: - true or false
# * 'shared'<~Boolean>: - true or false
def create_network(options = {})
data = { 'network' => {} }
l_options = [:name, :admin_state_up, :shared, :tenant_id]
l_options.select{|o| options[o]}.each do |key|
data['network'][key] = options[key]
end
request(
:body => Fog::JSON.encode(data),
:expects => 201,
:method => 'POST',
:path => 'networks'
)
end
end
class Mock
def create_network(options = {})
response = Excon::Response.new
response.status = 201
data = {
'id' => Fog::HP::Mock.uuid.to_s,
'name' => options[:name] || "",
'tenant_id' => options[:tenant_id] || Fog::Mock.random_numbers(14).to_s,
'status' => 'ACTIVE',
'subnets' => [],
'router:external' => false,
'admin_state_up' => options[:admin_state_up] || true,
'shared' => options[:shared] || false
}
self.data[:networks][data['id']] = data
response.body = { 'network' => data }
response
end
end
end
end
end