Skip to content

Commit 9ff369a

Browse files
authored
Release 1.5.4
Release 1.5.4
2 parents f10cd73 + 631dcaf commit 9ff369a

File tree

8 files changed

+170
-147
lines changed

8 files changed

+170
-147
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ cfncluster-node CHANGELOG
33

44
This file is used to list changes made in each version of the cfncluster-node package.
55

6+
1.5.4
7+
-----
8+
9+
Bug fixes/minor improvements:
10+
11+
- Upgraded Boto2 to Boto3 package.
12+
13+
614
1.5.2
715
-----
816

nodewatcher/nodewatcher.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[nodewatcher]
22
region = us-east-1
33
scheduler = test
4+
proxy = NONE

nodewatcher/nodewatcher.py

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414
__author__ = 'dougalb'
1515

1616
from datetime import datetime
17-
import boto.ec2
18-
import dateutil.parser
1917
import urllib2
20-
import ConfigParser
21-
import boto.ec2.autoscale
2218
import os
2319
import time
2420
import sys
2521
import tempfile
2622
import logging
23+
import boto3
24+
import ConfigParser
25+
from botocore.config import Config
2726

2827
log = logging.getLogger(__name__)
2928

@@ -37,12 +36,20 @@ def getConfig(instance_id):
3736
logging.getLogger().setLevel(lvl)
3837
_region = config.get('nodewatcher', 'region')
3938
_scheduler = config.get('nodewatcher', 'scheduler')
39+
_proxy = config.get('nodewatcher', 'proxy')
40+
proxy_config = Config()
41+
42+
if not _proxy == "NONE":
43+
proxy_config = Config(proxies={'https': _proxy})
44+
4045
try:
4146
_asg = config.get('nodewatcher', 'asg')
4247
except ConfigParser.NoOptionError:
43-
conn = boto.ec2.connect_to_region(_region,proxy=boto.config.get('Boto', 'proxy'),
44-
proxy_port=boto.config.get('Boto', 'proxy_port'))
45-
_asg = conn.get_all_instances(instance_ids=instance_id)[0].instances[0].tags['aws:autoscaling:groupName']
48+
ec2 = boto3.resource('ec2', region_name=_region, config=proxy_config)
49+
50+
instances = ec2.instances.filter(InstanceIds=[instance_id])
51+
instance = next(iter(instances or []), None)
52+
_asg = filter(lambda tag: tag.get('Key') == 'aws:autoscaling:groupName', instance.tags)[0].get('Value')
4653
log.debug("discovered asg: %s" % _asg)
4754
config.set('nodewatcher', 'asg', _asg)
4855

@@ -53,13 +60,13 @@ def getConfig(instance_id):
5360

5461
os.rename(tup[1], 'nodewatcher.cfg')
5562

56-
log.debug("region=%s asg=%s scheduler=%s" % (_region, _asg, _scheduler))
57-
return _region, _asg, _scheduler
63+
log.debug("region=%s asg=%s scheduler=%s prox_config=%s" % (_region, _asg, _scheduler, proxy_config))
64+
return _region, _asg, _scheduler, proxy_config
5865

59-
def getHourPercentile(instance_id, conn):
60-
_reservations = conn.get_all_instances(instance_ids=[instance_id])
61-
_instance = _reservations[0].instances[0]
62-
_launch_time = dateutil.parser.parse(_instance.launch_time).replace(tzinfo=None)
66+
def getHourPercentile(instance_id, ec2):
67+
instances = ec2.instances.filter(InstanceIds=[instance_id])
68+
instance = next(iter(instances or []), None)
69+
_launch_time = instance.launch_time.replace(tzinfo=None)
6370
_current_time = datetime.utcnow()
6471
_delta = _current_time - _launch_time
6572
_delta_in_hours = _delta.seconds / 3600.0
@@ -121,20 +128,17 @@ def lockHost(s,hostname,unlock=False):
121128

122129
return _r
123130

124-
def selfTerminate(region, asg, instance_id):
125-
_as_conn = boto.ec2.autoscale.connect_to_region(region,proxy=boto.config.get('Boto', 'proxy'),
126-
proxy_port=boto.config.get('Boto', 'proxy_port'))
127-
if not maintainSize(region, asg):
131+
def selfTerminate(asg_name, asg_conn, instance_id):
132+
if not maintainSize(asg_name, asg_conn):
128133
log.info("terminating %s" % instance_id)
129-
_as_conn.terminate_instance(instance_id, decrement_capacity=True)
130-
131-
def maintainSize(region, asg):
132-
_as_conn = boto.ec2.autoscale.connect_to_region(region,proxy=boto.config.get('Boto', 'proxy'),
133-
proxy_port=boto.config.get('Boto', 'proxy_port'))
134-
_asg = _as_conn.get_all_groups(names=[asg])[0]
135-
_capacity = _asg.desired_capacity
136-
_min_size = _asg.min_size
137-
log.debug("capacity=%d min_size=%d" % (_capacity, _min_size))
134+
asg_conn.terminate_instance_in_auto_scaling_group(InstanceId=instance_id, ShouldDecrementDesiredCapacity=True)
135+
136+
def maintainSize(asg_name, asg_conn):
137+
asg = asg_conn.describe_auto_scaling_groups(AutoScalingGroupNames=[asg_name]) \
138+
.get('AutoScalingGroups')[0]
139+
_capacity = asg.get('DesiredCapacity')
140+
_min_size = asg.get('MinSize')
141+
log.info("capacity=%d min_size=%d" % (_capacity, _min_size))
138142
if _capacity > _min_size:
139143
log.debug('capacity greater then min size.')
140144
return False
@@ -150,24 +154,25 @@ def main():
150154
log.info("nodewatcher startup")
151155
instance_id = getInstanceId()
152156
hostname = getHostname()
153-
region, asg, scheduler = getConfig(instance_id)
157+
region, asg_name, scheduler, proxy_config = getConfig(instance_id)
154158

155159
s = loadSchedulerModule(scheduler)
156160

157161
while True:
158162
time.sleep(60)
159-
conn = boto.ec2.connect_to_region(region)
160-
hour_percentile = getHourPercentile(instance_id,conn)
163+
ec2_conn = boto3.resource('ec2', region_name=region, config=proxy_config)
164+
asg_conn = boto3.client('autoscaling', region_name=region, config=proxy_config)
165+
hour_percentile = getHourPercentile(instance_id, ec2_conn)
161166
log.info('Percent of hour used: %d' % hour_percentile)
162167

163168
if hour_percentile < 95:
164169
continue
165-
170+
166171
jobs = getJobs(s, hostname)
167172
if jobs == True:
168173
log.info('Instance has active jobs.')
169174
else:
170-
if maintainSize(region, asg):
175+
if maintainSize(asg_name, asg_conn):
171176
continue
172177
# avoid race condition by locking and verifying
173178
lockHost(s, hostname)
@@ -177,7 +182,7 @@ def main():
177182
lockHost(s, hostname, unlock=True)
178183
continue
179184
else:
180-
selfTerminate(region, asg, instance_id)
185+
selfTerminate(asg_name, asg_conn, instance_id)
181186

182187
if __name__ == "__main__":
183188
main()

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
boto>=2.48.0
1+
boto3>=1.7.55
22
paramiko>=2.3.1
33
python-dateutil>=2.6.1

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def read(fname):
2121

2222
console_scripts = ['sqswatcher = sqswatcher.sqswatcher:main',
2323
'nodewatcher = nodewatcher.nodewatcher:main']
24-
version = "1.5.2"
25-
requires = ['boto>=2.48.0', 'python-dateutil>=2.6.1']
24+
version = "1.5.4"
25+
requires = ['boto3>=1.7.55', 'python-dateutil>=2.6.1']
2626

2727
if sys.version_info[:2] == (2, 6):
2828
# For python2.6 we have to require argparse since it

sqswatcher/plugins/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717

1818
hostfile_path = 'sqswatcher.hosts'
1919

20-
def addHost(hostname,cluster_user):
20+
def addHost(hostname,cluster_user,slots):
2121
if hostname != None:
22-
log.info('Adding', hostname)
22+
log.info('Adding %s' % hostname)
2323
hostfile = open(hostfile_path, 'a')
2424
print >> hostfile, hostname
2525
hostfile.close()
2626

2727
def removeHost(hostname,cluster_user):
2828
if hostname != None:
29-
log.info('Removing', hostname)
29+
log.info('Removing %s' % hostname)
3030
hostfile = open(hostfile_path, 'r')
3131
lines = hostfile.readlines()
3232
hostfile.close()

sqswatcher/sqswatcher.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ sqsqueue = AS-SQS
44
table_name = instances
55
scheduler = test
66
cluster_user = ec2-user
7+
proxy = NONE

0 commit comments

Comments
 (0)