vcloud-net_launcher 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ /Gemfile.lock
2
+ results.html
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ if ENV['VCLOUD_CORE_DEV_MASTER']
6
+ gem 'vcloud-core', :git => 'git@github.com:alphagov/vcloud-core.git', :branch => 'master'
7
+ elsif ENV['VCLOUD_CORE_DEV_LOCAL']
8
+ gem 'vcloud-core', :path => '../vcloud-core'
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 HM Government (Government Digital Service)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ vCloud Net Launcher
2
+ ===================
3
+
4
+ A tool that takes a YAML configuration file describing vCloud networks and configures each of them.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'vcloud-net_launcher'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install vcloud-net_launcher
19
+
20
+ ## Usage
21
+
22
+ vCloud-tools uses Fog.
23
+
24
+ To use it you need a `.fog` file in your home directory.
25
+
26
+ For example:
27
+
28
+ test:
29
+ vcloud_director_username: 'username@org_name'
30
+ vcloud_director_password: 'password'
31
+ vcloud_director_host: 'host.api.example.com'
32
+
33
+ Unfortunately current usage of fog requires the password in this file. Multiple sets of credentials can be specified in the fog file, using the following format:
34
+
35
+ test:
36
+ vcloud_director_username: 'username@org_name'
37
+ vcloud_director_password: 'password'
38
+ vcloud_director_host: 'host.api.example.com'
39
+
40
+ test2:
41
+ vcloud_director_username: 'username@org_name'
42
+ vcloud_director_password: 'password'
43
+ vcloud_director_host: 'host.api.vendor.net'
44
+
45
+ You can then pass the `FOG_CREDENTIAL` environment variable at the start of your command. The value of the `FOG_CREDENTIAL` environment variable is the name of the credential set in your fog file which you wish to use. For instance:
46
+
47
+ FOG_CREDENTIAL=test2 vcloud-net-launch node.yaml
48
+
49
+ An example configuration file is located in [examples/vcloud-net-launch][example_yaml]
50
+
51
+
52
+ ##Supports
53
+
54
+ * Configuration of multiple networks
55
+ * Supports natRouted and isolated network types
56
+ * Accepts multiple ip address ranges
57
+ * Defaults
58
+ * IsShared : false
59
+ * IpScope -> IsEnabled : true
60
+ * IpScope -> IsInherited : false
61
+
62
+ Limitations
63
+
64
+ * Not currently reentrant - if the process errors part of the way through, the previously applied network config
65
+ will need to be removed from the file before it is corrected and run again.
66
+
67
+ ## Contributing
68
+
69
+ 1. Fork it
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create new Pull Request
74
+
75
+ ## Other settings
76
+
77
+ vCloud Net Launcher uses vCloud Core. If you want to use the latest version of vCloud Core, or a local version, you can export some variables. See the Gemfile for details.
78
+
79
+ ## Testing
80
+
81
+ Default target: `bundle exec rake` runs the integration tests.
82
+
83
+ You need access to a suitable vCloud Director organization to run the
84
+ integration tests. It is not necessarily safe to run them against an existing
85
+ environment, unless care is taken with the entities being tested.
86
+
87
+ The easiest thing to do is create a local shell script called
88
+ `vcloud_env.sh` and set the contents:
89
+
90
+ export FOG\_CREDENTIAL=test
91
+ export VCLOUD\_VDC\_NAME="Name of the VDC"
92
+ export VCLOUD\_CATALOG\_NAME="catalog-name"
93
+ export VCLOUD\_TEMPLATE\_NAME="name-of-template"
94
+ export VCLOUD\_NETWORK1\_NAME="name-of-primary-network"
95
+ export VCLOUD\_NETWORK2\_NAME="name-of-secondary-network"
96
+ export VCLOUD\_NETWORK1\_IP="ip-on-primary-network"
97
+ export VCLOUD\_NETWORK2\_IP="ip-on-secondary-network"
98
+ export VCLOUD\_TEST\_STORAGE\_PROFILE="storage-profile-name"
99
+ export VCLOUD\_EDGE\_GATEWAY="name-of-edge-gateway-in-vdc"
100
+
101
+ Then run this before you run the integration tests.
102
+
103
+ [example_yaml]: ../examples/vcloud-net-launch/
104
+
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require 'cucumber/rake/task'
2
+ require 'rspec/core/rake_task'
3
+
4
+ CUKE_RESULTS = 'results.html'
5
+
6
+ Cucumber::Rake::Task.new(:features) do |t|
7
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty --no-source -x"
8
+ t.fork = false
9
+ end
10
+
11
+ RSpec::Core::RakeTask.new(:spec) do |task|
12
+ # Set a bogus Fog credential, otherwise it's possible for the unit
13
+ # tests to accidentially run (and succeed against!) an actual
14
+ # environment, if Fog connection is not stubbed correctly.
15
+ ENV['FOG_CREDENTIAL'] = 'random_nonsense_owiejfoweijf'
16
+ task.pattern = FileList['spec/vcloud/**/*_spec.rb']
17
+ end
18
+
19
+ RSpec::Core::RakeTask.new('integration') do |t|
20
+ t.pattern = FileList['spec/integration/**/*_spec.rb']
21
+ end
22
+
23
+ task :default => [:integration]
24
+
25
+ require "gem_publisher"
26
+ task :publish_gem do |t|
27
+ gem = GemPublisher.publish_if_updated("vcloud-net_launcher.gemspec", :rubygems)
28
+ puts "Published #{gem}" if gem
29
+ end
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'optparse'
6
+ require 'methadone'
7
+
8
+ require 'vcloud/net_launcher'
9
+
10
+ class App
11
+ include Methadone::Main
12
+ include Methadone::CLILogging
13
+ include Vcloud
14
+
15
+ main do |net_config_file|
16
+ NetLauncher::NetLaunch.new.run(net_config_file, options)
17
+ end
18
+
19
+ on("-m", "--mock", "Fog Mock mode enabled")
20
+
21
+ arg :net_config_file
22
+
23
+ examples_dir = File.absolute_path(
24
+ File.join(
25
+ File.dirname(__FILE__),
26
+ "..",
27
+ "examples",
28
+ File.basename(__FILE__),
29
+ ))
30
+
31
+ description "
32
+ vcloud-net-launch takes a configuration describing a vCloud network,
33
+ and tries to make it a reality.
34
+
35
+ See https://github.com/alphagov/vcloud-tools for more info
36
+
37
+ Example configuration files can be found in:
38
+ #{examples_dir}
39
+ "
40
+
41
+ version Vcloud::NetLauncher::VERSION
42
+
43
+ go!
44
+ end
@@ -0,0 +1,15 @@
1
+ p1-production:
2
+ vcloud_director_username: '<username_from_top_right_of_skyscape_flash_ui>@<org_id_from_url_in_skyscape_flash_ui>'
3
+ vcloud_director_password: '<your_skyscape_password>'
4
+ vcloud_director_host: 'vcd.portal.skyscapecloud.com'
5
+
6
+ # You can extract this information by logging into skyscape portal
7
+ performance-platform-production:
8
+ vcloud_director_username: '<xxx.x.xxxxxx>@<x-x-xx-xxxxxx>'
9
+ vcloud_director_password: '<your_skyscape_password>'
10
+ vcloud_director_host: 'vcd.portal.skyscapecloud.com'
11
+
12
+ carrenza-preview:
13
+ vcloud_director_username: '<email>@<org_id>'
14
+ vcloud_director_password: ''
15
+ vcloud_director_host: 'myvdc.carrenza.net'
@@ -0,0 +1,41 @@
1
+ # This example creates two orgVdcNetworks - one natRouted, the other isolated
2
+ #
3
+ # dns settings and ip_ranges are optional
4
+ #
5
+ # example-net-isolated-shared has is_shared set, which means that it will be
6
+ # available across all vDCs in the org (though is 'owned' by 'Our vDC').
7
+ #
8
+ ---
9
+ org_vdc_networks:
10
+
11
+ - name: example-net-routed-1
12
+ description: "Frontend example network"
13
+ vdc_name: 'Our vDC'
14
+ fence_mode: natRouted
15
+ edge_gateway: Gateway-FRONTEND
16
+ netmask: 255.255.255.0
17
+ gateway: 192.0.2.1
18
+ dns1: 8.8.8.8
19
+ dns2: 8.8.4.4
20
+ dns_suffix: testing.example.com
21
+ ip_ranges:
22
+ - start_address: 192.0.2.11
23
+ end_address: 192.0.2.40
24
+ - start_address: 192.0.2.101
25
+ end_address: 192.0.2.140
26
+
27
+ - name: example-net-isolated-shared
28
+ vdc_name: 'Our vDC'
29
+ fence_mode: isolated
30
+ is_shared: true
31
+ netmask: 255.255.255.0
32
+ gateway: 198.51.100.1
33
+ dns1: 8.8.8.8
34
+ dns2: 8.8.4.4
35
+ dns_suffix: testing.example.com
36
+ ip_ranges:
37
+ - start_address: 198.51.100.11
38
+ end_address: 198.51.100.40
39
+ - start_address: 198.51.100.101
40
+ end_address: 198.51.100.140
41
+
@@ -0,0 +1,3 @@
1
+ Then(/^the banner should document that this app takes (\d+) argument$/) do |arg1|
2
+ pending # express the regexp above with the code you wish you had
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'aruba/cucumber'
2
+ require 'methadone/cucumber'
3
+
4
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
5
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
6
+
7
+ Before do
8
+ # Using "announce" causes massive warnings on 1.9.2
9
+ @puts = true
10
+ @original_rubylib = ENV['RUBYLIB']
11
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
12
+ end
13
+
14
+ After do
15
+ ENV['RUBYLIB'] = @original_rubylib
16
+ end
@@ -0,0 +1,15 @@
1
+ Feature: "vcloud-net-launch" works as a useful command-line tool
2
+ In order to use "vcloud-net-launch" from the CLI
3
+ I want to have it behave like a typical Unix tool
4
+ So I don't get surpised
5
+
6
+ Scenario: Common arguments work
7
+ When I get help for "vcloud-net-launch"
8
+ Then the exit status should be 0
9
+ And the banner should be present
10
+ And the banner should document that this app takes options
11
+ And the following options should be documented:
12
+ |--version|
13
+ |--mock|
14
+ And the banner should document that this app's arguments are:
15
+ |net_config_file|
data/jenkins.sh ADDED
@@ -0,0 +1,13 @@
1
+ #!/bin/bash -x
2
+ set -e
3
+ bundle install --path "${HOME}/bundles/${JOB_NAME}"
4
+ # commented out for now as there are no unit tests
5
+ # and rake aefault is currently integration test
6
+ # bundle exec rake
7
+
8
+ ./scripts/generate_fog_conf_file.sh
9
+ export FOG_RC=fog_integration_test.config
10
+ bundle exec rake integration
11
+ rm fog_integration_test.config
12
+
13
+ bundle exec rake publish_gem
@@ -0,0 +1,8 @@
1
+ #!/bin/bash -x
2
+ set -e
3
+ bundle install --path "${HOME}/bundles/${JOB_NAME}"
4
+
5
+ ./scripts/generate_fog_conf_file.sh
6
+ export FOG_RC=fog_integration_test.config
7
+ bundle exec rake integration
8
+ rm fog_integration_test.config
@@ -0,0 +1,31 @@
1
+ require 'fog'
2
+
3
+ module Vcloud
4
+ module NetLauncher
5
+ class NetLaunch
6
+
7
+ def initialize
8
+ @config_loader = Vcloud::Core::ConfigLoader.new
9
+ end
10
+
11
+ def run(config_file = nil, options = {})
12
+ config = @config_loader.load_config(config_file)
13
+
14
+ if options[:mock] || ENV['FOG_MOCK']
15
+ ::Fog.mock!
16
+ end
17
+
18
+ config[:org_vdc_networks].each do |net_config|
19
+ net_config[:fence_mode] ||= 'isolated'
20
+ Vcloud::NetLauncher.logger.info("Provisioning orgVdcNetwork #{net_config[:name]}.")
21
+ begin
22
+ net = Vcloud::Core::OrgVdcNetwork.provision(net_config)
23
+ rescue RuntimeError => e
24
+ Vcloud::NetLauncher.logger.error("Could not provision orgVdcNetwork: #{e.message}")
25
+ raise
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module Vcloud
2
+ module NetLauncher
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'json'
4
+ require 'yaml'
5
+ require 'csv'
6
+ require 'open3'
7
+ require 'pp'
8
+
9
+ require 'vcloud/net_launcher/version'
10
+
11
+ require 'vcloud/fog'
12
+ require 'vcloud/core'
13
+
14
+ require 'vcloud/net_launcher/net_launch'
15
+
16
+ module Vcloud
17
+ module NetLauncher
18
+
19
+ def self.logger
20
+ @logger ||= Logger.new(STDOUT)
21
+ end
22
+
23
+ end
24
+ end
data/scripts/basic.erb ADDED
@@ -0,0 +1,13 @@
1
+ #!/bin/sh
2
+
3
+ (
4
+ echo "============================================================"
5
+ echo "in ${1}:"
6
+ echo "vapp_name: <%= vapp_name -%>"
7
+ echo "role: <%= vars[:role] -%>"
8
+ echo "environment: <%= vars[:environment] -%>"
9
+ echo
10
+ env
11
+ ) >> /PREAMBLE_OUT
12
+
13
+
@@ -0,0 +1,6 @@
1
+ cat <<EOF >fog_integration_test.config
2
+ default:
3
+ vcloud_director_username: '$API_USERNAME'
4
+ vcloud_director_password: '$API_PASSWORD'
5
+ vcloud_director_host: '$API_HOST'
6
+ EOF
@@ -0,0 +1,11 @@
1
+ class ErbHelper
2
+ def self.convert_erb_template_to_yaml test_namespace, input_erb_config
3
+ input_erb_config = input_erb_config
4
+ e = ERB.new(File.open(input_erb_config).read)
5
+ output_yaml_config = File.join(File.dirname(input_erb_config), "output_#{Time.now.strftime('%s')}.yaml")
6
+ File.open(output_yaml_config, 'w') { |f|
7
+ f.write e.result(OpenStruct.new(test_namespace).instance_eval { binding })
8
+ }
9
+ output_yaml_config
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ ---
2
+ org_vdc_networks:
3
+
4
+ - name: <%= network_name %>
5
+ vdc_name: <%= vdc_name %>
6
+ fence_mode: <%= fence_mode %>
7
+ netmask: <%= netmask %>
8
+ gateway: <%= gateway %>
9
+ edge_gateway: <%= edgeGateway %>
@@ -0,0 +1,151 @@
1
+ require 'spec_helper'
2
+ require 'pp'
3
+
4
+ describe Vcloud::Core::OrgVdcNetwork do
5
+
6
+ context "natRouted network" do
7
+
8
+ before(:all) do
9
+ test_data = define_test_data
10
+ @config = {
11
+ :name => test_data[:name],
12
+ :description => "Integration Test network #{@name}",
13
+ :vdc_name => test_data[:vdc_name],
14
+ :fence_mode => 'natRouted',
15
+ :edge_gateway => test_data[:edge_gateway_name],
16
+ :gateway => '10.88.11.1',
17
+ :netmask => '255.255.255.0',
18
+ :dns1 => '8.8.8.8',
19
+ :dns2 => '8.8.4.4',
20
+ :ip_ranges => [
21
+ { :start_address => '10.88.11.100',
22
+ :end_address => '10.88.11.150' },
23
+ { :start_address => '10.88.11.200',
24
+ :end_address => '10.88.11.250' },
25
+ ],
26
+ }
27
+ @net = Vcloud::Core::OrgVdcNetwork.provision(@config)
28
+ end
29
+
30
+ it 'should be an OrgVdcNetwork' do
31
+ expect(@net.class).to be(Vcloud::Core::OrgVdcNetwork)
32
+ end
33
+
34
+ it 'should have an id' do
35
+ expect(@net.id).to match(/^[0-9a-f-]+$/)
36
+ end
37
+
38
+ it 'should have a name' do
39
+ expect(@net.name) == @config[:name]
40
+ end
41
+
42
+ it 'should have a :gateway attribute' do
43
+ expect(@net.vcloud_attributes[:gateway]) == @config[:gateway]
44
+ end
45
+
46
+ it 'should have a :netmask attribute' do
47
+ expect(@net.vcloud_attributes[:gateway]) == @config[:netmask]
48
+ end
49
+
50
+ it 'should have a :dns1 attribute' do
51
+ expect(@net.vcloud_attributes[:dns1]) == @config[:dns1]
52
+ end
53
+
54
+ it 'should have a :dns2 attribute' do
55
+ expect(@net.vcloud_attributes[:dns2]) == @config[:dns2]
56
+ end
57
+
58
+ it 'should have an :ip_ranges attribute' do
59
+ expect(@net.vcloud_attributes[:ip_ranges]) == [
60
+ {:start_address=>"10.88.11.200", :end_address=>"10.88.11.250"},
61
+ {:start_address=>"10.88.11.100", :end_address=>"10.88.11.150"}
62
+ ]
63
+ end
64
+
65
+ after(:all) do
66
+ unless ENV['VCLOUD_TOOLS_RSPEC_NO_DELETE_ORG_VDC_NETWORK']
67
+ Vcloud::Fog::ServiceInterface.new.delete_network(@net.id) if @net
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ context "isolated network" do
74
+
75
+ before(:all) do
76
+ test_data = define_test_data
77
+ @config = {
78
+ :name => test_data[:name],
79
+ :description => "Integration Test network #{@name}",
80
+ :vdc_name => test_data[:vdc_name],
81
+ :fence_mode => 'isolated',
82
+ :gateway => '10.88.11.1',
83
+ :netmask => '255.255.255.0',
84
+ :dns1 => '8.8.8.8',
85
+ :dns2 => '8.8.4.4',
86
+ :ip_ranges => [
87
+ { :start_address => '10.88.11.100',
88
+ :end_address => '10.88.11.150' },
89
+ { :start_address => '10.88.11.200',
90
+ :end_address => '10.88.11.250' },
91
+ ],
92
+ }
93
+ @net = Vcloud::Core::OrgVdcNetwork.provision(@config)
94
+ end
95
+
96
+ it 'should be an OrgVdcNetwork' do
97
+ expect(@net.class).to be(Vcloud::Core::OrgVdcNetwork)
98
+ end
99
+
100
+ it 'should have an id' do
101
+ expect(@net.id).to match(/^[0-9a-f-]+$/)
102
+ end
103
+
104
+ it 'should have a name' do
105
+ expect(@net.name) == @config[:name]
106
+ end
107
+
108
+ it 'should have a :gateway attribute' do
109
+ expect(@net.vcloud_attributes[:gateway]) == @config[:gateway]
110
+ end
111
+
112
+ it 'should have a :netmask attribute' do
113
+ expect(@net.vcloud_attributes[:gateway]) == @config[:netmask]
114
+ end
115
+
116
+ it 'should have a :dns1 attribute' do
117
+ expect(@net.vcloud_attributes[:dns1]) == @config[:dns1]
118
+ end
119
+
120
+ it 'should have a :dns2 attribute' do
121
+ expect(@net.vcloud_attributes[:dns2]) == @config[:dns2]
122
+ end
123
+
124
+ it 'should have an :ip_ranges attribute' do
125
+ expect(@net.vcloud_attributes[:ip_ranges]) == [
126
+ {:start_address=>"10.88.11.200", :end_address=>"10.88.11.250"},
127
+ {:start_address=>"10.88.11.100", :end_address=>"10.88.11.150"}
128
+ ]
129
+ end
130
+
131
+ after(:all) do
132
+ unless ENV['VCLOUD_TOOLS_RSPEC_NO_DELETE_ORG_VDC_NETWORK']
133
+ Vcloud::Fog::ServiceInterface.new.delete_network(@net.id) if @net
134
+ end
135
+ end
136
+
137
+ end
138
+
139
+ def define_test_data
140
+ [ 'VCLOUD_VDC_NAME', 'VCLOUD_EDGE_GATEWAY' ].each do |n|
141
+ raise "Need #{n} set" unless ENV[n]
142
+ end
143
+ {
144
+ :name => "orgVdcNetwork-vcloud-tools-tests #{Time.now.strftime('%s')}",
145
+ :vdc_name => ENV['VCLOUD_VDC_NAME'],
146
+ :edge_gateway_name => ENV['VCLOUD_EDGE_GATEWAY'],
147
+ }
148
+ end
149
+
150
+ end
151
+
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+ require 'pp'
3
+ require 'erb'
4
+
5
+ module Vcloud
6
+ module NetLauncher
7
+ describe NetLaunch do
8
+
9
+ context 'with minimum input setup' do
10
+
11
+ it 'should create an isolated network' do
12
+ test_data = default_test_data('isolated')
13
+ @minimum_data_yaml = generate_data_file(test_data)
14
+
15
+ Vcloud::NetLauncher::NetLaunch.new.run(@minimum_data_yaml)
16
+
17
+ @found_networks = find_network(test_data[:network_name])
18
+ @found_networks.length.should == 1
19
+ provisioned_network = @found_networks[0]
20
+ provisioned_network[:gateway].should == test_data[:gateway]
21
+ provisioned_network[:netmask].should == test_data[:netmask]
22
+ provisioned_network[:isLinked].should == 'false'
23
+ end
24
+
25
+ it 'should create an nat routed network' do
26
+ test_data = default_test_data('natRouted')
27
+ test_data[:edgeGateway] = ENV['VCLOUD_EDGE_GATEWAY'] #only needed for natRouted networks
28
+ @minimum_data_yaml = generate_data_file(test_data)
29
+
30
+ Vcloud::NetLauncher::NetLaunch.new.run(@minimum_data_yaml)
31
+
32
+ @found_networks = find_network(test_data[:network_name])
33
+
34
+ @found_networks.length.should == 1
35
+ provisioned_network = @found_networks[0]
36
+ provisioned_network[:gateway].should == test_data[:gateway]
37
+ provisioned_network[:netmask].should == test_data[:netmask]
38
+ provisioned_network[:isLinked].should == 'true'
39
+ end
40
+
41
+ after(:each) do
42
+ unless ENV['VCLOUD_TOOLS_RSPEC_NO_DELETE_VAPP']
43
+ File.delete @minimum_data_yaml
44
+ fog_interface = Vcloud::Fog::ServiceInterface.new
45
+ provisioned_network_id = @found_networks[0][:href].split('/').last
46
+ fog_interface.delete_network(provisioned_network_id).should == true
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ def default_test_data(type)
53
+ {
54
+ network_name: "vapp-vcloud-tools-tests-#{Time.now.strftime('%s')}",
55
+ vdc_name: ENV['VCLOUD_VDC_NAME'],
56
+ fence_mode: type,
57
+ netmask: '255.255.255.0',
58
+ gateway: '192.0.2.1',
59
+ }
60
+ end
61
+
62
+ def find_network(network_name)
63
+ query = Vcloud::QueryRunner.new()
64
+ query.run('orgNetwork', :filter => "name==#{network_name}")
65
+ end
66
+
67
+ def generate_data_file(test_data)
68
+ minimum_data_erb = File.join(File.dirname(__FILE__), 'data/minimum_data_setup.yaml.erb')
69
+ ErbHelper.convert_erb_template_to_yaml(test_data, minimum_data_erb)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,4 @@
1
+ require 'erb_helper'
2
+ require 'bundler/setup'
3
+ require 'vcloud/net_launcher'
4
+ require 'support/stub_fog_interface.rb'
@@ -0,0 +1,59 @@
1
+ require 'ostruct'
2
+
3
+ class StubFogInterface
4
+
5
+ def name
6
+ 'Test vDC 1'
7
+ end
8
+
9
+ def vdc_object_by_name(vdc_name)
10
+ vdc = OpenStruct.new
11
+ vdc.name = 'test-vdc-1'
12
+ vdc
13
+ end
14
+
15
+ def template
16
+ { :href => '/vappTemplate-12345678-90ab-cdef-0123-4567890abcde' }
17
+ end
18
+
19
+ def find_networks(network_names, vdc_name)
20
+ [{
21
+ :name => 'org-vdc-1-net-1',
22
+ :href => '/org-vdc-1-net-1-id',
23
+ }]
24
+ end
25
+
26
+ def get_vapp(id)
27
+ { :name => 'test-vapp-1' }
28
+ end
29
+
30
+ def get_edge_gateway(id)
31
+ {
32
+ :name => 'test-edgegw-1',
33
+ :href => "/#{id}",
34
+ }
35
+ end
36
+
37
+ def vdc(name)
38
+ { }
39
+ end
40
+
41
+ def post_instantiate_vapp_template(vdc, template, name, params)
42
+ {
43
+ :href => '/test-vapp-1-id',
44
+ :Children => {
45
+ :Vm => ['bogus vm data']
46
+ }
47
+ }
48
+ end
49
+
50
+ def get_vapp_by_vdc_and_name
51
+ { }
52
+ end
53
+
54
+ def template(catalog_name, name)
55
+ { :href => '/vappTemplate-12345678-90ab-cdef-0123-4567890abcde' }
56
+ end
57
+
58
+
59
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path('../lib/', __FILE__)
4
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'vcloud/net_launcher/version'
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = 'vcloud-net_launcher'
10
+ s.version = Vcloud::NetLauncher::VERSION
11
+ s.authors = ['Anna Shipman']
12
+ s.email = ['anna.shipman@digital.cabinet-office.gov.uk']
13
+ s.summary = 'Tool to launch and configure vCloud networks'
14
+ s.description = 'Tool to launch and configure vCloud networks. Uses vcloud-core.'
15
+ s.homepage = 'http://github.com/alphagov/vcloud-net_launcher'
16
+ s.license = 'MIT'
17
+
18
+ s.files = `git ls-files`.split($/)
19
+ s.executables = s.files.grep(%r{^bin/}) {|f| File.basename(f)}
20
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
21
+ s.require_paths = ['lib']
22
+
23
+ s.required_ruby_version = '>= 1.9.2'
24
+
25
+ s.add_runtime_dependency 'vcloud-core', '>= 0.0.9'
26
+ s.add_runtime_dependency 'methadone'
27
+ s.add_development_dependency 'rake'
28
+ s.add_development_dependency 'rspec', '~> 2.14.1'
29
+ s.add_development_dependency 'cucumber', '~> 1.3.10'
30
+ s.add_development_dependency 'gem_publisher', '1.2.0'
31
+ end
32
+
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vcloud-net_launcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anna Shipman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-03-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vcloud-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.9
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.9
30
+ - !ruby/object:Gem::Dependency
31
+ name: methadone
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.14.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.14.1
78
+ - !ruby/object:Gem::Dependency
79
+ name: cucumber
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.3.10
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.3.10
94
+ - !ruby/object:Gem::Dependency
95
+ name: gem_publisher
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - '='
100
+ - !ruby/object:Gem::Version
101
+ version: 1.2.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - '='
108
+ - !ruby/object:Gem::Version
109
+ version: 1.2.0
110
+ description: Tool to launch and configure vCloud networks. Uses vcloud-core.
111
+ email:
112
+ - anna.shipman@digital.cabinet-office.gov.uk
113
+ executables:
114
+ - vcloud-net-launch
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - bin/vcloud-net-launch
124
+ - examples/.fog-example.fog
125
+ - examples/vcloud-net-launch/example-config.yaml
126
+ - features/step_definitions/vcloud-launch_steps.rb
127
+ - features/support/env.rb
128
+ - features/vcloud-net-launch.feature
129
+ - jenkins.sh
130
+ - jenkins_integration_tests.sh
131
+ - lib/vcloud/net_launcher.rb
132
+ - lib/vcloud/net_launcher/net_launch.rb
133
+ - lib/vcloud/net_launcher/version.rb
134
+ - scripts/basic.erb
135
+ - scripts/generate_fog_conf_file.sh
136
+ - spec/erb_helper.rb
137
+ - spec/integration/net_launcher/data/minimum_data_setup.yaml.erb
138
+ - spec/integration/net_launcher/org_vdc_network_spec.rb
139
+ - spec/integration/net_launcher/vcloud_net_launcher_spec.rb
140
+ - spec/spec_helper.rb
141
+ - spec/support/stub_fog_interface.rb
142
+ - vcloud-net_launcher.gemspec
143
+ homepage: http://github.com/alphagov/vcloud-net_launcher
144
+ licenses:
145
+ - MIT
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: 1.9.2
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ segments:
163
+ - 0
164
+ hash: -783879997107424928
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 1.8.23
168
+ signing_key:
169
+ specification_version: 3
170
+ summary: Tool to launch and configure vCloud networks
171
+ test_files:
172
+ - features/step_definitions/vcloud-launch_steps.rb
173
+ - features/support/env.rb
174
+ - features/vcloud-net-launch.feature
175
+ - spec/erb_helper.rb
176
+ - spec/integration/net_launcher/data/minimum_data_setup.yaml.erb
177
+ - spec/integration/net_launcher/org_vdc_network_spec.rb
178
+ - spec/integration/net_launcher/vcloud_net_launcher_spec.rb
179
+ - spec/spec_helper.rb
180
+ - spec/support/stub_fog_interface.rb