def _set_node_bundle(self): self.cwrite('Setting Node rule bundle...') data = NodeBundle(node=self._node.id, bundle=self._bundle.id) self._node_bundle, status_code = self._sds_conn.create_node_bundle( data) if not self._node_bundle: self.cwriteline('[Failed]', 'Unable to set Node rule bundle.') return False self.cwriteline('[OK]', 'Node rule bundle successfully set.') return True
def get_node_bundle_by_node_id(self, node_id): """ Get the Node Bundle from the server using the node id :param node_id: :return: """ url = '/api/nodes/{0}/bundle/'.format(node_id) reply, status_code, rq = self._make_json_request('GET', url) if reply is not None and status_code == requests.codes.ok and len( reply) > 0: return NodeBundle(reply[0]), status_code _logger.error( 'Failed to retrieve node bundle by node id ({0}).'.format(node_id)) return None, status_code
def update_node_bundle(self, nb): if nb is None: _logger.critical( 'NodeBundle parameter is not valid in update_node_bundle method.' ) return None, requests.codes.teapot url = '/api/nodes/{0}/bundle/{1}/'.format(nb.node, nb.bundle) # NodeBundleViewSet will update or create with a POST request. reply, status_code, rq = self._make_json_request( 'PUT', url, nb.to_dict()) if reply is not None and \ (status_code == requests.codes.created or status_code == requests.codes.ok): return NodeBundle(reply), status_code return None, status_code