From d102e74e2bcfe177c3efb7b35e7f5b499ec0bffe Mon Sep 17 00:00:00 2001 From: Rupak Ganguly Date: Thu, 21 Mar 2013 16:55:42 -0400 Subject: [PATCH] [hp|network] Add request method for update_network. --- lib/fog/hp/network.rb | 2 +- lib/fog/hp/requests/network/update_network.rb | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 lib/fog/hp/requests/network/update_network.rb diff --git a/lib/fog/hp/network.rb b/lib/fog/hp/network.rb index 086074d03..ed8a7b20c 100644 --- a/lib/fog/hp/network.rb +++ b/lib/fog/hp/network.rb @@ -17,7 +17,7 @@ module Fog request :delete_network request :get_network request :list_networks - #request :update_network + request :update_network module Utils diff --git a/lib/fog/hp/requests/network/update_network.rb b/lib/fog/hp/requests/network/update_network.rb new file mode 100644 index 000000000..06fb99249 --- /dev/null +++ b/lib/fog/hp/requests/network/update_network.rb @@ -0,0 +1,61 @@ +module Fog + module HP + class Network + + class Real + # Update attributes for an existing network + # + # ==== 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 + # + # ==== 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 + # * 'admin_state_up'<~Boolean>: - true or false + # * 'shared'<~Boolean>: - true or false + def update_network(network_id, options = {}) + data = { 'network' => {} } + + l_options = [:name, :admin_state_up, :shared] + l_options.select{|o| options[o]}.each do |key| + data['network'][key] = options[key] + end + + request( + :body => Fog::JSON.encode(data), + :expects => 200, + :method => 'PUT', + :path => "networks/#{network_id}" + ) + end + end + + class Mock + def update_network(network_id, options = {}) + response = Excon::Response.new + if network = list_networks.body['networks'].detect {|_| _['id'] == network_id} + network['name'] = options[:name] + network['shared'] = options[:shared] + network['admin_state_up'] = options[:admin_state_up] + response.body = { 'network' => network } + response.status = 200 + response + else + raise Fog::HP::Network::NotFound + end + end + end + + end + end +end