示例#1
0
文件: test_pods.py 项目: sfeole/maas
 def test_updates_existing_pod_minimal(self):
     self.fake_pod_discovery()
     zone = factory.make_Zone()
     pool = factory.make_ResourcePool()
     cpu_over_commit = random.randint(0, 10)
     memory_over_commit = random.randint(0, 10)
     power_parameters = {
         'power_address': 'qemu+ssh://1.2.3.4/system',
         'power_pass': '******',
     }
     orig_pod = factory.make_Pod(
         pod_type='virsh', zone=zone, pool=pool,
         cpu_over_commit_ratio=cpu_over_commit,
         memory_over_commit_ratio=memory_over_commit,
         parameters=power_parameters)
     new_name = factory.make_name("pod")
     form = PodForm(
         data={'name': new_name}, request=self.request, instance=orig_pod)
     self.assertTrue(form.is_valid(), form._errors)
     pod = form.save()
     self.assertEqual(new_name, pod.name)
     self.assertEqual(zone, pod.zone)
     self.assertEqual(pool, pod.pool)
     self.assertEqual(cpu_over_commit, pod.cpu_over_commit_ratio)
     self.assertEqual(memory_over_commit, pod.memory_over_commit_ratio)
     self.assertEqual(memory_over_commit, pod.memory_over_commit_ratio)
     self.assertEqual(power_parameters, pod.power_parameters)
示例#2
0
 def test_creates_pod_with_name(self):
     discovered_pod, discovered_racks, failed_racks = (
         self.fake_pod_discovery())
     zone = factory.make_Zone()
     pod_info = self.make_pod_info()
     pod_info['zone'] = zone.name
     request = MagicMock()
     request.user = factory.make_User()
     pod_name = factory.make_name('pod')
     pod_info['name'] = pod_name
     form = PodForm(data=pod_info, request=request)
     self.assertTrue(form.is_valid(), form._errors)
     pod = form.save()
     self.assertThat(
         pod,
         MatchesStructure(
             architectures=Equals(['amd64/generic']),
             name=Equals(pod_name),
             cores=Equals(discovered_pod.cores),
             memory=Equals(discovered_pod.memory),
             cpu_speed=Equals(discovered_pod.cpu_speed),
             zone=Equals(zone),
             power_type=Equals(pod_info['type']),
             power_parameters=Equals({
                 'power_address':
                 pod_info['power_address'],
                 'power_pass':
                 pod_info['power_pass'],
                 'default_storage_pool':
                 pod_info['default_storage_pool'],
             }),
             ip_address=MatchesStructure(ip=Equals(pod_info['ip_address'])),
         ))
示例#3
0
 def test_discover_and_sync_existing_pod(self):
     discovered_pod, discovered_racks, failed_racks = (
         self.fake_pod_discovery())
     pod_info = self.make_pod_info()
     orig_pod = factory.make_Pod(pod_type=pod_info['type'])
     request = MagicMock()
     request.user = factory.make_User()
     form = PodForm(data=pod_info, request=request, instance=orig_pod)
     pod = form.discover_and_sync_pod()
     self.assertThat(
         pod,
         MatchesStructure(
             id=Equals(orig_pod.id),
             bmc_type=Equals(BMC_TYPE.POD),
             architectures=Equals(['amd64/generic']),
             name=Equals(orig_pod.name),
             cores=Equals(discovered_pod.cores),
             memory=Equals(discovered_pod.memory),
             cpu_speed=Equals(discovered_pod.cpu_speed),
             power_type=Equals(pod_info['type']),
             power_parameters=Equals({}),
             ip_address=Is(None),
         ))
     routable_racks = [
         relation.rack_controller
         for relation in pod.routable_rack_relationships.all()
         if relation.routable
     ]
     not_routable_racks = [
         relation.rack_controller
         for relation in pod.routable_rack_relationships.all()
         if not relation.routable
     ]
     self.assertItemsEqual(routable_racks, discovered_racks)
     self.assertItemsEqual(not_routable_racks, failed_racks)
示例#4
0
文件: pods.py 项目: zeronewb/maas
    def create(self, request):
        """Create a Pod.

        :param type: Type of pod to create (rsd, virsh) (required).
        :type name: unicode
        :param power_address: Address for power control of the pod (required).
        :type power_address: unicode
        :param power_user: User for power control of the pod
            (required for rsd).
        :type power_user: unicode
        :param power_pass: Password for power control of the pod
            (required for rsd).
        :type power_pass: unicode
        :param name: Name for the pod (optional).
        :type name: unicode
        :param zone: Name of the zone for the pod (optional).
        :type zone: unicode
        :param pool: Name of resource pool this pod belongs and that
            composed machines get assigned to by default (optional).
        :type pool: unicode
        :param tags: A tag or tags (separated by comma) for the pod (optional).
        :type tags: unicode

        Returns 503 if the pod could not be discovered.
        Returns 404 if the pod is not found.
        Returns 403 if the user does not have permission to create a pod.
        """
        form = PodForm(data=request.data, request=request)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
示例#5
0
文件: pods.py 项目: pingli-study/maas
    def refresh(self, request, id):
        """@description-title Refresh a pod
        @description Performs pod discovery and updates all discovered
        information and discovered machines.

        @param (int) "{id}" [required=false] The pod's ID.

        @success (json) "success-json" A pod JSON object.
        @success-example "success-json" [exkey=refresh-pod] placeholder text

        @error (http-status-code) "404" 404
        @error (content) "not-found" No pod with that ID can be found.
        @error-example "not-found"
            Not Found

        @error (http-status-code) "403" 403
        @error (content) "no-perms" The user does not have the permissions
        to delete the pod.
        @error-example (content) "no-perms"
            This method is reserved for admin users.
        """
        pod = Pod.objects.get_pod_or_404(id, request.user, PodPermission.edit)
        form = PodForm(data=request.data, instance=pod, request=request)
        pod = form.discover_and_sync_pod()
        return pod
示例#6
0
 def get_form(params):
     request = HttpRequest()
     request.user = self.user
     form = PodForm(data=params, request=request)
     if not form.is_valid():
         raise HandlerValidationError(form.errors)
     else:
         return form
示例#7
0
 def test_raises_unable_to_discover_because_no_racks(self):
     self.patch(pods_module, "discover_pod").return_value = ({}, {})
     form = PodForm(data=self.make_pod_info())
     self.assertTrue(form.is_valid(), form._errors)
     error = self.assertRaises(PodProblem, form.save)
     self.assertEquals(
         "Unable to start the pod discovery process. "
         "No rack controllers connected.", str(error))
示例#8
0
    def create(self, request):
        """@description-title Create a VM host
        @description Create or discover a new VM host.

        @param (string) "type" [required=true] The type of VM host to create:
        ``lxd`` or ``virsh``.
        @param (string) "power_address" [required=true] Address that gives
        MAAS access to the VM host power control. For example, for virsh
        ``qemu+ssh://172.16.99.2/system``
        For ``lxd``, this is just the address of the host.
        @param (string) "power_user" [required=true] Username to use for
        power control of the VM host. Required for ``virsh``
        VM hosts that do not have SSH set up for public-key authentication.
        @param (string) "power_pass" [required=true] Password to use for
        power control of the VM host. Required ``virsh`` VM hosts that do
        not have SSH set up for public-key authentication and for ``lxd``
        if the MAAS certificate is not registered already in the LXD server.
        @param (string) "name" [required=false] The new VM host's name.
        @param (string) "zone" [required=false] The new VM host's zone.
        @param (string) "pool" [required=false] The name of the resource
        pool the new VM host will belong to. Machines composed from this VM host
        will be assigned to this resource pool by default.
        @param (string) "tags" [required=false] A tag or list of tags (
        comma delimited) to assign to the new VM host.
        @param (string) "project" [required=false] For ``lxd`` VM hosts, the
        project that MAAS will manage. If not provided, the ``default`` project
        will be used. If a nonexistent name is given, a new project with that
        name will be created.

        @success (http-status-code) "200" 200
        @success (json) "success-json" A JSON object containing a VM host object.
        @success-example (json) "success-json" [exkey=create] placeholder text

        @error (http-status-code) "404" 404
        @error (content) "not-found" No VM host with that ID can be found.
        @error-example "not-found"
            Not Found

        @error (http-status-code) "403" 403
        @error (content) "no-perms" The user does not have the permissions
        to delete the VM host.
        @error-example (content) "no-perms"
            This method is reserved for admin users.

        @error (http-status-code) "503" 503
        @error (content) "failed-login" MAAS could not find or could not
            authenticate with the VM host.
        @error-example (content) "failed-login"
            Failed talking to VM host: Failed to authenticate to the VM host.

        """
        if not request.user.has_perm(PodPermission.create):
            raise PermissionDenied()
        form = PodForm(data=request.data, request=request)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
示例#9
0
文件: test_pods.py 项目: sfeole/maas
 def test_creates_pod_with_zone(self):
     self.fake_pod_discovery()
     pod_info = self.make_pod_info()
     zone = factory.make_Zone()
     pod_info['zone'] = zone.name
     form = PodForm(data=pod_info, request=self.request)
     self.assertTrue(form.is_valid(), form._errors)
     pod = form.save()
     self.assertEqual(zone.id, pod.zone.id)
示例#10
0
文件: test_pods.py 项目: sfeole/maas
 def test_creates_pod_with_pool(self):
     self.fake_pod_discovery()
     pod_info = self.make_pod_info()
     pool = factory.make_ResourcePool()
     pod_info['pool'] = pool.name
     form = PodForm(data=pod_info, request=self.request)
     self.assertTrue(form.is_valid(), form._errors)
     pod = form.save()
     self.assertEqual(pool.id, pod.pool.id)
示例#11
0
文件: test_pods.py 项目: sfeole/maas
 def test_creates_pod_with_tags(self):
     self.fake_pod_discovery()
     pod_info = self.make_pod_info()
     tags = [factory.make_name('tag'), factory.make_name('tag')]
     pod_info['tags'] = ','.join(tags)
     form = PodForm(data=pod_info, request=self.request)
     self.assertTrue(form.is_valid(), form._errors)
     pod = form.save()
     self.assertItemsEqual(tags, pod.tags)
示例#12
0
文件: test_pods.py 项目: sfeole/maas
 def test_creates_pod_with_name(self):
     self.fake_pod_discovery()
     pod_info = self.make_pod_info()
     pod_name = factory.make_name('pod')
     pod_info['name'] = pod_name
     form = PodForm(data=pod_info, request=self.request)
     self.assertTrue(form.is_valid(), form._errors)
     pod = form.save()
     self.assertEqual(pod_name, pod.name)
示例#13
0
 def get_form(params):
     obj = self.get_object(params)
     request = HttpRequest()
     request.user = self.user
     form = PodForm(instance=obj, data=params, request=request)
     if not form.is_valid():
         raise HandlerValidationError(form.errors)
     else:
         form.cleaned_data['tags'] = params['tags']
         return form
示例#14
0
文件: test_pods.py 项目: sfeole/maas
 def test_raises_exception_from_rack_controller(self):
     failed_rack = factory.make_RackController()
     exc = factory.make_exception()
     self.patch(pods_module, "discover_pod").return_value = ({}, {
         failed_rack.system_id: exc,
     })
     pod_info = self.make_pod_info()
     form = PodForm(data=pod_info)
     self.assertTrue(form.is_valid(), form._errors)
     error = self.assertRaises(PodProblem, form.save)
     self.assertEquals(str(exc), str(error))
示例#15
0
文件: test_pods.py 项目: sfeole/maas
 def test_creates_pod_with_power_parameters(self):
     self.fake_pod_discovery()
     pod_info = self.make_pod_info()
     pod_info['power_pass'] = factory.make_name('pass')
     form = PodForm(data=pod_info, request=self.request)
     self.assertTrue(form.is_valid(), form._errors)
     pod = form.save()
     self.assertEqual(
         pod_info['power_address'], pod.power_parameters['power_address'])
     self.assertEqual(
         pod_info['power_pass'], pod.power_parameters['power_pass'])
示例#16
0
文件: test_pods.py 项目: sfeole/maas
 def test_creates_pod_with_overcommit(self):
     self.fake_pod_discovery()
     pod_info = self.make_pod_info()
     pod_info['cpu_over_commit_ratio'] = random.randint(0, 10)
     pod_info['memory_over_commit_ratio'] = random.randint(0, 10)
     form = PodForm(data=pod_info, request=self.request)
     self.assertTrue(form.is_valid(), form._errors)
     pod = form.save()
     self.assertEqual(
         pod_info['cpu_over_commit_ratio'], pod.cpu_over_commit_ratio)
     self.assertEqual(
         pod_info['memory_over_commit_ratio'], pod.memory_over_commit_ratio)
示例#17
0
文件: pods.py 项目: zeronewb/maas
    def refresh(self, request, id):
        """Refresh a specific Pod.

        Performs pod discovery and updates all discovered information and
        discovered machines.

        Returns 404 if the pod is not found.
        Returns 403 if the user does not have permission to refresh the pod.
        """
        pod = get_object_or_404(Pod, id=id)
        form = PodForm(data=request.data, instance=pod, request=request)
        pod = form.discover_and_sync_pod()
        return pod
示例#18
0
文件: pods.py 项目: pingli-study/maas
    def create(self, request):
        """@description-title Create a pod
        @description Create or discover a new pod.

        @param (string) "type" [required=true] The type of pod to create:
        ``rsd`` or ``virsh``.
        @param (string) "power_address" [required=true] Address that gives
        MAAS access to the pod's power control. For example:
        ``qemu+ssh://172.16.99.2/system``.
        @param (string) "power_user" [required=true] Username to use for
        power control of the pod. Required for ``rsd`` pods or ``virsh``
        pods that do not have SSH set up for public-key authentication.
        @param (string) "power_pass" [required=true] Password to use for
        power control of the pod. Required for ``rsd`` pods or ``virsh``
        pods that do not have SSH set up for public-key authentication.
        @param (string) "name" [required=false] The new pod's name.
        @param (string) "zone" [required=false] The new pod's zone.
        @param (string) "pool" [required=false] The name of the resource
        pool the new pod will belong to. Machines composed from this pod
        will be assigned to this resource pool by default.
        @param (string) "tags" [required=false] A tag or list of tags (
        comma delimited) to assign to the new pod.

        @success (http-status-code) "200" 200
        @success (json) "success-json" A JSON object containing a pod object.
        @success-example (json) "success-json" [exkey=create] placeholder text

        @error (http-status-code) "404" 404
        @error (content) "not-found" No pod with that ID can be found.
        @error-example "not-found"
            Not Found

        @error (http-status-code) "403" 403
        @error (content) "no-perms" The user does not have the permissions
        to delete the pod.
        @error-example (content) "no-perms"
            This method is reserved for admin users.

        @error (http-status-code) "503" 503
        @error (content) "failed-login" MAAS could not find the RSD
        pod or could not log into the virsh console.
        @error-example (content) "failed-login"
            Failed talking to pod: Failed to login to virsh console.
        """
        if not request.user.has_perm(PodPermission.create):
            raise PermissionDenied()
        form = PodForm(data=request.data, request=request)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
示例#19
0
文件: test_pods.py 项目: sfeole/maas
 def test_takes_over_bmc_with_pod(self):
     discovered_pod, _, _ = self.fake_pod_discovery()
     pod_info = self.make_pod_info()
     bmc = factory.make_BMC(
         power_type=pod_info['type'],
         power_parameters={
             'power_address': pod_info['power_address'],
             'power_pass': '',
         })
     form = PodForm(data=pod_info, request=self.request)
     self.assertTrue(form.is_valid(), form._errors)
     pod = form.save()
     self.assertEquals(bmc.id, pod.id)
     self.assertEquals(BMC_TYPE.POD, reload_object(bmc).bmc_type)
示例#20
0
    def update(self, request, id):
        """@description-title Update a specific pod
        @description Update a specific pod by ID.

        Note: A pod's 'type' cannot be updated. The pod must be deleted and
        re-added to change the type.

        @param (url-string) "{id}" [required=true] The pod's ID.
        @param (string) "name" [required=false] The pod's name.
        @param (string) "pool" [required=false] The name of the resource pool
        associated with this pod -- composed machines will be assigned to this
        resource pool by default.
        @param (int) "cpu_over_commit_ratio" [required=false] CPU overcommit
        ratio (1-10)
        @param (int) "memory_over_commit_ratio" [required=false] CPU overcommit
        ratio (1-10)
        @param (string) "default_storage_pool" [required=false] Default KVM
        storage pool to use when the pod has storage pools.
        @param (string) "power_address" [required=false] Address for power
        control of the pod.
        @param-example "power_address"
        ``Virsh: qemu+ssh://172.16.99.2/system``
        @param (string) "power_pass" [required=false] Password for access to
        power control of the pod.
        @param (string) "zone" [required=false] The pod's zone.
        @param (string) "default_macvlan_mode" [required=false] Default macvlan
        mode for pods that use it: bridge, passthru, private, vepa.
        @param (string) "tags" [required=false] Tag or tags (command separated)
        associated with the pod.
        @param (boolean) "console_log" [required=false] If 'True', VMs composed
        in this pod will have console output logged (Note: this will
        automatically create a tag named 'pod-console-logging' and apply it to
        the pod). If 'False', MAAS deletes the 'pod-console-logging' tag, if
        any, which turns off console logging.

        @success (http-status-code) "200" 200
        @success (json) "success-json" A JSON pod object.
        @success-example "success-json" [exkey=update-pod] placeholder text

        @error (http-status-code) "404" 404 -- The pod's ID was not found.
        @error (http-status-code) "403" 403 -- The current user does not have
        permission to update the pod.
        """
        pod = Pod.objects.get_pod_or_404(id, request.user, PodPermission.edit)
        form = PodForm(data=request.data, instance=pod, request=request)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
示例#21
0
    def create(self, request):
        """Create a Pod.

        :param type: Type of pod to create (rsd, virsh).
        :param name: Name for the pod (optional).

        Returns 503 if the pod could not be discovered.
        Returns 404 if the pod is not found.
        Returns 403 if the user does not have permission to create a pod.
        """
        form = PodForm(data=request.data, request=request)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
示例#22
0
        def get_form(params):
            # Clear rbac cache before check (this is in its own thread).
            rbac.clear()

            if not self.user.has_perm(self._meta.create_permission):
                raise HandlerPermissionError()

            request = HttpRequest()
            request.user = self.user
            form = PodForm(
                data=self.preprocess_form("create", params), request=request)
            if not form.is_valid():
                raise HandlerValidationError(form.errors)
            else:
                return form
示例#23
0
def _create_pod_for_deployment(node):
    virsh_password_meta = NodeMetadata.objects.filter(
        node=node, key="virsh_password"
    ).first()
    if virsh_password_meta is None:
        node.mark_failed(
            comment="Failed to deploy KVM: Password not found.", commit=False
        )
    else:
        virsh_password = virsh_password_meta.value
        virsh_password_meta.delete()
        # XXX: Should find the best IP to communicate with, given what the rack
        # controller can access, or use the boot interface IP address.
        ip = node.ip_addresses()[0]
        if ":" in ip:
            ip = "[%s]" % ip
        power_address = "qemu+ssh://virsh@%s/system" % ip
        pod_form = PodForm(
            data=dict(
                type="virsh",
                name=node.hostname,
                power_address=power_address,
                power_pass=virsh_password,
                zone=node.zone.name,
                pool=node.pool.name,
            ),
            user=node.owner,
        )
        if pod_form.is_valid():
            try:
                pod_form.save()
            except DatabaseError:
                # Re-raise database errors, since we want it to be
                # retried if possible. If it's not retriable, we
                # couldn't mark the node as failed anyway, since the
                # transaction will be broken.
                # XXX: We should refactor the processing of messages so
                # that the node is marked failed/deployed in a seperate
                # transaction than the one doing the processing.
                raise
            except Exception:
                node.mark_failed(comment=POD_CREATION_ERROR, commit=False)
                log.err(None, "Exception while saving pod form.")
            else:
                node.status = NODE_STATUS.DEPLOYED
        else:
            node.mark_failed(comment=POD_CREATION_ERROR, commit=False)
            log.msg("Error while creating KVM pod: %s" % dict(pod_form.errors))
示例#24
0
 def test_updates_existing_pod(self):
     discovered_pod, discovered_racks, failed_racks = (
         self.fake_pod_discovery())
     zone = factory.make_Zone()
     pod_info = self.make_pod_info()
     pod_info['zone'] = zone.name
     orig_pod = factory.make_Pod(pod_type=pod_info['type'])
     new_name = factory.make_name("pod")
     pod_info['name'] = new_name
     request = MagicMock()
     request.user = factory.make_User()
     form = PodForm(data=pod_info, request=request, instance=orig_pod)
     self.assertTrue(form.is_valid(), form._errors)
     pod = form.save()
     self.assertThat(
         pod,
         MatchesStructure(
             id=Equals(orig_pod.id),
             bmc_type=Equals(BMC_TYPE.POD),
             architectures=Equals(['amd64/generic']),
             name=Equals(new_name),
             cores=Equals(discovered_pod.cores),
             memory=Equals(discovered_pod.memory),
             cpu_speed=Equals(discovered_pod.cpu_speed),
             zone=Equals(zone),
             power_type=Equals(pod_info['type']),
             power_parameters=Equals({
                 'power_address':
                 pod_info['power_address'],
                 'power_pass':
                 pod_info['power_pass'],
                 'default_storage_pool':
                 pod_info['default_storage_pool'],
             }),
             ip_address=MatchesStructure(ip=Equals(pod_info['ip_address'])),
         ))
     routable_racks = [
         relation.rack_controller
         for relation in pod.routable_rack_relationships.all()
         if relation.routable
     ]
     not_routable_racks = [
         relation.rack_controller
         for relation in pod.routable_rack_relationships.all()
         if not relation.routable
     ]
     self.assertItemsEqual(routable_racks, discovered_racks)
     self.assertItemsEqual(not_routable_racks, failed_racks)
示例#25
0
文件: test_pods.py 项目: sfeole/maas
 def test_updates_default_storage_pool(self):
     discovered_pod, _, _ = (
         self.fake_pod_discovery())
     default_storage_pool = random.choice(discovered_pod.storage_pools)
     pod = factory.make_Pod(pod_type='virsh')
     pod.sync(discovered_pod, self.request.user)
     form = PodForm(data={
         'default_storage_pool': default_storage_pool.id,
         'power_address': 'qemu:///system',
     }, request=self.request, instance=pod)
     self.assertTrue(form.is_valid(), form._errors)
     pod = form.save()
     self.assertThat(pod, MatchesStructure(
         default_storage_pool=MatchesStructure(
             pool_id=Equals(default_storage_pool.id)),
     ))
示例#26
0
文件: test_pods.py 项目: sfeole/maas
 def test_prevents_duplicate_pod(self):
     discovered_pod, _, _ = self.fake_pod_discovery()
     pod_info = self.make_pod_info()
     form = PodForm(data=pod_info, request=self.request)
     self.assertTrue(form.is_valid(), form._errors)
     form.save()
     new_form = PodForm(data=pod_info)
     self.assertTrue(new_form.is_valid(), form._errors)
     self.assertRaises(ValidationError, new_form.save)
示例#27
0
    def update(self, request, id):
        """Update a specific Pod.

        :param name: Name for the pod (optional).

        Note: 'type' cannot be updated on a Pod. The Pod must be deleted and
        re-added to change the type.

        Returns 404 if the pod is not found.
        Returns 403 if the user does not have permission to update the pod.
        """
        pod = get_object_or_404(Pod, id=id)
        form = PodForm(data=request.data, instance=pod, request=request)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
示例#28
0
    def update(self, request, id):
        """@description-title Update a specific VM host
        @description Update a specific VM host by ID.

        Note: A VM host's 'type' cannot be updated. The VM host must be deleted
        and re-added to change the type.

        @param (url-string) "{id}" [required=true] The VM host's ID.
        @param (string) "name" [required=false] The VM host's name.
        @param (string) "pool" [required=false] The name of the resource pool
        associated with this VM host -- composed machines will be assigned to this
        resource pool by default.
        @param (int) "cpu_over_commit_ratio" [required=false] CPU overcommit
        ratio (0-10)
        @param (int) "memory_over_commit_ratio" [required=false] CPU overcommit
        ratio (0-10)
        @param (string) "default_storage_pool" [required=false] Default KVM
        storage pool to use when the VM host has storage pools.
        @param (string) "power_address" [required=false] Address for power
        control of the VM host.
        @param-example "power_address"
        ``Virsh: qemu+ssh://172.16.99.2/system``
        @param (string) "power_pass" [required=false] Password for access to
        power control of the VM host.
        @param (string) "zone" [required=false] The VM host's zone.
        @param (string) "default_macvlan_mode" [required=false] Default macvlan
        mode for VM hosts that use it: bridge, passthru, private, vepa.
        @param (string) "tags" [required=false] Tag or tags (command separated)
        associated with the VM host.

        @success (http-status-code) "200" 200
        @success (json) "success-json" A JSON VM host object.
        @success-example "success-json" [exkey=update-vmhost] placeholder text

        @error (http-status-code) "404" 404 -- The VM host's ID was not found.
        @error (http-status-code) "403" 403 -- The current user does not have
        permission to update the VM host.

        """
        pod = Pod.objects.get_pod_or_404(id, request.user, PodPermission.edit)
        form = PodForm(data=request.data, instance=pod, request=request)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)
示例#29
0
        def get_form(params):
            # Clear rbac cache before check (this is in its own thread).
            rbac.clear()

            obj = self.get_object(params)
            if not self.user.has_perm(self._meta.edit_permission, obj):
                raise HandlerPermissionError()

            request = HttpRequest()
            request.user = self.user
            form = PodForm(
                instance=obj, data=self.preprocess_form("update", params),
                request=request)
            if not form.is_valid():
                raise HandlerValidationError(form.errors)
            else:
                form.cleaned_data['tags'] = params['tags']
                return form
示例#30
0
    def update(self, request, id):
        """Update a specific Pod.

        :param name: Name for the pod
        :type name: unicode
        :param pool: Name of resource pool this pod belongs and that
            composed machines get assigned to by default.
        :type pool: unicode
        :param cpu_over_commit_ratio: CPU overcommit ratio
        :type cpu_over_commit_ratio: unicode
        :param memory_over_commit_ratio: Memory overcommit ratio
        :type memory_over_commit_ratio: unicode
        :param default_storage_pool: Default storage pool (used when pod has
            storage pools).
        :type default_storage_pool: unicode
        :param power_address: Address for power control of the pod
        :type power_address: unicode
        :param power_pass: Password for power control of the pod
        :type power_pass: unicode
        :param zone: Name of the zone for the pod
        :type zone: unicode
        :param default_macvlan_mode: Default macvlan mode (bridge, passthru,
           private, vepa) for the pod.
        :type default_macvlan_mode: unicode
        :param tags: A tag or tags (separated by comma) for the pod.
        :type tags: unicode
        :param console_log: If True, created VMs for this pod will have
            their console output logged.  To do this, a tag with the name
            'pod-console-logging' is created.  If False, it checks to see if
            this tag already exists and deletes it if it does.
        :type console_log: boolean

        Note: 'type' cannot be updated on a Pod. The Pod must be deleted and
        re-added to change the type.

        Returns 404 if the pod is not found.
        Returns 403 if the user does not have permission to update the pod.
        """
        pod = get_object_or_404(Pod, id=id)
        form = PodForm(data=request.data, instance=pod, request=request)
        if form.is_valid():
            return form.save()
        else:
            raise MAASAPIValidationError(form.errors)