Module: Kontena::Machine::Upcloud::UpcloudCommon

Included in:
MasterProvisioner, NodeDestroyer, NodeProvisioner, NodeRestarter
Defined in:
lib/kontena/machine/upcloud/upcloud_common.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



10
11
12
# File 'lib/kontena/machine/upcloud/upcloud_common.rb', line 10

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



9
10
11
# File 'lib/kontena/machine/upcloud/upcloud_common.rb', line 9

def username
  @username
end

Instance Method Details

#abort_unless_api_accessObject



45
46
47
48
49
# File 'lib/kontena/machine/upcloud/upcloud_common.rb', line 45

def abort_unless_api_access
  unless api_access?
    abort('Upcloud API authentication failed. Check that API access is enabled for the user.')
  end
end

#api_access?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/kontena/machine/upcloud/upcloud_common.rb', line 38

def api_access?
  response = get('account')
  response.kind_of?(Hash) && response.has_key?(:account)
rescue
  false
end

#find_plan(name) ⇒ Object



26
27
28
# File 'lib/kontena/machine/upcloud/upcloud_common.rb', line 26

def find_plan(name)
  get('plan')[:plans][:plan].find{|s| s[:name].downcase.eql?(name.downcase)}
end

#find_template(name) ⇒ Object



22
23
24
# File 'lib/kontena/machine/upcloud/upcloud_common.rb', line 22

def find_template(name)
  get('storage/template')[:storages][:storage].find{|s| s[:title].downcase.start_with?(name.downcase)}
end

#get_server(id) ⇒ Object



34
35
36
# File 'lib/kontena/machine/upcloud/upcloud_common.rb', line 34

def get_server(id)
  get("server/#{id}").fetch(:server, nil)
end

#upcloud_clientObject



12
13
14
15
16
17
18
19
20
# File 'lib/kontena/machine/upcloud/upcloud_common.rb', line 12

def upcloud_client
  @upcloud_client ||= Excon.new(
    'https://api.upcloud.com',
    omit_default_port: true,
    user: username,
    password: password,
    headers: { "Accept-Encoding" => 'application/json' }
  )
end

#zone_exist?(name) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/kontena/machine/upcloud/upcloud_common.rb', line 30

def zone_exist?(name)
  get('zone')[:zones][:zone].map{|p| p[:id]}.include?(name)
end