示例#1
0
 def test_find_nodegroup_looks_up_only_configured_interfaces(self):
     network = IPNetwork("192.168.41.0/24")
     factory.make_node_group(
         network=network,
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED)
     ip = factory.getRandomIPInNetwork(network)
     self.assertIsNone(find_nodegroup(get_request(ip)))
示例#2
0
 def test_more_than_1_unmanaged_interface(self):
     nodegroup1 = factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED,
         network=IPNetwork("192.168.41.0/16"))
     factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED,
         network=IPNetwork("192.168.41.0/24"))
     self.assertEqual(
         nodegroup1, find_nodegroup(get_request('192.168.41.199')))
示例#3
0
 def test_more_than_1_unmanaged_interface(self):
     nodegroup1 = factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED,
         network=IPNetwork("192.168.41.0/16"))
     factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED,
         network=IPNetwork("192.168.41.0/24"))
     self.assertEqual(nodegroup1,
                      find_nodegroup(get_request('192.168.41.199')))
示例#4
0
 def test_find_nodegroup_handles_multiple_matches_on_same_nodegroup(self):
     self.patch(nodegroupinterface, "MINIMUM_NETMASK_BITS", 1)
     nodegroup = factory.make_node_group(network=IPNetwork("10/8"))
     NodeGroupInterface.objects.create(
         nodegroup=nodegroup, ip='10.0.0.2', subnet_mask='255.0.0.0',
         broadcast_ip='10.0.0.1', interface='eth71')
     NodeGroupInterface.objects.create(
         nodegroup=nodegroup, ip='10.0.0.3', subnet_mask='255.0.0.0',
         broadcast_ip='10.0.0.2', interface='eth72')
     self.assertEqual(nodegroup, find_nodegroup(get_request('10.0.0.9')))
示例#5
0
 def test_1_managed_interface_and_1_unmanaged(self):
     # The managed nodegroup is chosen in preference to the unmanaged
     # nodegroup.
     nodegroup = factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS,
         network=IPNetwork("192.168.41.0/24"))
     factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED,
         network=IPNetwork("192.168.41.0/16"))
     self.assertEqual(
         nodegroup, find_nodegroup(get_request('192.168.41.199')))
示例#6
0
 def test_1_managed_interface_and_1_unmanaged(self):
     # The managed nodegroup is chosen in preference to the unmanaged
     # nodegroup.
     nodegroup = factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS,
         network=IPNetwork("192.168.41.0/24"))
     factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED,
         network=IPNetwork("192.168.41.0/16"))
     self.assertEqual(nodegroup,
                      find_nodegroup(get_request('192.168.41.199')))
示例#7
0
 def test_1_managed_interface(self):
     nodegroup = factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS,
         network=IPNetwork("192.168.41.0/24"))
     self.assertEqual(
         nodegroup, find_nodegroup(get_request('192.168.41.199')))
示例#8
0
 def test_find_nodegroup_returns_None_if_not_found(self):
     self.assertIsNone(
         find_nodegroup(get_request(factory.getRandomIPAddress())))
示例#9
0
 def test_find_nodegroup_looks_up_nodegroup_by_controller_ip(self):
     nodegroup = factory.make_node_group()
     ip = nodegroup.get_managed_interface().ip
     self.assertEqual(
         nodegroup,
         find_nodegroup(get_request(ip)))
示例#10
0
def create_node(request):
    """Service an http request to create a node.

    The node will be in the New state.

    :param request: The http request for this node to be created.
    :return: A `Node`.
    :rtype: :class:`maasserver.models.Node`.
    :raises: ValidationError
    """

    # For backwards compatibilty reasons, requests may be sent with:
    #     architecture with a '/' in it: use normally
    #     architecture without a '/' and no subarchitecture: assume 'generic'
    #     architecture without a '/' and a subarchitecture: use as specified
    #     architecture with a '/' and a subarchitecture: error
    given_arch = request.data.get('architecture', None)
    given_subarch = request.data.get('subarchitecture', None)
    altered_query_data = request.data.copy()
    if given_arch and '/' in given_arch:
        if given_subarch:
            # Architecture with a '/' and a subarchitecture: error.
            raise ValidationError('Subarchitecture cannot be specified twice.')
        # Architecture with a '/' in it: use normally.
    elif given_arch:
        if given_subarch:
            # Architecture without a '/' and a subarchitecture:
            # use as specified.
            altered_query_data['architecture'] = '/'.join(
                [given_arch, given_subarch])
            del altered_query_data['subarchitecture']
        else:
            # Architecture without a '/' and no subarchitecture:
            # assume 'generic'.
            altered_query_data['architecture'] += '/generic'

    if 'nodegroup' not in altered_query_data:
        # If 'nodegroup' is not explicitely specified, get the origin of the
        # request to figure out which nodegroup the new node should be
        # attached to.
        if request.data.get('autodetect_nodegroup', None) is None:
            # We insist on this to protect command-line API users who
            # are manually enlisting nodes.  You can't use the origin's
            # IP address to indicate in which nodegroup the new node belongs.
            raise ValidationError(
                "'autodetect_nodegroup' must be specified if 'nodegroup' "
                "parameter missing")
        nodegroup = find_nodegroup(request)
        if nodegroup is not None:
            altered_query_data['nodegroup'] = nodegroup

    Form = get_node_create_form(request.user)
    form = Form(data=altered_query_data)
    if form.is_valid():
        node = form.save()
        # Hack in the power parameters here.
        store_node_power_parameters(node, request)
        maaslog.info("%s: Enlisted new node", node.hostname)
        return node
    else:
        raise ValidationError(form.errors)
示例#11
0
 def test_1_managed_interface(self):
     nodegroup = factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS,
         network=IPNetwork("192.168.41.0/24"))
     self.assertEqual(nodegroup,
                      find_nodegroup(get_request('192.168.41.199')))
示例#12
0
 def test_find_nodegroup_returns_None_if_not_found(self):
     self.assertIsNone(
         find_nodegroup(get_request(factory.getRandomIPAddress())))
示例#13
0
 def test_find_nodegroup_looks_up_nodegroup_by_controller_ip(self):
     nodegroup = factory.make_node_group()
     ip = nodegroup.get_managed_interface().ip
     self.assertEqual(nodegroup, find_nodegroup(get_request(ip)))
示例#14
0
 def test_find_nodegroup_accepts_any_ip_in_nodegroup_subnet(self):
     nodegroup = factory.make_node_group(
         network=IPNetwork("192.168.41.0/24"))
     self.assertEqual(
         nodegroup,
         find_nodegroup(get_request('192.168.41.199')))
示例#15
0
文件: api.py 项目: cloudbase/maas
 def read(self, request, version):
     check_version(version)
     nodegroup = find_nodegroup(request)
     return HttpResponse(
         get_enlist_userdata(nodegroup=nodegroup), mimetype="text/plain")
示例#16
0
文件: api.py 项目: cloudbase/maas
 def get_enlist_preseed(self, request, version=None):
     """Render and return a preseed script for enlistment."""
     nodegroup = find_nodegroup(request)
     return HttpResponse(
         get_enlist_preseed(nodegroup=nodegroup), mimetype="text/plain")
示例#17
0
 def test_finds_nodegroup_by_network_address(self):
     nodegroup = factory.make_node_group(
         network=IPNetwork("192.168.28.1/24"))
     self.assertEqual(
         nodegroup,
         find_nodegroup(get_request('192.168.28.0')))