コード例 #1
0
ファイル: openstack.py プロジェクト: sbulage/wrapanapi
    def get_vm(self, name=None, id=None, ip=None):
        """
        Get a VM based on name, or ID, or IP

        Passes args to find_vms to search for matches

        Args:
            name (str)
            id (str)
            ip (str)

        Returns:
            single OpenstackInstance object

        Raises:
            VMInstanceNotFound -- vm not found
            MultipleInstancesError -- more than 1 vm found
        """
        # Store the kwargs used for the exception msg's
        kwargs = {'name': name, 'id': id, 'ip': ip}
        kwargs = {key: val for key, val in kwargs.items() if val is not None}

        matches = self.find_vms(**kwargs)
        if not matches:
            raise VMInstanceNotFound('match criteria: {}'.format(kwargs))
        elif len(matches) > 1:
            raise MultipleInstancesError('match criteria: {}'.format(kwargs))
        return matches[0]
コード例 #2
0
ファイル: google.py プロジェクト: tkhamis/wrapanapi
    def get_vm(self, name, zone=None, try_all_zones=False):
        """
        Get a single VM with given name in a specified zone

        By default self._zone is used

        Args:
            name: name of VM
            zone: zone to get VM from, defaults to self._zone
            try_all_zones: if VM not found in 'zone', then continue to look for it
                in all other zones
        Returns:
            GCEInstance object
        Raises:
            VMInstanceNotFound if unable to find vm
            MultipleInstancesError if multiple vm's with the same name found
        """
        if not zone:
            zone = self._zone
        instances = self.find_vms(name, zones=[zone])
        if not instances and try_all_zones:
            self.logger.info("Looking for instance '%s' in all zones", name)
            instances = self.find_vms(name, zones=None)
        if not instances:
            raise VMInstanceNotFound(name)
        elif len(instances) > 1:
            raise MultipleInstancesError(name)
        return instances[0]
コード例 #3
0
    def get_vm(self, name, hide_deleted=True):
        """
        Get a single EC2Instance with name or id equal to 'name'

        Must be a unique name

        Args:
            name: name or id of instance
        Returns:
            EC2Instance object
        Raises:
            VMInstanceNotFound if no instance exists with this name/id
            MultipleInstancesError if name is not unique
        """
        instances = self.find_vms(name=name, hide_deleted=hide_deleted)
        if not instances:
            raise VMInstanceNotFound(name)
        elif len(instances) > 1:
            raise MultipleInstancesError('Instance name "%s" is not unique' %
                                         name)
        return instances[0]