Module: Kontena::Machine::Upcloud::UpcloudCommon
- Included in:
- MasterProvisioner, NodeDestroyer, NodeProvisioner, NodeRestarter
- Defined in:
- lib/kontena/machine/upcloud/upcloud_common.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #abort_unless_api_access ⇒ Object
- #api_access? ⇒ Boolean
- #find_plan(name) ⇒ Object
- #find_template(name) ⇒ Object
- #get_server(id) ⇒ Object
- #upcloud_client ⇒ Object
- #zone_exist?(name) ⇒ Boolean
Instance Attribute Details
#password ⇒ Object (readonly)
Returns the value of attribute password.
10 11 12 |
# File 'lib/kontena/machine/upcloud/upcloud_common.rb', line 10 def password @password end |
#username ⇒ Object (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_access ⇒ Object
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
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_client ⇒ Object
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
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 |