def show(self, request, resource, *args, **kwargs): """ Handle the GET /nodes/{resource} request Args: request (webob.Request): the request object from WSGI resource (str): the resource being requested Returns: A dict as the result of the state machine which is used to create a WSGI response object. """ log.info('%s: received request for definition: %s' % (resource, request.url)) log.debug('%s\nResource: %s\n' % (request, resource)) node_id = resource.split('/')[0] try: fobj = self.repository.get_file(self.expand(resource, NODE_FN)) node = create_node(fobj.read(CONTENT_TYPE_JSON)) except Exception as err: # pylint: disable=W0703 log.error('%s: unable to read %s file for %s: %s' % (NODE_FN, node_id, resource, err)) response = self.http_bad_request() return self.response(**response) return self.fsm('do_validation', resource=resource, request=request, node=node, node_id=node_id)
def create(self, request, **kwargs): """ Handle the POST /nodes request The create method will handle in incoming POST request from the node and determine if the node already exists or not. If the node does not exist, then the node will be created based on the request body. Args: request (webob.Request): the request object from WSGI Returns: A dict as the result of the state machine which is used to create a WSGI response object. """ log.debug('%s\n' % request) try: node = create_node(request.json) except Exception as err: # pylint: disable=W0703 log.error('Unable to create node: %s (request=%s)' % (err, request)) response = self.http_bad_request() return self.response(**response) node_id = node.identifier() if not node_id: log.error('Missing node identifier: %s (request=%s)' % (node, request)) response = self.http_bad_request() return self.response(**response) return self.fsm('node_exists', request=request, node=node, node_id=node_id)
def show(self, request, resource, *args, **kwargs): """ Handle the GET /nodes/{resource} request Args: request (webob.Request): the request object from WSGI resource (str): the resource being requested Returns: A dict as the result of the state machine which is used to create a WSGI response object. """ log.debug('%s\nResource: %s\n' % (request, resource)) node_id = resource.split('/')[0] try: fobj = self.repository.get_file(self.expand(resource, NODE_FN)) node = create_node(fobj.read(CONTENT_TYPE_JSON)) except Exception as err: # pylint: disable=W0703 log.error('%s: unable to read file resource %s: %s' % (node_id, resource, err)) response = self.http_bad_request() return self.response(**response) return self.fsm('get_definition', resource=resource, request=request, node=node, node_id=node_id)
def create(self, request, **kwargs): """ Handle the POST /nodes request The create method will handle in incoming POST request from the node and determine if the node already exists or not. If the node does not exist, then the node will be created based on the request body. Args: request (webob.Request): the request object from WSGI Returns: A dict as the result of the state machine which is used to create a WSGI response object. """ log.info('%s: received system information from node:\n%s' % (request.remote_addr, request.json)) try: node = create_node(request.json) except Exception as err: # pylint: disable=W0703 log.error('Unable to create node: %s (request=%s)' % (err, request)) response = self.http_bad_request() return self.response(**response) node_id = node.identifier() if not node_id: log.error('Missing node identifier: %s (request=%s)' % (node, request)) response = self.http_bad_request() return self.response(**response) identifier = runtime.default.identifier log.info('%s: node ID is %s:%s' % (request.remote_addr, identifier, node_id)) return self.fsm('node_exists', request=request, node=node, node_id=node_id)
def test_create_node_fixup_systemmac_period(self): attrs = Mock(systemmac='99.99.99.99.99.99') result = create_node({'systemmac': attrs.systemmac}) self.assertTrue('.' not in result.systemmac)
def test_create_node_fixup_systemmac_colon(self): attrs = Mock(systemmac='99:99:99:99:99:99') result = create_node({'systemmac': attrs.systemmac}) self.assertTrue(':' not in result.systemmac)