Class: Chef::Provisioning::AWSDriver::TaggingStrategy::EC2
- Inherits:
-
Object
- Object
- Chef::Provisioning::AWSDriver::TaggingStrategy::EC2
- Defined in:
- lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb
Instance Attribute Summary collapse
-
#aws_object_id ⇒ Object
readonly
Returns the value of attribute aws_object_id.
-
#desired_tags ⇒ Object
readonly
Returns the value of attribute desired_tags.
-
#ec2_client ⇒ Object
readonly
Returns the value of attribute ec2_client.
Instance Method Summary collapse
- #current_tags ⇒ Object
- #delete_tags(tag_keys) ⇒ Object
-
#initialize(ec2_client, aws_object_id, desired_tags) ⇒ EC2
constructor
A new instance of EC2.
- #set_tags(tags) ⇒ Object
Constructor Details
#initialize(ec2_client, aws_object_id, desired_tags) ⇒ EC2
Returns a new instance of EC2.
26 27 28 29 30 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb', line 26 def initialize(ec2_client, aws_object_id, ) @ec2_client = ec2_client @aws_object_id = aws_object_id @desired_tags = end |
Instance Attribute Details
#aws_object_id ⇒ Object (readonly)
Returns the value of attribute aws_object_id.
24 25 26 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb', line 24 def aws_object_id @aws_object_id end |
#desired_tags ⇒ Object (readonly)
Returns the value of attribute desired_tags.
24 25 26 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb', line 24 def @desired_tags end |
#ec2_client ⇒ Object (readonly)
Returns the value of attribute ec2_client.
24 25 26 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb', line 24 def ec2_client @ec2_client end |
Instance Method Details
#current_tags ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb', line 32 def # http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Client.html#describe_tags-instance_method resp = ec2_client.({ filters: [ { name: "resource-id", values: [aws_object_id] } ] }) Hash[resp..map {|t| [t.key, t.value]}] end |
#delete_tags(tag_keys) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb', line 55 def (tag_keys) # http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Client.html#delete_tags-instance_method ec2_client.({ resources: [aws_object_id], tags: tag_keys.map {|k| {key: k} } }) end |
#set_tags(tags) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/chef/provisioning/aws_driver/tagging_strategy/ec2.rb', line 45 def () # http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Client.html#create_tags-instance_method # "The value parameter is required, but if you don't want the tag to have a value, specify # the parameter with no value, and we set the value to an empty string." ec2_client.({ resources: [aws_object_id], tags: .map {|k,v| {key: k, value: v} } }) end |