require "vagrant" module VagrantPlugins module Skytap class Config < Vagrant.plugin("2", :config) # The user id for accessing Skytap. # # @return [String] attr_accessor :username # The secret API token for accessing Skytap. # # @return [String] attr_accessor :api_token # The base URL for Skytap API calls. # # @return [String] attr_accessor :base_url # The url of the source VM to use. # # @return [String] attr_accessor :vm_url # The timeout to wait for a VM to become ready. # # @return [Fixnum] attr_accessor :instance_ready_timeout # The total number of virtual CPUs for this VM. # # @return [Integer] attr_accessor :cpus # The number of virtual CPUs per socket. # # @return [Integer] attr_accessor :cpuspersocket # The RAM to use for this machine (measured in MB). # # @return [Integer] attr_accessor :ram # The VMware guest OS setting for this machine. # # @return [String] attr_accessor :guestos def initialize(region_specific=false) @username = UNSET_VALUE @api_token = UNSET_VALUE @base_url = UNSET_VALUE @vm_url = UNSET_VALUE @instance_ready_timeout = UNSET_VALUE @region = UNSET_VALUE @cpus = UNSET_VALUE @cpuspersocket = UNSET_VALUE @ram = UNSET_VALUE @guestos = UNSET_VALUE end #------------------------------------------------------------------- # Internal methods. #------------------------------------------------------------------- def finalize! # Try to get access keys from standard Skytap environment variables; they # will default to nil if the environment variables are not present. @username = ENV['VAGRANT_SKYTAP_USERNAME'] if @username == UNSET_VALUE @api_token = ENV['VAGRANT_SKYTAP_API_TOKEN'] if @api_token == UNSET_VALUE # Base URL for API calls. @base_url = "https://cloud.skytap.com/" if @base_url == UNSET_VALUE # Source VM url must be set. @vm_url = nil if @vm_url == UNSET_VALUE # Set the default timeout for waiting for an instance to be ready @instance_ready_timeout = 120 if @instance_ready_timeout == UNSET_VALUE # Hardware settings default to nil (will be obtained # from the source VM) @cpus = nil if @cpus == UNSET_VALUE @cpuspersocket = nil if @cpuspersocket == UNSET_VALUE @ram = nil if @ram == UNSET_VALUE @guestos = nil if @guestos == UNSET_VALUE # Mark that we finalized @__finalized = true end def validate(machine) errors = _detected_errors errors << I18n.t('vagrant_skytap.config.username_required') unless username errors << I18n.t('vagrant_skytap.config.api_token_required') unless api_token errors << I18n.t('vagrant_skytap.config.vm_url_required') unless vm_url { "Skytap Provider" => errors } end end end end