Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  bugfix multiple sub allocation pools ranges [ISSUE #24]
  increase task sleep to 5s and bumping version 0.1.1
  Putting back Google DNS as default if not specified
  remove awesome_print
  binding vCloud 5.5 API on 5.1 driver
  updated .gitignore to ignore yard docs.
  Debug cut and general cosmetic cleanup
  added DNS choice using the "ip_dns" Array config property.
  more debug cut
  cut down on debug again
  cut down on debug, fixed error raise in meta, removed old get_api_version
  misc fixes
  User message fixes.
  Updated sync_folders.rb with code from vagrant-aws, added license on top Will focus on a better sync engine later in the future.
  updated .gitignore
  Updated gemspec.
  Removed dependency on rest-client gem, moved everything to httpclient.
  removed stray comment
  Fixed destroy vApp bug.
  • Loading branch information
frapposelli committed Jan 20, 2014
2 parents 4a0edf2 + d1677e9 commit 520c1ae
Show file tree
Hide file tree
Showing 19 changed files with 276 additions and 254 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.vagrant/*
pkg/*
Gemfile.lock
Gemfile.lock
test-*
.yardoc/*
doc/*
56 changes: 28 additions & 28 deletions lib/vagrant-vcloud/action/build_vapp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def call(env)
cnx = cfg.vcloud_cnx.driver
vmName = env[:machine].name

if cfg.ip_dns.nil?
dnsAddress1 = "8.8.8.8"
dnsAddress2 = "8.8.4.4"
else
dnsAddress1 = cfg.ip_dns.shift
dnsAddress2 = cfg.ip_dns.shift
end

if !cfg.ip_subnet.nil?

@logger.debug("Input address: #{cfg.ip_subnet}")
Expand All @@ -38,15 +46,17 @@ def call(env)

@logger.debug("Range: #{rangeAddresses}")

rangeAddresses.shift # Delete the "network" address from the range.
gatewayIp = rangeAddresses.shift # Retrieve the first usable IP, to be used as a gateway.
rangeAddresses.reverse! # Reverse the array in place.
rangeAddresses.shift # Delete the "broadcast" address from the range.
rangeAddresses.reverse! # Reverse back the array.
rangeAddresses.shift # Delete the "network" address from the range.
gatewayIp = rangeAddresses.shift # Retrieve the first usable IP, to be used as a gateway.
rangeAddresses.reverse! # Reverse the array in place.
rangeAddresses.shift # Delete the "broadcast" address from the range.
rangeAddresses.reverse! # Reverse back the array.

@logger.debug("Gateway IP: #{gatewayIp.to_s}")
@logger.debug("Netmask: #{cidr.wildcard_mask}")
@logger.debug("IP Pool: #{rangeAddresses.first}-#{rangeAddresses.last}")
@logger.debug("DNS1: #{dnsAddress1} DNS2: #{dnsAddress2}")


network_options = {
:name => "Vagrant-vApp-Net",
Expand All @@ -58,12 +68,13 @@ def call(env)
:ip_allocation_mode => "POOL",
:parent_network => cfg.vdc_network_id,
:enable_firewall => "false",
:dns1 => "8.8.8.8", # FIXME: We should let the user choose DNS servers and then
:dns2 => "8.8.4.4" # fall back to Google's if they're not specified.
:dns1 => dnsAddress1,
:dns2 => dnsAddress2
}

else

@logger.debug("DNS1: #{dnsAddress1} DNS2: #{dnsAddress2}")
# No IP subnet specified, reverting to defaults
network_options = {
:name => "Vagrant-vApp-Net",
Expand All @@ -75,8 +86,8 @@ def call(env)
:ip_allocation_mode => "POOL",
:parent_network => cfg.vdc_network_id,
:enable_firewall => "false",
:dns1 => "8.8.8.8",
:dns2 => "8.8.4.4"
:dns1 => dnsAddress1,
:dns2 => dnsAddress2
}

end
Expand Down Expand Up @@ -115,28 +126,25 @@ def call(env)
# FIXME: Add a lot of error handling for each step here !

if newVApp
env[:ui].success("vApp #{newVApp[:name]} created successfully!")
env[:ui].success("vApp #{newVApp[:name]} successfully created.")

# Add the vm id as machine.id
newVMProperties = newVApp[:vms_hash].fetch(vmName)
env[:machine].id = newVMProperties[:id]

### SET GUEST CONFIG
#env[:ui].info("Setting Guest Customization on ID: [#{vmName}] of vApp [#{newVApp[:name]}]")

@logger.info("Setting Guest Customization on ID: [#{vmName}] of vApp [#{newVApp[:name]}]")

setCustom = cnx.set_vm_guest_customization(newVMProperties[:id], vmName, {
:enabled => true,
:admin_passwd_enabled => false
})
cnx.wait_task_completion(setCustom)

# @logger.info("Starting VM [#{vmName}] - this will take a while as vShield Edge is getting deployed as well")
# env[:ui].info("Starting VM [#{vmName}] - this will take a while as vShield Edge is getting deployed as well")
# poweronVM = cnx.poweron_vm(newVMProperties[:id])
# cnx.wait_task_completion(poweronVM)

else
env[:ui].error("vApp #{newVApp[:name]} creation failed!")
raise
raise # FIXME: error handling missing.
end
else
env[:ui].info("Adding VM to existing vApp...")
Expand All @@ -160,27 +168,19 @@ def call(env)

if newVApp

#env[:ui].success("VM #{vmName} added to #{newVApp[:name]} successfully!")
#@logger.info("VM #{vmName} added to #{newVApp[:name]} successfully!")

# Add the vm id as machine.id
newVMProperties = newVApp[:vms_hash].fetch(vmName)
env[:machine].id = newVMProperties[:id]

### SET GUEST CONFIG
#@logger.info("Setting Guest Customization on ID: [#{newVMProperties[:id]}] of vApp [#{newVApp[:name]}]")
#env[:ui].info("Setting Guest Customization on ID: [#{vmName}] of vApp [#{newVApp[:name]}]")

@logger.info("Setting Guest Customization on ID: [#{newVMProperties[:id]}] of vApp [#{newVApp[:name]}]")

setCustom = cnx.set_vm_guest_customization(newVMProperties[:id], vmName, {
:enabled => true,
:admin_passwd_enabled => false
})
cnx.wait_task_completion(setCustom)

# @logger.info("Starting VM [#{vmName}]")
# env[:ui].info("Starting VM [#{vmName}]")
# poweronVM = cnx.poweron_vm(newVMProperties[:id])
# cnx.wait_task_completion(poweronVM)

else

env[:ui].error("VM #{vmName} add to #{newVApp[:name]} failed!")
Expand Down
1 change: 0 additions & 1 deletion lib/vagrant-vcloud/action/connect_vcloud.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#require "vcloud-rest/connection"
require "log4r"

module VagrantPlugins
Expand Down
10 changes: 1 addition & 9 deletions lib/vagrant-vcloud/action/destroy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,12 @@ def call(env)
env[:ui].info("Single VM left in the vApp, destroying the vApp...")

if cfg.vdc_edge_gateway_ip && cfg.vdc_edge_gateway
env[:ui].info("Removing mapping for ip #{cfg.vdc_edge_gateway_ip} on Edge #{cfg.vdc_edge_gateway}.")
env[:ui].info("Removing NAT rules on [#{cfg.vdc_edge_gateway}] for IP [#{cfg.vdc_edge_gateway_ip}].")
@logger.debug("Deleting Edge Gateway rules - vdc id: #{cfg.vdc_id}")
edge_remove = cnx.remove_edge_gateway_rules(cfg.vdc_edge_gateway, cfg.vdc_id, cfg.vdc_edge_gateway_ip, vAppId)
cnx.wait_task_completion(edge_remove)
end

env[:ui].info("Powering off vApp...")
vAppStopTask = cnx.poweroff_vapp(vAppId)
vAppStopWait = cnx.wait_task_completion(vAppStopTask)

if !vAppStopWait[:errormsg].nil?
raise Errors::StopVAppError, :message => vAppStopWait[:errormsg]
end

env[:ui].info("Destroying vApp...")
vAppDeleteTask = cnx.delete_vapp(vAppId)
@logger.debug("vApp Delete task id #{vAppDeleteTask}")
Expand Down
40 changes: 2 additions & 38 deletions lib/vagrant-vcloud/action/forward_ports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def call(env)
# Get the ports we're forwarding
env[:forwarded_ports] ||= compile_forwarded_ports(env[:machine].config)

@logger.debug("WE'RE GOING TO FORWARD THIS!: #{@env[:forwarded_ports]}")

forward_ports

@app.call(env)
Expand All @@ -28,8 +26,6 @@ def call(env)
def forward_ports
ports = []

# interfaces = @env[:machine].provider.driver.read_network_interfaces

cfg = @env[:machine].provider_config
cnx = cfg.vcloud_cnx.driver
vmName = @env[:machine].name
Expand All @@ -49,28 +45,8 @@ def forward_ports
:host_port => fp.host_port
}

# Assuming the only reason to establish port forwarding is
# because the VM is using Virtualbox NAT networking. Host-only
# bridged networking don't require port-forwarding and establishing
# forwarded ports on these attachment types has uncertain behaviour.
@env[:ui].info("Forwarding Ports: VM port #{fp.guest_port} -> vShield Edge port #{fp.host_port}")

# Verify we have the network interface to attach to
# if !interfaces[fp.adapter]
# raise Vagrant::Errors::ForwardPortAdapterNotFound,
# :adapter => fp.adapter.to_s,
# :guest => fp.guest_port.to_s,
# :host => fp.host_port.to_s
# end

# Port forwarding requires the network interface to be a NAT interface,
# so verify that that is the case.
# if interfaces[fp.adapter][:type] != :nat
# @env[:ui].info(I18n.t("vagrant.actions.vm.forward_ports.non_nat",
# message_attributes))
# next
# end

# Add the options to the ports array to send to the driver later
ports << {
:guestip => fp.guest_ip,
Expand All @@ -85,20 +61,11 @@ def forward_ports

if !ports.empty?
# We only need to forward ports if there are any to forward

@logger.debug("Here's what we should pass to the driver method: #{ports.inspect}")
@logger.debug("here's our network id #{cfg.vdc_network_id}")
# @env[:machine].provider.driver.forward_ports(ports)

# newvapp[:vms_hash].each do |key, value|

# nat_rules << { :nat_external_port => j.to_s, :nat_internal_port => "873", :nat_protocol => "UDP", :vm_scoped_local_id => value[:vapp_scoped_local_id]}
# j += 1
@logger.debug("Port object to be passed: #{ports.inspect}")
@logger.debug("Current network id #{cfg.vdc_network_id}")

### Here we apply the nat_rules to the vApp we just built

# puts "### Applying Port Forwarding NAT Rules"

addports = cnx.add_vapp_port_forwarding_rules(
vAppId,
"Vagrant-vApp-Net",
Expand All @@ -115,11 +82,8 @@ def forward_ports
raise Errors::ComposeVAppError, :message => wait[:errormsg]
end


end



end
end
end
Expand Down
8 changes: 0 additions & 8 deletions lib/vagrant-vcloud/action/handle_nat_port_collisions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,11 @@ def call(env)
# Determine a list of usable ports for repair
usable_ports = Set.new(env[:machine].config.vm.usable_port_range)

@logger.debug("USABLE PORTS: #{usable_ports.inspect}")

# Pass one, remove all defined host ports from usable ports
with_forwarded_ports(env) do |options|
usable_ports.delete(options[:host])
end

@logger.debug("USABLE PORTS AFTER IN USE DELETION: #{usable_ports.inspect}")

cfg = env[:machine].provider_config
cnx = cfg.vcloud_cnx.driver
vmName = env[:machine].name
Expand All @@ -59,12 +55,8 @@ def call(env)
guest_port = options[:guest]
host_port = options[:host]

#testHash = rules.flatten
@logger.debug("DEBUGGING NETWORKS: rules: #{rules.inspect}")

# If the port is open (listening for TCP connections)
if rules.include?(host_port)
@logger.debug("SO OUR PORT IS INCLUDED IN RULES BUT WHAT'S IN OPTIONS?: #{options.inspect}")
if !options[:auto_correct]
raise Errors::ForwardPortCollision,
:guest_port => guest_port.to_s,
Expand Down
23 changes: 11 additions & 12 deletions lib/vagrant-vcloud/action/inventory_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def vcloud_upload_box(env)

boxOVF = "#{boxDir}/#{boxFile}.ovf"

### Still relying on ruby-progressbar because report_progress basically sucks.
# Still relying on ruby-progressbar because report_progress basically sucks.

@logger.debug("OVF File: #{boxOVF}")
uploadOVF = cnx.upload_ovf(
Expand All @@ -38,6 +38,7 @@ def vcloud_upload_box(env)
cfg.catalog_id,
{
:progressbar_enable => true
# FIXME: export chunksize as a parameter and lower the default to 1M.
#:chunksize => 262144
}
)
Expand All @@ -49,7 +50,7 @@ def vcloud_upload_box(env)
raise Errors::CatalogAddError, :message => addOVFtoCatalog[:errormsg]
end

## Retrieve catalog_item ID
# Retrieve catalog_item ID
cfg.catalog_item = cnx.get_catalog_item_by_name(cfg.catalog_id, env[:machine].box.name.to_s)

end
Expand All @@ -63,7 +64,7 @@ def vcloud_create_catalog(env)

@logger.debug("Catalog Creation result: #{catalogCreation.inspect}")

env[:ui].info("Catalog [#{cfg.catalog_name}] created successfully.")
env[:ui].info("Catalog [#{cfg.catalog_name}] successfully created.")

cfg.catalog_id = catalogCreation[:catalog_id]

Expand All @@ -83,11 +84,7 @@ def vcloud_check_inventory(env)

cfg.catalog = cnx.get_catalog_by_name(cfg.org, cfg.catalog_name)


@logger.debug("BEFORE get_catalog_id_by_name")
cfg.catalog_id = cnx.get_catalog_id_by_name(cfg.org, cfg.catalog_name)
@logger.debug("AFTER get_catalog_id_by_name: #{cfg.catalog_id}")


if cfg.catalog_id.nil?
env[:ui].warn("Catalog [#{cfg.catalog_name}] does not exist!")
Expand All @@ -96,12 +93,12 @@ def vcloud_check_inventory(env)
"Would you like to create the [#{cfg.catalog_name}] catalog?\nChoice (yes/no): "
)

# FIXME: add an OR clause for just Y
if user_input.downcase == "yes"
if user_input.downcase == "yes" || user_input.downcase == "y"
vcloud_create_catalog(env)
else
env[:ui].error("Catalog not created, exiting...")

# FIXME: wrong error message
raise VagrantPlugins::VCloud::Errors::VCloudError,
:message => "Catalog not available, exiting..."

Expand All @@ -118,6 +115,8 @@ def vcloud_check_inventory(env)
# Checking Catalog mandatory requirements
if !cfg.catalog_id
@logger.info("Catalog [#{cfg.catalog_name}] STILL does not exist!")

# FIXME: wrong error message
raise VagrantPlugins::VCloud::Errors::VCloudError,
:message => "Catalog not available, exiting..."

Expand All @@ -133,20 +132,20 @@ def vcloud_check_inventory(env)
"[#{cfg.catalog_name}] Catalog?\nChoice (yes/no): "
)

# FIXME: add an OR clause for just Y
if user_input.downcase == "yes"
if user_input.downcase == "yes" || user_input.downcase == "y"
env[:ui].info("Uploading [#{env[:machine].box.name.to_s}]...")
vcloud_upload_box(env)
else
env[:ui].error("Catalog item not available, exiting...")

# FIXME: wrong error message
raise VagrantPlugins::VCloud::Errors::VCloudError,
:message => "Catalog item not available, exiting..."

end

else
#env[:ui].info("Using catalog item [#{env[:machine].box.name.to_s}] in Catalog [#{cfg.catalog_name}]...")
@logger.info("Using catalog item [#{env[:machine].box.name.to_s}] in Catalog [#{cfg.catalog_name}]...")
end
end

Expand Down
Loading

0 comments on commit 520c1ae

Please sign in to comment.