Skip to content

Instantly share code, notes, and snippets.

@ephur
Created March 29, 2013 22:12
Show Gist options
  • Save ephur/5274034 to your computer and use it in GitHub Desktop.
Save ephur/5274034 to your computer and use it in GitHub Desktop.
for region in servers:
for server in servers[region]:
server_check = self.__server_okay_to_delete(server, constraints)
if server_check['bool'] is not True:
self._log.info("%s:NOT_DELETED:%s:%s:%s:%s" % (job_name, ddi, server.id, region, server_check['msg']))
continue
try:
# @TODO (ephur): Uncomment the line below to make this thing delete all the things
# self._regions[region].servers.delete(server.id)
self._log.info("%s:DELETED:%s:%s:%s:%s" % (job_name, ddi, server.id, region, self._flavors[int(server.flavor['id'])]))
results.append((job_name, "deleted", ddi, server.id, region, self._flavors[int(server.flavor['id'])]))
except novaexceptions.ClientException as e:
self._log.error("%s:ERROR_DELETING:%s:%s:%s:%s" % (job_name, ddi, server.id, region, self._flavors[int(server.flavor['id'])]))
results.append((job_name, "error_deleting", ddi, server.id, region, self._flavors[int(server.flavor['id'])]))
return results
@ephur
Copy link
Author

ephur commented Mar 29, 2013

def __account_okay_to_delete(self, ddi, constraints):
    """ Check the account level constraints """
    check = dict()
    check['bool'] = True
    check['msg'] = ""

    # Account Level Constraints
    if 'auth' in constraints.keys():
        # Check auth for the account
        if self.__check_auth(ddi) not in constraints['auth']:
            check['bool'] = False
            check['msg'] += ':auth status not in allowed values'

    if 'status' in constraints.keys():
        if self.__check_status(ddi) not in constraints['status']:
            check['bool'] = False
            check['msg'] += ':account status not in allowed values'

    if 'hours_in_status' in constraints.keys():
        try:
            if self.__hours_since_update(ddi) < int(constraints['hours_in_status']):
                check['bool'] = False
                check['msg'] += ':account not in status long enough (%s hours)' % (self.__hours_since_update(ddi))
        except Typecheck as e:
                check['bool'] = False
                check['msg'] += ':unable to determine how long account in current status'

    return check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment