def manage_resource(request, resource_id, action_type): """ Manages the actions executed over SampleResource's. """ if action_type == "delete": SampleResourceController.delete(resource_id) # Go to manage resources again return HttpResponse("")
def sync_am_resources(agg_id, xmlrpc_server): """ Retrieves SampleResource objects from the AM's xmlrpc server every time the AM is updated """ connections = dict() failed_resources = [] resources = xmlrpc_server.get_resources() context = etree.iterparse(BytesIO(resources)) delete_resources(agg_id) aggregate = SampleResourceAggregateModel.objects.get(id = agg_id) # for slice in aggregate.slice_set: # File (nodes) for action, elem in context: node_name = "" instance = am_resource() children_context = elem.iterchildren() # Node (tags) for elem in children_context: if "connection" not in elem.tag: setattr(instance, elem.tag, elem.text) if elem.tag == "name": node_name = elem.text elif elem.tag == "connections": connections[node_name] = [] connections_context = elem.iterchildren() for connection in connections_context: connections[node_name].append(connection.text) try: if instance: # SampleResourceController.create(instance, agg_id, slice) SampleResourceController.create(instance, agg_id) except: try: failed_resources.append(instance.name) except: pass # Connections between SampleResources are computed later, when all nodes have been created try: for node, node_connections in connections.iteritems(): connections_aux = [] for connection in node_connections: try: # Linked to another SampleResources res = SampleResourceModel.objects.get(name = connection) if res: connections_aux.append(res) except: pass connections[node] = connections_aux # Setting connections on resource with name as in 'node' var node_resource = SampleResourceModel.objects.get(name = node) node_resource.set_connections(connections[node]) node_resource.save() except: pass return failed_resources
def sync_am_resources(agg_id, xmlrpc_server): """ Retrieves SampleResource objects from the AM's xmlrpc server every time the AM is updated """ connections = dict() failed_resources = [] resources = xmlrpc_server.get_resources() context = etree.iterparse(BytesIO(resources)) delete_resources(agg_id) aggregate = SampleResourceAggregateModel.objects.get(id=agg_id) # for slice in aggregate.slice_set: # File (nodes) for action, elem in context: node_name = "" instance = am_resource() children_context = elem.iterchildren() # Node (tags) for elem in children_context: if "connection" not in elem.tag: setattr(instance, elem.tag, elem.text) if elem.tag == "name": node_name = elem.text elif elem.tag == "connections": connections[node_name] = [] connections_context = elem.iterchildren() for connection in connections_context: connections[node_name].append(connection.text) try: if instance: # SampleResourceController.create(instance, agg_id, slice) SampleResourceController.create(instance, agg_id) except: try: failed_resources.append(instance.name) except: pass # Connections between SampleResources are computed later, when all nodes have been created try: for node, node_connections in connections.iteritems(): connections_aux = [] for connection in node_connections: try: # Linked to another SampleResources res = SampleResourceModel.objects.get(name=connection) if res: connections_aux.append(res) except: pass connections[node] = connections_aux # Setting connections on resource with name as in 'node' var node_resource = SampleResourceModel.objects.get(name=node) node_resource.set_connections(connections[node]) node_resource.save() except: pass return failed_resources
def pre_save(instance, created): """ Fills SampleResource instance prior to its saving. Used within the scope of the generic_crud method. """ instance = SampleResourceController.fill(instance, slice, agg_id, resource_id)