<commit_before>from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Nodes import Node, Nodes
from PLC.Slices import Slice, Slices
from PLC.Auth import Auth

class AddSliceToNodes(Method):
    """
    Adds the specified slice to the specified nodes. Nodes may be
    either local or foreign nodes.

    If the slice is already associated with a node, no errors are
    returned.

    Returns 1 if successful, faults otherwise.
    """

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

    accepts = [
        Auth(),
        Mixed(Slice.fields['slice_id'],
              Slice.fields['name']),
	[Mixed(Node.fields['node_id'],
               Node.fields['hostname'])]
        ]

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

    def call(self, auth, slice_id_or_name, node_id_or_hostname_list):
        # Get slice information
        slices = Slices(self.api, [slice_id_or_name])
        if not slices:
            raise PLCInvalidArgument, "No such slice"
        slice = slices[0]

        if slice['peer_id'] is not None:
            raise PLCInvalidArgument, "Not a local slice"

        if 'admin' not in self.caller['roles']:
            if self.caller['person_id'] in slice['person_ids']:
                pass
            elif 'pi' not in self.caller['roles']:
                raise PLCPermissionDenied, "Not a member of the specified slice"
            elif slice['site_id'] not in self.caller['site_ids']:
                raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
	
        # Get specified nodes, add them to the slice         
        nodes = Nodes(self.api, node_id_or_hostname_list)
	for node in nodes:
	    # check the slice whitelist on each node first
	    if node['slice_ids_whitelist'] and \
	       slice['slice_id'] not in node['slice_ids_whitelist']:
		raise PLCInvalidArgument, "%s is not on %s's whitelist" % \
		  (slice['name'], node['hostname'])
            if slice['slice_id'] not in node['slice_ids']:
                slice.add_node(node, commit = False)

        slice.sync()

	self.event_objects = {'Node': [node['node_id'] for node in nodes],
			      'Slice': [slice['slice_id']]}

        return 1<commit_msg>- only query the node_fields we need<commit_after>from PLC.Faults import *
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Nodes import Node, Nodes
from PLC.Slices import Slice, Slices
from PLC.Auth import Auth

class AddSliceToNodes(Method):
    """
    Adds the specified slice to the specified nodes. Nodes may be
    either local or foreign nodes.

    If the slice is already associated with a node, no errors are
    returned.

    Returns 1 if successful, faults otherwise.
    """

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

    accepts = [
        Auth(),
        Mixed(Slice.fields['slice_id'],
              Slice.fields['name']),
	[Mixed(Node.fields['node_id'],
               Node.fields['hostname'])]
        ]

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

    def call(self, auth, slice_id_or_name, node_id_or_hostname_list):
        # Get slice information
        slices = Slices(self.api, [slice_id_or_name])
        if not slices:
            raise PLCInvalidArgument, "No such slice"
        slice = slices[0]

        if slice['peer_id'] is not None:
            raise PLCInvalidArgument, "Not a local slice"

        if 'admin' not in self.caller['roles']:
            if self.caller['person_id'] in slice['person_ids']:
                pass
            elif 'pi' not in self.caller['roles']:
                raise PLCPermissionDenied, "Not a member of the specified slice"
            elif slice['site_id'] not in self.caller['site_ids']:
                raise PLCPermissionDenied, "Specified slice not associated with any of your sites"
	
        # Get specified nodes, add them to the slice         
        nodes = Nodes(self.api, node_id_or_hostname_list, ['node_id', 'hostname', 'slice_ids', 'slice_ids_whitelist'])
	for node in nodes:
	    # check the slice whitelist on each node first
	    if node['slice_ids_whitelist'] and \
	       slice['slice_id'] not in node['slice_ids_whitelist']:
		raise PLCInvalidArgument, "%s is not on %s's whitelist" % \
		  (slice['name'], node['hostname'])
            if slice['slice_id'] not in node['slice_ids']:
                slice.add_node(node, commit = False)

        slice.sync()

	self.event_objects = {'Node': [node['node_id'] for node in nodes],
			      'Slice': [slice['slice_id']]}

        return 1
{'fraction_non_alphanumeric': 0.10599382988100485, 'fraction_numerical': 0.0017628911414720142, 'mean_word_length': 2.596671949286846, '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': '1856412', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1324, 'n_words': 429}