<commit_before>from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Auth import PasswordAuth
from PLC.Nodes import Node, Nodes
from PLC.NodeNetworks import NodeNetwork, NodeNetworks

class AdmDeleteNodeNetwork(Method):
    """
    Delete an existing Node Network. Nodenetwork_id must be associated to 
    node_id and not be associated with a different node.

    Admins may delete any node network. PIs and techs can only delete 
    nodenetworks for thier nodes.

    Returns 1 if successful, faults otherwise.
    """

    roles = ['admin', 'pi', 'tech']

    accepts = [
        PasswordAuth(),
        Mixed(NodeNetwork.all_fields['node_id'],
	      NodeNetwork.all_fields['hostname']),
	Mixed(NodeNetwork.all_fields['nodenetwork_id'],
	      NodeNetwork.all_fields['hostname'])
        ]

    returns = Parameter(int, '1 if successful')

    def call(self, auth, node_id_or_hostname, nodenetwork_id_or_hostname):
        # Get node network information
        nodenetworks = NodeNetworks(self.api, [nodenetwork_id_or_hostname]).values()
        if not nodenetworks:
            raise PLCInvalidArgument, "No such node network"
	nodenetwork = nodenetworks[0]
	
	# Get node information
	nodes = Nodes(self.api, [node_id_or_hostname]).values()
	if not nodes:
		raise PLCInvalidArgument, "No such node"
	node = nodes[0]

	# Check if node network is associated with specified node
	if not node['node_id'] ==  nodenetwork['node_id'] or nodenetwork['nodenetwork_id'] not in node['nodenetwork_ids']:
		raise PLCInvalidArgument, "node network not assoicated with this node"

	assert self.caller is not None

        # If we are not an admin, make sure that the caller is a
        # member of the site at which the node is located.
        if 'admin' not in self.caller['roles']:
        	if node['site_id'] not in self.caller['site_ids']:
			raise PLCPermissionDenied, "Not allowed to delete node network at this node"
		if 'tech' not in self.caller['roles']:
                        raise PLCPermissionDenied, "Not allowed to add node network for specified node"
        nodenetwork.delete()

        return 1<commit_msg>- fix parameter documentation - whitespace nits - remove tech role check<commit_after>from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Auth import PasswordAuth
from PLC.Nodes import Node, Nodes
from PLC.NodeNetworks import NodeNetwork, NodeNetworks

class AdmDeleteNodeNetwork(Method):
    """
    Delete an existing Node Network. Nodenetwork_id must be associated to 
    node_id and not be associated with a different node.

    Admins may delete any node network. PIs and techs can only delete 
    nodenetworks for thier nodes.

    Returns 1 if successful, faults otherwise.
    """

    roles = ['admin', 'pi', 'tech']

    accepts = [
        PasswordAuth(),
        Mixed(Node.fields['node_id'],
	      Node.fields['hostname']),
	Mixed(NodeNetwork.fields['nodenetwork_id'],
	      NodeNetwork.fields['hostname'])
        ]

    returns = Parameter(int, '1 if successful')

    def call(self, auth, node_id_or_hostname, nodenetwork_id_or_hostname):
        # Get node network information
        nodenetworks = NodeNetworks(self.api, [nodenetwork_id_or_hostname]).values()
        if not nodenetworks:
            raise PLCInvalidArgument, "No such node network"
	nodenetwork = nodenetworks[0]
	
	# Get node information
	nodes = Nodes(self.api, [node_id_or_hostname]).values()
	if not nodes:
		raise PLCInvalidArgument, "No such node"
	node = nodes[0]

	# Check if node network is associated with specified node
	if node['node_id'] != nodenetwork['node_id'] or \
           nodenetwork['nodenetwork_id'] not in node['nodenetwork_ids']:
            raise PLCInvalidArgument, "Node network not associated with node"

        # Authenticated functino
	assert self.caller is not None

        # If we are not an admin, make sure that the caller is a
        # member of the site at which the node is located.
        if 'admin' not in self.caller['roles']:
            if node['site_id'] not in self.caller['site_ids']:
                raise PLCPermissionDenied, "Not allowed to delete this node network"

        nodenetwork.delete()

        return 1
{'fraction_non_alphanumeric': 0.08397480755773268, 'fraction_numerical': 0.002332633543270352, 'mean_word_length': 3.340080971659919, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3085682', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1246, 'n_words': 426}