-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
135 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
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
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
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
25 changes: 25 additions & 0 deletions
25
source/lib/vagrant-openstack-provider/command/subnet_list.rb
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,25 @@ | ||
require 'vagrant-openstack-provider/command/utils' | ||
require 'vagrant-openstack-provider/command/abstract_command' | ||
|
||
module VagrantPlugins | ||
module Openstack | ||
module Command | ||
class SubnetList < AbstractCommand | ||
include VagrantPlugins::Openstack::Command::Utils | ||
|
||
def self.synopsis | ||
I18n.t('vagrant_openstack.command.subnet_list_synopsis') | ||
end | ||
|
||
def cmd(name, argv, env) | ||
fail Errors::NoArgRequiredForCommand, cmd: name unless argv.size == 0 | ||
rows = [] | ||
env[:openstack_client].neutron.get_subnets(env).each do |subnet| | ||
rows << [subnet.id, subnet.name, subnet.cidr, subnet.enable_dhcp, subnet.network_id] | ||
end | ||
display_table(env, ['Id', 'Name', 'CIDR', 'DHCP', 'Network Id'], rows) | ||
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
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
46 changes: 46 additions & 0 deletions
46
source/spec/vagrant-openstack-provider/command/subnet_list_spec.rb
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,46 @@ | ||
require 'vagrant-openstack-provider/spec_helper' | ||
|
||
describe VagrantPlugins::Openstack::Command::SubnetList do | ||
describe 'cmd' do | ||
|
||
let(:neutron) do | ||
double('neutron').tap do |neutron| | ||
neutron.stub(:get_subnets) do | ||
[ | ||
Subnet.new('subnet-01', 'Subnet 1', '192.168.1.0/24', true, 'net-01'), | ||
Subnet.new('subnet-02', 'Subnet 2', '192.168.2.0/24', false, 'net-01'), | ||
Subnet.new('subnet-03', 'Subnet 3', '192.168.100.0/24', true, 'net-02') | ||
] | ||
end | ||
end | ||
end | ||
|
||
let(:env) do | ||
Hash.new.tap do |env| | ||
env[:ui] = double('ui') | ||
env[:ui].stub(:info).with(anything) | ||
env[:openstack_client] = double | ||
env[:openstack_client].stub(:neutron) { neutron } | ||
end | ||
end | ||
|
||
before :each do | ||
@subnet_list_cmd = VagrantPlugins::Openstack::Command::SubnetList.new(nil, env) | ||
end | ||
|
||
it 'prints subnet list from server' do | ||
neutron.should_receive(:get_subnets).with(env) | ||
|
||
expect(env[:ui]).to receive(:info).with(' | ||
+-----------+----------+------------------+-------+------------+ | ||
| Id | Name | CIDR | DHCP | Network Id | | ||
+-----------+----------+------------------+-------+------------+ | ||
| subnet-01 | Subnet 1 | 192.168.1.0/24 | true | net-01 | | ||
| subnet-02 | Subnet 2 | 192.168.2.0/24 | false | net-01 | | ||
| subnet-03 | Subnet 3 | 192.168.100.0/24 | true | net-02 | | ||
+-----------+----------+------------------+-------+------------+') | ||
|
||
@subnet_list_cmd.cmd('subnet-list', [], env) | ||
end | ||
end | ||
end |