Class: Chef::Knife

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/knife/ec2_ami_list.rb,
lib/chef/knife/ec2_eip_list.rb,
lib/chef/knife/ec2_vpc_list.rb,
lib/chef/knife/ec2_flavor_list.rb,
lib/chef/knife/ec2_server_list.rb,
lib/chef/knife/ec2_subnet_list.rb,
lib/chef/knife/helpers/ec2_base.rb,
lib/chef/knife/ec2_server_create.rb,
lib/chef/knife/ec2_server_delete.rb,
lib/chef/knife/helpers/s3_source.rb,
lib/chef/knife/ec2_securitygroup_list.rb

Defined Under Namespace

Modules: Ec2Base Classes: Ec2AmiList, Ec2EniList, Ec2FlavorList, Ec2SecuritygroupList, Ec2ServerCreate, Ec2ServerDelete, Ec2ServerList, Ec2SubnetList, Ec2VpcList, S3Source

Instance Method Summary collapse

Instance Method Details

#aws_cred_file_location ⇒ String?

the path to the aws credentials file. if passed via cli config use that if default location exists on disk fallback to that

Returns:

  • (String, nil) —

    location to aws credentials file or nil if none exists



245
246
247
248
249
250
251
# File 'lib/chef/knife/helpers/ec2_base.rb', line 245

def aws_cred_file_location
  @cred_file ||= if !config[:aws_credential_file].nil?
                   config[:aws_credential_file]
                 else
                   Chef::Util::PathHelper.home(".aws", "credentials") if ::File.exist?(Chef::Util::PathHelper.home(".aws", "credentials"))
                 end
end

#custom_warnings! ⇒ Object

Custom Warning



289
290
291
292
293
# File 'lib/chef/knife/helpers/ec2_base.rb', line 289

def custom_warnings!
  unless config[:region]
    ui.warn "No region was specified in knife.rb/config.rb or as an argument. The default region, us-east-1, will be used:"
  end
end

#find_server_platform(server_name) ⇒ String

Get the platform from server name

Returns:

  • (String)


283
284
285
286
# File 'lib/chef/knife/helpers/ec2_base.rb', line 283

def find_server_platform(server_name)
  get_platform = VALID_PLATFORMS.select { |name| server_name.downcase.include?(name) }
  get_platform.first
end

#iam_name_from_profile(profile) ⇒ String

Returns:

  • (String)


254
255
256
257
258
259
260
# File 'lib/chef/knife/helpers/ec2_base.rb', line 254

def iam_name_from_profile(profile)
  # The IAM profile object only contains the name as part of the arn
  if profile && profile.key?("arn")
    name = profile["arn"].split("/")[-1]
  end
  name || ""
end

#ini_parse(file) ⇒ Object



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/chef/knife/helpers/ec2_base.rb', line 262

def ini_parse(file)
  current_section = {}
  map = {}
  file.each_line do |line|
    line = line.split(/^|\s;/).first # remove comments
    section = line.match(/^\s*\[([^\[\]]+)\]\s*$/) unless line.nil?
    if section
      current_section = section[1]
    elsif current_section
      item = line.match(/^\s*(.+?)\s*=\s*(.+?)\s*$/) unless line.nil?
      if item
        map[current_section] ||= {}
        map[current_section][item[1]] = item[2]
      end
    end
  end
  map
end