Class: VagrantPlugins::ProfitBricks::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-profitbricks/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/vagrant-profitbricks/config.rb', line 87

def initialize
  @password = UNSET_VALUE
  @profitbricks_url = 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
  @volume_size = UNSET_VALUE
  @location = UNSET_VALUE
  @volume_type = UNSET_VALUE
  @volume_licence_type = UNSET_VALUE
  @volume_availability_zone = UNSET_VALUE
  @public_ssh_keys = UNSET_VALUE
  @cpu_family = UNSET_VALUE
  @lan_id = UNSET_VALUE
  @nat = UNSET_VALUE
  @image_password = UNSET_VALUE
end

Instance Attribute Details

#coresObject

number of cores in profitbricks server



73
74
75
# File 'lib/vagrant-profitbricks/config.rb', line 73

def cores
  @cores
end

#cpu_familyObject

Sets the CPU type. “AMD_OPTERON” or “INTEL_XEON”. Defaults to “AMD_OPTERON”.



79
80
81
# File 'lib/vagrant-profitbricks/config.rb', line 79

def cpu_family
  @cpu_family
end

#datacenter_idObject

Id or Name (name can be regular expression ) of datacenter. If provided with Name that doesn’t match new datacenter will be created in location specified by location option



40
41
42
# File 'lib/vagrant-profitbricks/config.rb', line 40

def datacenter_id
  @datacenter_id
end

#flavorObject

The flavor of server to launch, either the ID or name. This can also be a regular expression to partially match a name.



26
27
28
# File 'lib/vagrant-profitbricks/config.rb', line 26

def flavor
  @flavor
end

#imageObject

The name or ID of the image to use. This can also be a regular expression to partially match a name.



30
31
32
# File 'lib/vagrant-profitbricks/config.rb', line 30

def image
  @image
end

#image_aliasObject

Returns the value of attribute image_alias.



31
32
33
# File 'lib/vagrant-profitbricks/config.rb', line 31

def image_alias
  @image_alias
end

#image_passwordObject

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]



70
71
72
# File 'lib/vagrant-profitbricks/config.rb', line 70

def image_password
  @image_password
end

#lan_idObject

The LAN ID the network interface (NIC) will sit on. If the LAN ID does not exist it will be created.



82
83
84
# File 'lib/vagrant-profitbricks/config.rb', line 82

def lan_id
  @lan_id
end

#locationObject

Specify location for datacenter if one needs to be created, default value is ‘us/las’



43
44
45
# File 'lib/vagrant-profitbricks/config.rb', line 43

def location
  @location
end

#natObject

Indicates the private IP address has outbound access to the public internet. Defaults to ‘false’.



85
86
87
# File 'lib/vagrant-profitbricks/config.rb', line 85

def nat
  @nat
end

#passwordString

The API key to access ProfitBricks - password

Returns:

  • (String)


11
12
13
# File 'lib/vagrant-profitbricks/config.rb', line 11

def password
  @password
end

#profitbricks_urlObject

The url to access ProfitBricks Cloud API.

expected to be a string url - ‘api.profitbricks.com/cloudapi/v4/’



22
23
24
# File 'lib/vagrant-profitbricks/config.rb', line 22

def profitbricks_url
  @profitbricks_url
end

#public_ssh_keysObject

One or more SSH keys to allow access to the volume via SSH.

Works with ProfitBricks supplied Linux images.


65
66
67
# File 'lib/vagrant-profitbricks/config.rb', line 65

def public_ssh_keys
  @public_ssh_keys
end

#ramObject

Required, amount of memory in GB allocated to virtual server



76
77
78
# File 'lib/vagrant-profitbricks/config.rb', line 76

def ram
  @ram
end

#server_nameObject

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.



36
37
38
# File 'lib/vagrant-profitbricks/config.rb', line 36

def server_name
  @server_name
end

#usernameString

The username to access ProfitBricks.

Returns:

  • (String)


16
17
18
# File 'lib/vagrant-profitbricks/config.rb', line 16

def username
  @username
end

#volume_availability_zoneObject

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


61
62
63
# File 'lib/vagrant-profitbricks/config.rb', line 61

def volume_availability_zone
  @volume_availability_zone
end

#volume_licence_typeObject

The licence type of the volume. Options: LINUX, WINDOWS, UNKNOWN, OTHER

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


55
56
57
# File 'lib/vagrant-profitbricks/config.rb', line 55

def volume_licence_type
  @volume_licence_type
end

#volume_sizeObject

Disk volume size in GB



46
47
48
# File 'lib/vagrant-profitbricks/config.rb', line 46

def volume_size
  @volume_size
end

#volume_typeObject

Disk volume type (SSD or HDD)

Will default to HDD if not specified


50
51
52
# File 'lib/vagrant-profitbricks/config.rb', line 50

def volume_type
  @volume_type
end

Instance Method Details

#finalize!Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/vagrant-profitbricks/config.rb', line 110

def finalize!
  @password = nil if @password == UNSET_VALUE
  @profitbricks_url = nil if @profitbricks_url == 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
  @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
  @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

#validate(_machine) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/vagrant-profitbricks/config.rb', line 131

def validate(_machine)
  errors = _detected_errors

  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

  {
    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)
  end

  { 'ProfitBricks Provider' => errors }
end