Пример #1
0
def sync_instance(contact, email):
    contact = contact or settings.get('contact_name')
    email = email or settings.get('contact_email')
    # registration needed if the instance does not have a uuid
    if not settings.get('uuid'):
        logger.warn(
            'unable to synchronise: missing uuid, registering the server instead'
        )
        register_instance(contact, email)
        return

    organisation = HelperMaKaCInfo.getMaKaCInfoInstance().getOrganisation()
    payload = {
        'enabled': True,
        'url': Config.getInstance().getBaseURL(),
        'contact': contact,
        'email': email,
        'organisation': organisation
    }
    url = urljoin(_url, settings.get('uuid'))
    response = requests.patch(url,
                              data=dumps(payload),
                              headers=_headers,
                              timeout=TIMEOUT)
    try:
        response.raise_for_status()
    except HTTPError as err:
        if err.response.status_code == 404:
            logger.warn(
                'unable to synchronise: the server was not registered, registering the server now'
            )
            register_instance(contact, email)
        else:
            logger.error(
                'failed to synchronise the server with the community hub, got: %s',
                err.message)
            raise
    except Timeout:
        logger.error(
            'failed to synchronise: timeout while contacting the community hub'
        )
        raise
    except RequestException as err:
        logger.error(
            'unexpected exception while synchronizing the server with the Community Hub: %s',
            err.message)
        raise
    else:
        settings.set_multi({
            'joined': True,
            'contact_name': payload['contact'],
            'contact_email': payload['email']
        })
        logger.info(
            'successfully synchronized the server with the community hub')
Пример #2
0
def sync_instance(contact, email):
    contact = contact or cephalopod_settings.get('contact_name')
    email = email or cephalopod_settings.get('contact_email')
    # registration needed if the instance does not have a uuid
    if not cephalopod_settings.get('uuid'):
        logger.warn(
            'unable to synchronize: missing uuid, registering the server instead'
        )
        register_instance(contact, email)
        return

    payload = {
        'enabled': True,
        'url': config.BASE_URL,
        'contact': contact,
        'email': email,
        'organization': core_settings.get('site_organization')
    }
    url = url_join(_get_url(), cephalopod_settings.get('uuid'))
    response = requests.patch(url,
                              data=json.dumps(payload),
                              headers=HEADERS,
                              timeout=TIMEOUT,
                              verify=(not config.DEBUG))
    try:
        response.raise_for_status()
    except HTTPError as err:
        if err.response.status_code == 404:
            logger.warn(
                'unable to synchronize: the server was not registered, registering the server now'
            )
            register_instance(contact, email)
        else:
            logger.error(
                'failed to synchronize the server with the community hub, got: %s',
                err.message)
            raise
    except Timeout:
        logger.error(
            'failed to synchronize: timeout while contacting the community hub'
        )
        raise
    except RequestException as err:
        logger.error(
            'unexpected exception while synchronizing the server with the Community Hub: %s',
            err.message)
        raise
    else:
        cephalopod_settings.set_multi({
            'joined': True,
            'contact_name': payload['contact'],
            'contact_email': payload['email']
        })
        logger.info(
            'successfully synchronized the server with the community hub')
Пример #3
0
def sync_instance(contact, email):
    contact = contact or settings.get('contact_name')
    email = email or settings.get('contact_email')
    # registration needed if the instance does not have a uuid
    if not settings.get('uuid'):
        logger.warn('unable to synchronise: missing uuid, registering the server instead')
        register_instance(contact, email)
        return

    organisation = HelperMaKaCInfo.getMaKaCInfoInstance().getOrganisation()
    payload = {'enabled': True,
               'url': Config.getInstance().getBaseURL(),
               'contact': contact,
               'email': email,
               'organisation': organisation}
    url = urljoin(_url, settings.get('uuid'))
    response = requests.patch(url, data=dumps(payload), headers=_headers, timeout=TIMEOUT)
    try:
        response.raise_for_status()
    except HTTPError as err:
        if err.response.status_code == 404:
            logger.warn('unable to synchronise: the server was not registered, registering the server now')
            register_instance(contact, email)
        else:
            logger.error('failed to synchronise the server with the community hub, got: {err.message}'.format(err=err))
            raise
    except Timeout:
        logger.error('failed to synchronise: timeout while contacting the community hub')
        raise
    except RequestException as err:
        logger.error('unexpected exception while synchronizing the server with the Community Hub: {err.message}'
                     .format(err=err))
        raise
    else:
        settings.set_multi({
            'joined': True,
            'contact_name': payload['contact'],
            'contact_email': payload['email']})
        logger.info('successfully synchronized the server with the community hub')
Пример #4
0
def sync_instance(contact, email):
    contact = contact or cephalopod_settings.get('contact_name')
    email = email or cephalopod_settings.get('contact_email')
    # registration needed if the instance does not have a uuid
    if not cephalopod_settings.get('uuid'):
        logger.warn('unable to synchronize: missing uuid, registering the server instead')
        register_instance(contact, email)
        return

    payload = {'enabled': True,
               'url': config.BASE_URL,
               'contact': contact,
               'email': email,
               'organization': core_settings.get('site_organization')}
    url = url_join(_get_url(), cephalopod_settings.get('uuid'))
    response = requests.patch(url, data=json.dumps(payload), headers=HEADERS, timeout=TIMEOUT,
                              verify=(not config.DEBUG))
    try:
        response.raise_for_status()
    except HTTPError as err:
        if err.response.status_code == 404:
            logger.warn('unable to synchronize: the server was not registered, registering the server now')
            register_instance(contact, email)
        else:
            logger.error('failed to synchronize the server with the community hub, got: %s', err.message)
            raise
    except Timeout:
        logger.error('failed to synchronize: timeout while contacting the community hub')
        raise
    except RequestException as err:
        logger.error('unexpected exception while synchronizing the server with the Community Hub: %s', err.message)
        raise
    else:
        cephalopod_settings.set_multi({
            'joined': True,
            'contact_name': payload['contact'],
            'contact_email': payload['email']})
        logger.info('successfully synchronized the server with the community hub')