def unregister_instance(): payload = {'enabled': False} 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.error( 'failed to unregister the server to the community hub, got: %s', err.message) raise except Timeout: logger.error( 'failed to unregister: timeout while contacting the community hub') raise except RequestException as err: logger.error( 'unexpected exception while unregistering the server with the Community Hub: %s', err.message) raise settings.set('joined', False) logger.info('successfully unregistered the server from the community hub')
def unregister_instance(): payload = {'enabled': False} 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.error('failed to unregister the server to the community hub, got: %s', err.message) raise except Timeout: logger.error('failed to unregister: timeout while contacting the community hub') raise except RequestException as err: logger.error('unexpected exception while unregistering the server with the Community Hub: %s', err.message) raise settings.set('joined', False) logger.info('successfully unregistered the server from the community hub')
def register_instance(contact, email): organisation = HelperMaKaCInfo.getMaKaCInfoInstance().getOrganisation() payload = {'url': Config.getInstance().getBaseURL(), 'contact': contact, 'email': email, 'organisation': organisation} response = requests.post(_url, data=dumps(payload), headers=_headers, timeout=TIMEOUT) try: response.raise_for_status() except HTTPError as err: logger.error('failed to register the server to the community hub, got: %s', err.message) settings.set('joined', False) raise except Timeout: logger.error('failed to register: timeout while contacting the community hub') settings.set('joined', False) raise except RequestException as err: logger.error('unexpected exception while registering the server with the Community Hub: %s', err.message) raise json_response = response.json() if 'uuid' not in json_response: logger.error('invalid json reply from the community hub: uuid missing') settings.set('joined', False) raise ValueError('invalid json reply from the community hub: uuid missing') settings.set_multi({ 'joined': True, 'uuid': json_response['uuid'], 'contact_name': payload['contact'], 'contact_email': payload['email'] }) logger.info('successfully registered the server to the community hub')
def register_instance(contact, email): organisation = HelperMaKaCInfo.getMaKaCInfoInstance().getOrganisation() payload = { 'url': Config.getInstance().getBaseURL(), 'contact': contact, 'email': email, 'organisation': organisation } response = requests.post(_url, data=dumps(payload), headers=_headers, timeout=TIMEOUT) try: response.raise_for_status() except HTTPError as err: logger.error( 'failed to register the server to the community hub, got: %s', err.message) settings.set('joined', False) raise except Timeout: logger.error( 'failed to register: timeout while contacting the community hub') settings.set('joined', False) raise except RequestException as err: logger.error( 'unexpected exception while registering the server with the Community Hub: %s', err.message) raise json_response = response.json() if 'uuid' not in json_response: logger.error('invalid json reply from the community hub: uuid missing') settings.set('joined', False) raise ValueError( 'invalid json reply from the community hub: uuid missing') settings.set_multi({ 'joined': True, 'uuid': json_response['uuid'], 'contact_name': payload['contact'], 'contact_email': payload['email'] }) logger.info('successfully registered the server to the community hub')