lib/vagrant-profitbricks/config.rb in vagrant-profitbricks-1.0.0 vs lib/vagrant-profitbricks/config.rb in vagrant-profitbricks-4.0.0

- old
+ new

@@ -1,35 +1,37 @@ -require "vagrant" -require "fog/profitbricks" +# frozen_string_literal: true +require 'vagrant' +require 'fog/profitbricks' + module VagrantPlugins module ProfitBricks - class Config < Vagrant.plugin("2", :config) - # The API key to access ProfitBricks - profitbricks_password + class Config < Vagrant.plugin('2', :config) + # The API key to access ProfitBricks - password # @return [String] attr_accessor :password # The username to access ProfitBricks. # # @return [String] attr_accessor :username - # The profitbricks_url to access ProfitBricks. + # The url to access ProfitBricks Cloud API. # # expected to be a string url - - # 'https://api.profitbricks.com/cloudapi/v3/' + # 'https://api.profitbricks.com/cloudapi/v4/' attr_accessor :profitbricks_url # The flavor of server to launch, either the ID or name. This # can also be a regular expression to partially match a name. attr_accessor :flavor # The name or ID of the image to use. This can also be a regular # expression to partially match a name. attr_accessor :image + attr_accessor :image_alias - # The name of the server. This defaults to the name of the machine # defined by Vagrant (via `config.vm.define`), but can be overriden # here. attr_accessor :server_name @@ -37,43 +39,43 @@ # new datacenter will be created in location specified by location option attr_accessor :datacenter_id # Specify location for datacenter if one needs to be created, default value is 'us/las' attr_accessor :location - + # Disk volume size in GB - attr_accessor :profitbricks_volume_size + attr_accessor :volume_size # Disk volume type (SSD or HDD) # Will default to HDD if not specified attr_accessor :volume_type # The licence type of the volume. Options: LINUX, WINDOWS, UNKNOWN, OTHER - # You will need to provide either the image or the licence_type parameters. + # You will need to provide either the image or the licence_type parameters. # licence_type is required, but if image is supplied, it is already set and cannot be changed attr_accessor :volume_licence_type - # The storage availability zone assigned to the volume. - # Valid values: AUTO, ZONE_1, ZONE_2, or ZONE_3. This only applies to HDD volumes. + # The storage availability zone assigned to the volume. + # Valid values: AUTO, ZONE_1, ZONE_2, or ZONE_3. This only applies to HDD volumes. # Leave blank or set to AUTO when provisioning SSD volumes. # Will default to AUTO if not specified attr_accessor :volume_availability_zone - # One or more SSH keys to allow access to the volume via SSH. + # One or more SSH keys to allow access to the volume via SSH. # Works with ProfitBricks supplied Linux images. - attr_accessor :volume_ssh_keys + attr_accessor :public_ssh_keys # POne-time password is set on the Image for the appropriate account. # This field may only be set in creation requests. When reading, it always returns null. # Password has to contain 8-50 characters. Only these characters are allowed: [abcdefghjkmnpqrstuvxABCDEFGHJKLMNPQRSTUVX23456789] attr_accessor :image_password # number of cores in profitbricks server - attr_accessor :profitbricks_cores + attr_accessor :cores # Required, amount of memory in GB allocated to virtual server - attr_accessor :profitbricks_ram + attr_accessor :ram # Sets the CPU type. "AMD_OPTERON" or "INTEL_XEON". Defaults to "AMD_OPTERON". attr_accessor :cpu_family # The LAN ID the network interface (NIC) will sit on. If the LAN ID does not exist it will be created. @@ -81,72 +83,75 @@ # Indicates the private IP address has outbound access to the public internet. Defaults to 'false'. attr_accessor :nat def initialize - @password = UNSET_VALUE + @password = UNSET_VALUE @profitbricks_url = UNSET_VALUE - @flavor = UNSET_VALUE - @profitbricks_cores = UNSET_VALUE - @profitbricks_ram = UNSET_VALUE - @image = UNSET_VALUE + @flavor = UNSET_VALUE + @cores = UNSET_VALUE + @ram = UNSET_VALUE + @image = nil + @image_alias = nil @server_name = UNSET_VALUE @datacenter_id = UNSET_VALUE @username = UNSET_VALUE - @profitbricks_volume_size = UNSET_VALUE + @volume_size = UNSET_VALUE @location = UNSET_VALUE @volume_type = UNSET_VALUE @volume_licence_type = UNSET_VALUE @volume_availability_zone = UNSET_VALUE - @volume_ssh_keys = UNSET_VALUE + @public_ssh_keys = UNSET_VALUE @cpu_family = UNSET_VALUE @lan_id = UNSET_VALUE @nat = UNSET_VALUE @image_password = UNSET_VALUE end def finalize! - @password = nil if @password == UNSET_VALUE + @password = nil if @password == UNSET_VALUE @profitbricks_url = nil if @profitbricks_url == UNSET_VALUE - @flavor = nil if @flavor == UNSET_VALUE - @profitbricks_cores = 1 if @profitbricks_cores == UNSET_VALUE - @profitbricks_ram = 256 if profitbricks_ram == UNSET_VALUE - @image = /ubuntu/ if @image == UNSET_VALUE + @flavor = nil if @flavor == UNSET_VALUE + @cores = 1 if @cores == UNSET_VALUE + @ram = 2048 if ram == UNSET_VALUE @server_name = nil if @server_name == UNSET_VALUE @datacenter_id = nil if @datacenter_id == UNSET_VALUE @username = nil if @username == UNSET_VALUE - @profitbricks_volume_size = 5 if @profitbricks_volume_size == UNSET_VALUE + @volume_size = 5 if @volume_size == UNSET_VALUE @location = 'us/las' if @location == UNSET_VALUE @volume_type = 'HDD' if @volume_type == UNSET_VALUE @volume_licence_type = 'UNKNOWN' if @volume_licence_type == UNSET_VALUE @volume_availability_zone = 'AUTO' if @volume_availability_zone == UNSET_VALUE - @volume_ssh_keys = nil if @volume_ssh_keys == UNSET_VALUE + @public_ssh_keys = nil if @public_ssh_keys == UNSET_VALUE @cpu_family = 'AMD_OPTERON' if @cpu_family == UNSET_VALUE @lan_id = nil if @lan_id == UNSET_VALUE @nat = false if @nat == UNSET_VALUE @image_password = nil if @image_password == UNSET_VALUE end - def validate(machine) + def validate(_machine) errors = _detected_errors - errors << I18n.t("vagrant_profitbricks.config.password_required") if !@password - errors << I18n.t("vagrant_profitbricks.config.username_required") if !@username - errors << I18n.t("vagrant_profitbricks.config.datacenter_required") if !@datacenter_id + errors << I18n.t('vagrant_profitbricks.config.password_required') unless @password + errors << I18n.t('vagrant_profitbricks.config.username_required') unless @username + errors << I18n.t('vagrant_profitbricks.config.datacenter_required') unless @datacenter_id + errors << I18n.t('vagrant_profitbricks.config.image_or_image_alias_must_be_provided') if !@image && !@image_alias + errors << I18n.t('vagrant_profitbricks.config.image_password_or_public_ssh_required') if !@public_ssh_keys && !@image_password + { - :profitbricks_url => @profitbricks_url + url: @profitbricks_url }.each_pair do |key, value| - errors << I18n.t("vagrant_profitbricks.config.invalid_uri", :key => key, :uri => value) unless value.nil? || valid_uri?(value) + errors << I18n.t('vagrant_profitbricks.config.invalid_uri', key: key, uri: value) unless value.nil? || valid_uri?(value) end - { "ProfitBricks Provider" => errors } + { 'ProfitBricks Provider' => errors } end private - def valid_uri? value + def valid_uri?(value) uri = URI.parse value - uri.kind_of?(URI::HTTP) + uri.is_a?(URI::HTTP) end end end end