From c8341b318b69f43a3267542aa56896b7b80afe59 Mon Sep 17 00:00:00 2001 From: Bob Date: Tue, 9 Feb 2016 14:08:03 +0100 Subject: [PATCH 1/3] Only use sec groups if enabled, don't use networks in Basic --- README.md | 13 +++++----- lib/vagrant-cloudstack/action/run_instance.rb | 26 +++++++++++++++++-- locales/en.yml | 6 +++++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 81e0948e..d0d28148 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,6 @@ Vagrant.configure("2") do |config| cloudstack.network_id = "AAAAAAAAAAAAAAAAAAA" cloudstack.zone_id = "AAAAAAAAAAAAAAAAAAA" cloudstack.project_id = "AAAAAAAAAAAAAAAAAAA" - cloudstack.network_type = "Advanced" # or "Basic" end end ``` @@ -82,7 +81,6 @@ Vagrant.configure("2") do |config| cloudstack.name = "doge-is-a-hostname-now" # Sadly there is currently no support for the project api in fog. cloudstack.project_id = "AAAAAAAAAAAAAAAAAAA" - cloudstack.network_type = "Advanced" # or "Basic" end end ``` @@ -130,7 +128,6 @@ to update UUIDs in your Vagrantfile. If both are specified, the id parameter tak * `domain_id` - Domain id to launch the instance into * `network_id` - Network uuid that the instance should use * `network_name` - Network name that the instance should use -* `network_type` - CloudStack Network Type(default: Advanced) * `project_id` - Project uuid that the instance should belong to * `service_offering_id`- Service offering uuid to use for the instance * `service_offering_name`- Service offering name to use for the instance @@ -211,9 +208,15 @@ supported with `vagrant-cloudstack`, currently. If any of these are specified, Vagrant will emit a warning, but will otherwise boot the Cloudstack machine. +### Basic networking versus Advanced networking + +The plugin will determine this network type dynamically from the zone. +The setting `network_type` in the Vagrant file has been deprecated, +and is silently ignored. + ### Basic Networking -If you set the `network_type` to `basic`, you can use Security +If the network type of your zone is `basic`, you can use Security Groups and associate rules in your Vagrantfile. If you already have Security Groups, you can associate them to your @@ -226,7 +229,6 @@ Vagrant.configure("2") do |config| config.vm.provider :cloudstack do |cloudstack| cloudstack.api_key = "foo" cloudstack.secret_key = "bar" - cloudstack.network_type = "basic" cloudstack.security_group_ids = ['aaaa-bbbb-cccc-dddd', '1111-2222-3333-4444'] end end @@ -241,7 +243,6 @@ Vagrant.configure("2") do |config| config.vm.provider :cloudstack do |cloudstack| cloudstack.api_key = "foo" cloudstack.secret_key = "bar" - cloudstack.network_type = "basic" cloudstack.security_group_names = [' min_fantastiska_security_group', 'another_security_grupp'] end diff --git a/lib/vagrant-cloudstack/action/run_instance.rb b/lib/vagrant-cloudstack/action/run_instance.rb index dae8bf7e..15029e1a 100644 --- a/lib/vagrant-cloudstack/action/run_instance.rb +++ b/lib/vagrant-cloudstack/action/run_instance.rb @@ -37,7 +37,6 @@ def call(env) @template = CloudstackResource.new(domain_config.template_id, domain_config.template_name || env[:machine].config.vm.box, 'template') hostname = domain_config.name - network_type = domain_config.network_type project_id = domain_config.project_id keypair = domain_config.keypair static_nat = domain_config.static_nat @@ -64,11 +63,34 @@ def call(env) private_ip_address = domain_config.private_ip_address @resource_service.sync_resource(@zone, { 'available' => true }) - @resource_service.sync_resource(@network) + cs_zone = env[:cloudstack_compute].zones.find{ |f| f.id == @zone.id } @resource_service.sync_resource(@service_offering) @resource_service.sync_resource(@disk_offering) @resource_service.sync_resource(@template, {'zoneid' => @zone.id, 'templatefilter' => 'executable' }) + if cs_zone.network_type.downcase == 'basic' + # No network specification in basic zone + env[:ui].warn(I18n.t('vagrant_cloudstack.basic_network', :zone_name => @zone.name)) if @network.id || @network.name + @network = CloudstackResource.new(nil, nil, 'network') + + # No portforwarding in basic zone, so none of the below + pf_ip_address = nil + pf_ip_address_id = nil + pf_public_port = nil + pf_public_rdp_port = nil + pf_public_port_randomrange = nil + else + @resource_service.sync_resource(@network) + end + + if !cs_zone.security_groups_enabled + if !security_group_ids.empty? || !security_group_names.empty? || !security_groups.empty? + env[:ui].warn(I18n.t('vagrant_cloudstack.security_groups_disabled', :zone_name => @zone.name)) + end + security_group_ids = [] + security_group_names = [] + security_groups = [] + end # Can't use Security Group IDs and Names at the same time # Let's use IDs by default... if security_group_ids.empty? and !security_group_names.empty? diff --git a/locales/en.yml b/locales/en.yml index 5f3746be..f9be43fd 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -2,6 +2,9 @@ en: vagrant_cloudstack: already_status: |- The machine is already %{status}. + basic_network: |- + Network name or id defined but zone %{zone_name} is of network type 'Basic' + Network name or id will be ignored launching_instance: |- Launching an instance with the following settings... launch_no_keypair_no_sshkey: |- @@ -21,6 +24,9 @@ en: Make sure rsync is installed and the binary can be found in the PATH. rsync_folder: |- Rsyncing folder: %{hostpath} => %{guestpath} + security_groups_disabled: |- + Security groups defined but not supported in the zone %{zone_name} + Defined security groups will be ignored ssh_key_pair_creating: |- Creating an SSH keypair in CloudStack... ssh_key_pair_removing: |- From 51b857ab990589cf245b5d55dd3cef4d3155160b Mon Sep 17 00:00:00 2001 From: Bob Date: Fri, 19 Feb 2016 08:58:41 +0100 Subject: [PATCH 2/3] Remove references/usage of `network_type` --- README.md | 1 - functional-tests/rsync/Vagrantfile.advanced_networking | 1 - functional-tests/vmlifecycle/Vagrantfile.advanced_networking | 1 - 3 files changed, 3 deletions(-) diff --git a/README.md b/README.md index d0d28148..b0a56b3b 100644 --- a/README.md +++ b/README.md @@ -258,7 +258,6 @@ Vagrant.configure("2") do |config| config.vm.provider :cloudstack do |cloudstack| cloudstack.api_key = "foo" cloudstack.secret_key = "bar" - cloudstack.network_type = "basic" cloudstack.security_groups = [ { :name => "Awesome_security_group", diff --git a/functional-tests/rsync/Vagrantfile.advanced_networking b/functional-tests/rsync/Vagrantfile.advanced_networking index 98607e6c..a73b9e16 100644 --- a/functional-tests/rsync/Vagrantfile.advanced_networking +++ b/functional-tests/rsync/Vagrantfile.advanced_networking @@ -27,7 +27,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| cloudstack.network_name = ENV['NETWORK_NAME'] cloudstack.service_offering_name = ENV['SERVICE_OFFERING_NAME'] - cloudstack.network_type = 'Advanced' cloudstack.pf_ip_address = public_source_nat_ip cloudstack.pf_public_port = public_ssh_port cloudstack.pf_private_port = ENV['PRIVATE_SSH_PORT'] diff --git a/functional-tests/vmlifecycle/Vagrantfile.advanced_networking b/functional-tests/vmlifecycle/Vagrantfile.advanced_networking index c97ce117..4653e96d 100644 --- a/functional-tests/vmlifecycle/Vagrantfile.advanced_networking +++ b/functional-tests/vmlifecycle/Vagrantfile.advanced_networking @@ -50,7 +50,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |global_config| cloudstack.network_name = ENV['NETWORK_NAME'] cloudstack.service_offering_name = ENV['SERVICE_OFFERING_NAME'] - cloudstack.network_type = 'Advanced' cloudstack.pf_ip_address = public_source_nat_ip cloudstack.pf_public_port = options['public_port'] From f6fb2165b59cc74a29e15bf8ff086bd07d4d950c Mon Sep 17 00:00:00 2001 From: Bob Date: Fri, 19 Feb 2016 09:03:06 +0100 Subject: [PATCH 3/3] Am I worthy? --- vagrant-cloudstack.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vagrant-cloudstack.gemspec b/vagrant-cloudstack.gemspec index 2a68f8f4..6d1e44ca 100644 --- a/vagrant-cloudstack.gemspec +++ b/vagrant-cloudstack.gemspec @@ -6,7 +6,7 @@ Gem::Specification.new do |s| s.version = VagrantPlugins::Cloudstack::VERSION s.platform = Gem::Platform::RUBY s.license = 'MIT' - s.authors = ['Mitchell Hashimoto', 'Carl Loa Odin', 'Tor-Åke Fransson', 'Olle Lundberg', 'Roeland Kuipers', 'Yuichi Uemura', 'Atsushi Sasaki', 'Nicolas Brechet', 'Peter Jönsson', 'Christophe Roux', 'Andrei Chiriaev', 'Miguel Ferreira', 'Timothy van Zadelhoff', 'Geurt Schimmel'] + s.authors = ['Mitchell Hashimoto', 'Carl Loa Odin', 'Tor-Åke Fransson', 'Olle Lundberg', 'Roeland Kuipers', 'Yuichi Uemura', 'Atsushi Sasaki', 'Nicolas Brechet', 'Peter Jönsson', 'Christophe Roux', 'Andrei Chiriaev', 'Miguel Ferreira', 'Timothy van Zadelhoff', 'Geurt Schimmel', 'Bob van den Heuvel'] s.email = 'int-toolkit@schubergphilis.com' s.homepage = 'https://github.com/schubergphilis/vagrant-cloudstack/' s.summary = 'Enables Vagrant to manage machines in Cloudstack.'