def update(instance_id): updateable_params = ('AllocatedStorage',) incompletes = bottle.request.query.getone('accepts_incomplete') bottle.response.content_type = 'application/json' if incompletes is None: return _abort_async_required() data = json.loads(bottle.request.body.read()) for param in data['parameters'].keys(): if param not in updateable_params: bottle.response.status = 400 msg = 'Updating of {0} is not supported'.format(param) return json.dumps({'description': msg}) dynamodb = utils.boto3_session(**CONFIG['aws']).resource('dynamodb') table = dynamodb.Table(name=CONFIG['dynamodb_table']) record = table.get_item(Key={'instance_id': instance_id}) if 'Item' not in record.keys(): bottle.response.status = 410 return json.dumps({}) else: record = record.pop('Item') rds = RDS(DBInstanceIdentifier=record['hostname'], **CONFIG['aws']) details = rds.db_instance_details() if data['parameters']['AllocatedStorage'] <= details['AllocatedStorage']: bottle.response.status = 400 return json.dumps({ 'description': 'Decreasing AllocatedStorage is not supported.' }) rds.update_instance( DBInstanceIdentifier=record['hostname'], **data['parameters'] ) for i in xrange(0,10): details = rds.db_instance_details() if details['DBInstanceStatus'] != 'available': break sleep(5) else: bottle.response.status = 408 return json.dumps({}) record['last_operation'] = 'update' record['parameters'] = data['parameters'] table.put_item(Item=record) bottle.response.status = 202 return json.dumps({})
def update_polling(record): """Last operation polling logic for update action. """ rds = RDS(DBInstanceIdentifier=record['hostname'], **CONFIG['aws']) details = rds.db_instance_details() if details['DBInstanceStatus'] != 'available': response = {'state': 'in progress', 'description': 'Updating service.'} bottle.response.status = 200 return json.dumps(response) else: response = {'state': 'succeeded', 'description': 'Service updated.'} bottle.response.status = 200 return json.dumps(response)