Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch ec2 tags from aws instead of from facter command #1447

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy-agent/deployd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
# 2: puppet applied successfully with changes
PUPPET_SUCCESS_EXIT_CODES = [0, 2]

__version__ = '1.2.57'
__version__ = '1.2.58'
18 changes: 15 additions & 3 deletions deploy-agent/deployd/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import socket
import traceback
import json
import boto3

from deployd.client.base_client import BaseClient
from deployd.client.restfulclient import RestfulClient
Expand Down Expand Up @@ -171,11 +172,22 @@ def _read_host_info(self):
# so need to read ec2_tags from facter and parse Autoscaling tag to cover this case
if not self._autoscaling_group:
ec2_tags = facter_data.get(ec2_tags_key)
if ec2_tags:
ec2_tags['availability_zone'] = self._availability_zone
self._ec2_tags = json.dumps(ec2_tags) if ec2_tags else None
self._autoscaling_group = ec2_tags.get(asg_tag_key) if ec2_tags else None

# Obtain all EC2 tags, inclusive of those that are outside the scope of the 'facter' command.
self._ec2_tags = None
try:
ec2 = boto3.resource('ec2', region_name='us-east-1')
liyaqin1 marked this conversation as resolved.
Show resolved Hide resolved
ec2instance = ec2.Instance(self._id)
all_tags = {}
for tag in ec2instance.tags:
all_tags[tag["Key"]] = tag["Value"]
all_tags["availability_zone"] = self._availability_zone
self._ec2_tags = json.dumps(all_tags)
except Exception:
log.warn("Failed to get host {} tags.".format(self._id))
pass

if not self._stage_type and not self._stage_type_fetched:
self._stage_type = facter_data.get(stage_type_key, None)
self._stage_type_fetched = True
Expand Down
2 changes: 2 additions & 0 deletions deploy-agent/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"gevent==20.12.0; python_version >= '3.8'",
"lockfile==0.10.2",
"boto>=2.39.0",
"botocore==1.5.34",
"boto3==1.4.4",
"python-daemon==2.0.6",
"future==0.18.2"
]
Expand Down
Loading