Skip to content

Commit

Permalink
Add create_network and delete_network to CPI methods
Browse files Browse the repository at this point in the history
  • Loading branch information
medvedzver committed Aug 8, 2018
1 parent c568270 commit 9095ead
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/bosh/cpi/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Bosh::Cpi::Cli
resize_disk
ping
calculate_vm_cloud_properties
create_network
delete_network
).freeze

RPC_METHOD_TO_RUBY_METHOD = {
Expand Down
19 changes: 19 additions & 0 deletions lib/cloud_v1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,25 @@ def calculate_vm_cloud_properties(vm_properties)
not_implemented(:calculate_vm_cloud_properties)
end

##
# Creates a network that will be used to place VMs on.
#
# @param [Hash] network_definition properties required for creating network.
# may contain range and gateway keys. Has to have cloud_properties - properties required for creating
# this network specific to a CPI
# @return [Hash] network_cid key has unique id of network, cloud_properties are properties required for placing VMs
def create_network(network_definition)
not_implemented(:create_network)
end

##
# Deletes network by given network_id
# @param [String] network_id of network to delete
# @return [void]
def delete_network(network_id)
not_implemented(:delete_network)
end

private

def not_implemented(method)
Expand Down
44 changes: 44 additions & 0 deletions spec/unit/cpi/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,50 @@ def make_result_regexp(result, error = 'null', log_string = 'fake-log')
end
end

describe 'create_network' do
let(:network_definition) {
{ 'range' => '192.68.1.1' }
}
let(:created_network) {
[ 'network-cid', {}, {cloud_properties: {}} ]
}
it 'takes json and calls specified method on the cpi' do
expect(cpi).to(receive(:create_network).
with(network_definition)).
and_return([created_network])

subject.run <<-JSON
{
"method": "create_network",
"arguments": [ {"range": "192.68.1.1"} ],
"context" : { "director_uuid" : "abc" }
}
JSON

expect(result_io.string).to match('network-cid')
end
end

describe 'delete_network' do
let(:network_id) { 'network-id' }

it 'takes json and calls specified method on the cpi' do
expect(cpi).to(receive(:delete_network).
with('network-id')) { logs_io.write('fake-log') }.
and_return(nil)


subject.run <<-JSON
{
"method": "delete_network",
"arguments": [ "network-id" ],
"context" : { "director_uuid" : "abc" }
}
JSON
expect(result_io.string).to match(make_result_regexp(nil))
end
end

context 'when request json cannot be parsed' do
it 'returns invalid_call error' do
subject.run('invalid-json')
Expand Down

0 comments on commit 9095ead

Please sign in to comment.