module Chef::Knife::ProfitbricksBase

Public Class Methods

included(includer) click to toggle source
# File lib/chef/knife/profitbricks_base.rb, line 7
def self.included(includer)
  includer.class_eval do
    deps do
      require 'profitbricks'
    end

    option :profitbricks_username,
      short: '-u USERNAME',
      long: '--username USERNAME',
      description: 'Your ProfitBricks username',
      proc: proc { |username| Chef::Config[:knife][:profitbricks_username] = username }

    option :profitbricks_password,
      short: '-p PASSWORD',
      long: '--password PASSWORD',
      description: 'Your ProfitBricks password',
      proc: proc { |password| Chef::Config[:knife][:profitbricks_password] = password }

    option :profitbricks_url,
      short: '-U URL',
      long: '--url URL',
      description: 'The ProfitBricks API URL',
      proc: proc { |url| Chef::Config[:knife][:profitbricks_url] = url }
  end
end

Public Instance Methods

connection() click to toggle source
# File lib/chef/knife/profitbricks_base.rb, line 33
def connection
  ProfitBricks.configure do |config|
    config.username = Chef::Config[:knife][:profitbricks_username]
    config.password = Chef::Config[:knife][:profitbricks_password]
    config.url = Chef::Config[:knife][:profitbricks_url]
    config.debug = Chef::Config[:knife][:profitbricks_debug] || false
    config.global_classes = false
    config.headers = Hash.new
    config.headers['User-Agent'] = "Chef/#{::Chef::VERSION} knife-profitbricks/#{::Knife::ProfitBricks::VERSION}"
  end
end
error_and_exit(message) click to toggle source
# File lib/chef/knife/profitbricks_base.rb, line 55
def error_and_exit(message)
  ui.error message
  exit(1)
end
get_image(image_name, image_type, image_location) click to toggle source
# File lib/chef/knife/profitbricks_base.rb, line 61
def get_image(image_name, image_type, image_location)
  images = ProfitBricks::Image.list
  min_image = nil
  images.each do |image|
    if image.properties['name'].downcase.include? image_name && image.properties['public'] == true && image.properties['imageType'] == image_type && image.properties['location'] == image_location
      min_image = image
    end
  end
  min_image
end
msg_pair(label, value, color = :cyan) click to toggle source
# File lib/chef/knife/profitbricks_base.rb, line 45
def msg_pair(label, value, color = :cyan)
  if value && !value.to_s.empty?
    puts "#{ui.color(label, color)}: #{value}"
  end
end
validate_required_params(required_params, params) click to toggle source
# File lib/chef/knife/profitbricks_base.rb, line 51
def validate_required_params(required_params, params)
  missing_params = required_params.select do |param|
     params[param].nil?
   end
  def error_and_exit(message)
    ui.error message
    exit(1)
  end
end