lib/chef/knife/ec2_server_create.rb in knife-ec2-1.0.9 vs lib/chef/knife/ec2_server_create.rb in knife-ec2-1.0.11
- old
+ new
@@ -267,10 +267,16 @@
Chef::Config[:knife][:aws_tag] ||= []
Chef::Config[:knife][:aws_tag].push(aws_tag)
Chef::Config[:knife][:aws_tag]
}
+ option :cpu_credits,
+ long: "--cpu-credits CPU_CREDITS",
+ description: "The credit option for CPU usage of the instance. Valid values are standard and unlimited. T3 instances launch as unlimited by default. T2 instances launch as standard by default.",
+ default: "standard",
+ in: %w{standard unlimited}
+
def plugin_create_instance!
requested_elastic_ip = config[:associate_eip] if config[:associate_eip]
# For VPC EIP assignment we need the allocation ID so fetch full EIP details
elastic_ip = ec2_connection.describe_addresses.addresses.detect { |addr| addr if addr.public_ip == requested_elastic_ip }
@@ -332,10 +338,11 @@
msg_pair("IAM Profile", config_value(:iam_instance_profile))
msg_pair("AWS Tags", printed_aws_tags)
msg_pair("Volume Tags", printed_volume_tags)
msg_pair("SSH Key", server.key_name)
+ msg_pair("T2/T3 Unlimited", printed_t2_t3_unlimited)
puts("\n")
# occasionally 'ready?' isn't, so retry a couple times if needed.
tries = 6
@@ -716,10 +723,15 @@
# If --chef-tag is provided then it will be set in chef as single value e.g. --chef-tag "myTag"
# --tags has been removed from knife-ec2, now it's available in core
config[:tags] += config_value(:chef_tag)
ui.warn("[DEPRECATED] --chef-tag option is deprecated and will be removed in future release. Use --tags TAGS option instead.")
end
+
+ if config_value(:cpu_credits) && !config_value(:flavor)
+ ui.error("Instance type should be specified and should be any of T2/T3 type.")
+ exit 1
+ end
end
def parse_aws_tags
tags = config_value(:aws_tag)
if !tags.nil? && (tags.length != tags.to_s.count("="))
@@ -956,10 +968,15 @@
## cannot pass disable_api_termination option to the API when using spot instances ##
attributes[:disable_api_termination] = config_value(:disable_api_termination) if config_value(:spot_price).nil?
attributes[:instance_initiated_shutdown_behavior] = config_value(:instance_initiated_shutdown_behavior)
+
+ attributes[:credit_specification] =
+ {
+ cpu_credits: config[:cpu_credits],
+ }
attributes
end
def create_ec2_instance(attributes)
ec2_connection.run_instances(attributes)
@@ -1398,9 +1415,17 @@
ht
end
def printed_aws_tags
hashed_tags.map { |tag, val| "#{tag}: #{val}" }.join(", ")
+ end
+
+ def printed_t2_t3_unlimited
+ if config[:cpu_credits] == "unlimited"
+ "Enabled"
+ else
+ "Disabled"
+ end
end
end
end
end