Exemplo n.º 1
0
def _check_machines_exist(provider):
    """Check whether there is a machine associated to a provider or not.
    """
    for machine in Machine.machines(provider.provider_id):
        raise _errors.ProviderError(
            "There are machines associated to the provider (%s)." %
            (provider.provider_id, ))
Exemplo n.º 2
0
def search(provider_id, generic_filters, meta_filters, skip_store):
    """Return information on existing machine(s).
    """
    provider = _retrieve_provider(provider_id)

    if not skip_store:
        if generic_filters or meta_filters:
            raise ConfigurationError(
                "Filters are only supported when the 'skip_store' option "
                "is set.")
        machines = Machine.machines(provider.provider_id)
    else:
        generic_filters, meta_filters = \
           _preprocess_filters(generic_filters, meta_filters)
        manager = provider.get_provider_machine()

        if issubclass(manager, AbstractDatabaseManager):
            meta_filters = {}
            manager = _retrieve_database_manager(provider_id)
        elif issubclass(manager, AbstractMachineManager):
            manager = _retrieve_machine_manager(provider_id)

        machines = manager.search(generic_filters, meta_filters)

    rset = ResultSet(names=('uuid', 'provider_id', 'av_zone', 'addresses'),
                     types=(str, str, str, str))

    for machine in machines:
        row = (str(machine.uuid), machine.provider_id, machine.av_zone,
               machine.addresses)
        rset.append_row(row)
    return CommandResult(None, results=rset)
Exemplo n.º 3
0
    def execute(self,
                provider_id,
                generic_filters=None,
                meta_filters=None,
                skip_store=False):
        """Return information on existing machine(s).

        :param provider_id: Provider's Id.
        :param generic_filters: Filter returned machines by some properites
                                but metadata properties.
        :param meta_filters: Filter returned machines by metadata properties.
        :param skip_store: Proceed anyway if there is no information on
                           the machine in the state store. Default is False.
        """
        rset = ResultSet(names=('uuid', 'provider_id', 'av_zone', 'addresses'),
                         types=(str, str, str, str))

        if not skip_store:
            if generic_filters or meta_filters:
                raise _errors.ConfigurationError(
                    "Filters are only supported when the 'skip_store' option "
                    "is set.")
            provider = _retrieve_provider(provider_id)
            for mc in Machine.machines(provider.provider_id):
                rset.append_row(
                    (str(mc.uuid), mc.provider_id, mc.av_zone, mc.addresses))
        else:
            generic_filters, meta_filters = \
                _preprocess_filters(generic_filters, meta_filters)
            manager = _retrieve_manager(provider_id)
            for mc in manager.search_machines(generic_filters, meta_filters):
                rset.append_row(
                    (str(mc.uuid), mc.provider_id, mc.av_zone, mc.addresses))

        return CommandResult(None, results=rset)
Exemplo n.º 4
0
def _check_machines_exist(provider):
    """Check whether there is a machine associated to a provider or not.
    """
    for machine in Machine.machines(provider.provider_id):
        raise _errors.ProviderError(
            "There are machines associated to the provider (%s)." %
            (provider.provider_id, )
        )
Exemplo n.º 5
0
    def test_machines(self):
        """Check machines created within a provider.
        """
        machine_1 = Machine(uuid=self.uuid_1,
                            provider_id=self.provider.provider_id,
                            av_zone=self.av_zone)
        Machine.add(machine_1)

        machine_2 = Machine(uuid=self.uuid_2,
                            provider_id=self.provider.provider_id,
                            av_zone=self.av_zone)
        Machine.add(machine_2)

        ret = [ isinstance(machine, Machine) for machine in \
            Machine.machines(self.provider.provider_id)
        ]
        self.assertEqual(len(ret), 2)
        self.assertTrue(all(ret))
Exemplo n.º 6
0
def search(provider_id, generic_filters, meta_filters, skip_store):
    """Return information on existing machine(s).
    """
    provider = _retrieve_provider(provider_id)

    if not skip_store:
        if generic_filters or meta_filters:
            raise ConfigurationError(
                "Filters are only supported when the 'skip_store' option "
                "is set."
            )
        machines = Machine.machines(provider.provider_id)
    else:
        generic_filters, meta_filters = \
           _preprocess_filters(generic_filters, meta_filters)
        manager = provider.get_provider_machine()

        if issubclass(manager, AbstractDatabaseManager):
            meta_filters = {}
            manager = _retrieve_database_manager(provider_id)
        elif issubclass(manager, AbstractMachineManager):
            manager = _retrieve_machine_manager(provider_id)

        machines = manager.search(generic_filters, meta_filters)

    rset = ResultSet(
    names=('uuid', 'provider_id', 'av_zone', 'addresses'),
        types=(str, str, str, str)
    )

    for machine in machines:
        row = (
            str(machine.uuid), machine.provider_id, machine.av_zone,
            machine.addresses
        )
        rset.append_row(row)
    return CommandResult(None, results=rset)