lib/fog/openstack/requests/network/create_network.rb in fog-maestrodev-1.8.0.20130114204828 vs lib/fog/openstack/requests/network/create_network.rb in fog-maestrodev-1.14.0.20130806165225
- old
+ new
@@ -4,15 +4,49 @@
class Real
def create_network(options = {})
data = { 'network' => {} }
- vanilla_options = [:name, :shared, :admin_state_up, :tenant_id]
+ vanilla_options = [
+ :name,
+ :shared,
+ :admin_state_up,
+ :tenant_id
+ ]
+
vanilla_options.reject{ |o| options[o].nil? }.each do |key|
data['network'][key] = options[key]
end
+ # Advanced Features through API Extensions
+ #
+ # Not strictly required but commonly found in OpenStack
+ # installs with Quantum networking.
+ #
+ # @see http://docs.openstack.org/trunk/openstack-network/admin/content/provider_attributes.html
+ provider_options = [
+ :router_external,
+ :provider_network_type,
+ :provider_segmentation_id,
+ :provider_physical_network
+ ]
+
+ # Map Fog::Network::OpenStack::Network
+ # model attributes to OpenStack provider attributes
+ aliases = {
+ :provider_network_type => 'provider:network_type',
+ # Not applicable to the "local" or "gre" network types
+ :provider_physical_network => 'provider:physical_network',
+ :provider_segmentation_id => 'provider:segmentation_id',
+ :router_external => 'router:external'
+ }
+
+ provider_options.reject{ |o| options[o].nil? }.each do |key|
+ aliased_key = aliases[key] || key
+ data['network'][aliased_key] = options[key]
+ end
+
request(
:body => Fog::JSON.encode(data),
:expects => [201],
:method => 'POST',
:path => 'networks'
@@ -31,14 +65,35 @@
'subnets' => [],
'status' => 'ACTIVE',
'admin_state_up' => options[:admin_state_up],
'tenant_id' => options[:tenant_id],
}
+
+ # Add provider specific attributes when found
+ #
+ provider_options = [
+ :router_external,
+ :provider_network_type,
+ :provider_segmentation_id,
+ :provider_physical_network
+ ]
+ aliases = {
+ :provider_network_type => 'provider:network_type',
+ # Not applicable to the "local" or "gre" network types
+ :provider_physical_network => 'provider:physical_network',
+ :provider_segmentation_id => 'provider:segmentation_id',
+ :router_external => 'router:external'
+ }
+ provider_options.reject{ |o| options[o].nil? }.each do |key|
+ aliased_key = aliases[key] || key
+ data[aliased_key] = options[key]
+ end
+
self.data[:networks][data['id']] = data
response.body = { 'network' => data }
response
end
end
end
end
-end
\ No newline at end of file
+end