-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from opscode/pd-network-list
Network list implementation
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Author:: Prabhu Das (<[email protected]>) | ||
# Copyright:: Copyright (c) 2014 Chef Software, Inc. | ||
|
||
require 'chef/knife/cloud/list_resource_command' | ||
require 'chef/knife/openstack_helpers' | ||
require 'chef/knife/cloud/openstack_service_options' | ||
|
||
class Chef | ||
class Knife | ||
class Cloud | ||
class OpenstackNetworkList < ResourceListCommand | ||
include OpenstackHelpers | ||
include OpenstackServiceOptions | ||
|
||
banner "knife openstack network list (options)" | ||
|
||
def before_exec_command | ||
#set columns_with_info map | ||
@columns_with_info = [ | ||
{:label => 'Name', :key => 'name'}, | ||
{:label => 'ID', :key => 'id'}, | ||
{:label => 'Tenant', :key => 'tenant_id'}, | ||
{:label => 'Shared', :key => 'shared'} | ||
] | ||
end | ||
|
||
def query_resource | ||
@service.list_networks | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'spec_helper' | ||
require 'chef/knife/openstack_network_list' | ||
require 'chef/knife/cloud/openstack_service' | ||
require 'support/shared_examples_for_command' | ||
|
||
describe Chef::Knife::Cloud::OpenstackNetworkList do | ||
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackNetworkList.new | ||
|
||
let (:instance) {Chef::Knife::Cloud::OpenstackNetworkList.new} | ||
|
||
context "#validate!" do | ||
before(:each) do | ||
Chef::Config[:knife][:openstack_username] = "testuser" | ||
Chef::Config[:knife][:openstack_password] = "testpassword" | ||
Chef::Config[:knife][:openstack_auth_url] = "tsturl" | ||
instance.stub(:exit) | ||
end | ||
|
||
it "validate openstack mandatory options" do | ||
expect {instance.validate!}.to_not raise_error | ||
end | ||
|
||
it "raise error on openstack_username missing" do | ||
Chef::Config[:knife].delete(:openstack_username) | ||
instance.ui.should_receive(:error).with("You did not provide a valid 'Openstack Username' value.") | ||
expect { instance.validate! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError) | ||
end | ||
|
||
it "raise error on openstack_password missing" do | ||
Chef::Config[:knife].delete(:openstack_password) | ||
instance.ui.should_receive(:error).with("You did not provide a valid 'Openstack Password' value.") | ||
expect { instance.validate! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError) | ||
end | ||
|
||
it "raise error on openstack_auth_url missing" do | ||
Chef::Config[:knife].delete(:openstack_auth_url) | ||
instance.ui.should_receive(:error).with("You did not provide a valid 'Openstack Auth Url' value.") | ||
expect { instance.validate! }.to raise_error(Chef::Knife::Cloud::CloudExceptions::ValidationError) | ||
end | ||
end | ||
|
||
context "query_resource" do | ||
it "returns the networks using the fog service." do | ||
instance.service = double | ||
instance.service.should_receive(:list_networks) | ||
instance.query_resource | ||
end | ||
end | ||
end |