Esempio n. 1
0
 def get_network(self, name=None, id=None):
     if not name and not id or name and id:
         raise ValueError("Either name or id must be set and not both!")
     networks = self.find_networks(name=name, id=id)
     name_or_id = name if name else id
     if not networks:
         raise NotFoundError(
             "Network with name {} not found".format(name_or_id))
     elif len(networks) > 1:
         raise MultipleItemsError(
             "Multiple networks with name {} found".format(name_or_id))
     return networks[0]
Esempio n. 2
0
    def get_template(self, name):
        """
        Find template with name 'name'.

        Raises ImageNotFoundError if no matches found
        Raises MultipleItemsError if multiple matches found
        """
        matches = self.find_templates(name=name)
        if not matches:
            raise ImageNotFoundError('template with name {}'.format(name))
        if len(matches) > 1:
            raise MultipleItemsError('multiple templates with name {}'.format(name))
        return matches[0]
Esempio n. 3
0
    def get_vm(self, vm_name):
        """
        Find VM with name 'name'.

        Raises ImageNotFoundError if no matches found
        Raises MultipleItemsError if multiple matches found
        """
        matches = self.find_vms(name=vm_name)
        if not matches:
            raise VMInstanceNotFound('vm with name {}'.format(vm_name))
        if len(matches) > 1:
            raise MultipleItemsError('multiple VMs with name {}'.format(vm_name))
        return matches[0]
Esempio n. 4
0
    def get_stack(self, name):
        """
        Get single stack if it exists

        Args:
            name: unique name or id of the stack
        Returns:
            CloudFormationStack object
        """
        stacks = self.find_stacks(name)
        if not stacks:
            raise NotFoundError("Stack with name {} not found".format(name))
        elif len(stacks) > 1:
            raise MultipleItemsError(
                "Multiple stacks with name {} found".format(name))
        return stacks[0]
Esempio n. 5
0
    def get_vm(self, name=None, uuid=None):
        """
        Get a single VM by name or ID

        Returns:
            wrapanapi.systems.rhevm.RHEVMVirtualMachine
        Raises:
            MultipleItemsError if multiple VM's found with this name/id
            VMInstanceNotFound if VM not found with this name/id
        """
        matches = self.find_vms(name=name, uuid=uuid)
        if not matches:
            raise VMInstanceNotFound('name={}, id={}'.format(name, uuid))
        if len(matches) > 1:
            raise MultipleItemsError(
                'Found multiple matches for VM with name={}, id={}'.format(
                    name, uuid))
        return matches[0]
Esempio n. 6
0
    def get_template(self, name=None, uuid=None):
        """
        Get a single template by name or ID

        Returns:
            wrapanapi.systems.rhevm.RHEVMTemplate
        Raises:
            MultipleItemsError if multiple templates found with this name/id
            NotFoundError if template not found with this name/id
        """
        matches = self.find_templates(name=name, uuid=uuid)
        if not matches:
            raise NotFoundError('Template with name={}, id={}'.format(
                name, uuid))
        if len(matches) > 1:
            raise MultipleItemsError(
                'Found multiple matches for template with name={}, id={}'.
                format(name, uuid))
        return matches[0]