from .config import Configurable
from .drivers import drivers
__all__ = ['CloudCollection']


class CloudCollection(Configurable):

    def __init__(self, config, resources=None):
        super(CloudCollection, self).__init__(config)
        self._resources = set(resources) or set()
        self._driver = drivers[self._config['cloud']['type']](self._config)
        for node in self._config['cloud']['nodes']:
            if not node.get('services'):
                node['services'] = self._driver.get_services(node['hosts'][0])

    def __sub__(self, collection):
        self._resources -= collection._resources

    def __and__(self, collection):
        self._resources &= collection._resources

    def __or__(self, collection):
        self._resources |= collection._resources

    def __xor__(self, collection):
        self._resources ^= collection._resources

    def __add__(self, collection):
        self.__or__(collection)

    def __len__(self):
        return len(self._resources)

    def __contains__(self, collection):
        return collection._resources.issubset(self._resources)

    def __iter__(self):
        for resource in self._resources:
            yield type(self)(self._config, [resource])

8c15afae3755b47914d4a3b3f58574b4872cc5c7
<mask token>


class CloudCollection(Configurable):
    <mask token>
    <mask token>
    <mask token>

    def __or__(self, collection):
        self._resources |= collection._resources
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    def __iter__(self):
        for resource in self._resources:
            yield type(self)(self._config, [resource])

<mask token>


class CloudCollection(Configurable):

    def __init__(self, config, resources=None):
        super(CloudCollection, self).__init__(config)
        self._resources = set(resources) or set()
        self._driver = drivers[self._config['cloud']['type']](self._config)
        for node in self._config['cloud']['nodes']:
            if not node.get('services'):
                node['services'] = self._driver.get_services(node['hosts'][0])
    <mask token>
    <mask token>

    def __or__(self, collection):
        self._resources |= collection._resources

    def __xor__(self, collection):
        self._resources ^= collection._resources

    def __add__(self, collection):
        self.__or__(collection)
    <mask token>

    def __contains__(self, collection):
        return collection._resources.issubset(self._resources)

    def __iter__(self):
        for resource in self._resources:
            yield type(self)(self._config, [resource])

<mask token>
__all__ = ['CloudCollection']


class CloudCollection(Configurable):

    def __init__(self, config, resources=None):
        super(CloudCollection, self).__init__(config)
        self._resources = set(resources) or set()
        self._driver = drivers[self._config['cloud']['type']](self._config)
        for node in self._config['cloud']['nodes']:
            if not node.get('services'):
                node['services'] = self._driver.get_services(node['hosts'][0])

    def __sub__(self, collection):
        self._resources -= collection._resources

    def __and__(self, collection):
        self._resources &= collection._resources

    def __or__(self, collection):
        self._resources |= collection._resources

    def __xor__(self, collection):
        self._resources ^= collection._resources

    def __add__(self, collection):
        self.__or__(collection)

    def __len__(self):
        return len(self._resources)

    def __contains__(self, collection):
        return collection._resources.issubset(self._resources)

    def __iter__(self):
        for resource in self._resources:
            yield type(self)(self._config, [resource])

from .config import Configurable
from .drivers import drivers
__all__ = ['CloudCollection']


class CloudCollection(Configurable):

    def __init__(self, config, resources=None):
        super(CloudCollection, self).__init__(config)
        self._resources = set(resources) or set()
        self._driver = drivers[self._config['cloud']['type']](self._config)
        for node in self._config['cloud']['nodes']:
            if not node.get('services'):
                node['services'] = self._driver.get_services(node['hosts'][0])

    def __sub__(self, collection):
        self._resources -= collection._resources

    def __and__(self, collection):
        self._resources &= collection._resources

    def __or__(self, collection):
        self._resources |= collection._resources

    def __xor__(self, collection):
        self._resources ^= collection._resources

    def __add__(self, collection):
        self.__or__(collection)

    def __len__(self):
        return len(self._resources)

    def __contains__(self, collection):
        return collection._resources.issubset(self._resources)

    def __iter__(self):
        for resource in self._resources:
            yield type(self)(self._config, [resource])
