Example #1
0
def get_all_domains():
    """Retrieves the list of all domains and prints their total number and
    the number of active domains.

    The number of the domains must be always greater than zero,
    since the default domain is always in the list of the returned domains.
    """
    response = api('config/domain_management/domains', 'GET')
    response_body = from_json(response)

    print('INFO: Number of all domains retrieved: ' + str(len(response_body)))

    # Now count only active domains.
    num = sum(map(lambda d: d['deleted'] is False, response_body))
    print('INFO: Number of active domains retrieved: ' + str(num))
Example #2
0
def update_domain(domain):
    """Returns an updated domain.

    It is only the description of the domain which is changed from empty to
    'New Description'.
    """
    domain['description'] = 'New Description'
    response = api('config/domain_management/domains/' + str(domain['id']),
                   'POST', data=to_json(domain), json=True)
    if response.code == 200:
        updated_domain = from_json(response)
        if updated_domain['description'] == 'New Description':
            print('INFO: Domain successfully updated', file=sys.stderr)
            return domain

    print('ERROR: Domain update failed', file=sys.stderr)
    pp_response(response)
Example #3
0
def update_domain(domain):
    """Returns an updated domain.

    It is only the description of the domain which is changed from empty to
    'New Description'.
    """
    domain['description'] = 'New Description'
    response = api('config/domain_management/domains/' + str(domain['id']),
                   'POST',
                   data=to_json(domain),
                   json=True)
    if response.code == 200:
        updated_domain = from_json(response)
        if updated_domain['description'] == 'New Description':
            print('INFO: Domain successfully updated', file=sys.stderr)
            return domain

    print('ERROR: Domain update failed', file=sys.stderr)
    pp_response(response)