Esempio n. 1
0
def main(args_str=None):
    if not args_str:
        args_str = ' '.join(sys.argv[1:])
    args = parse_args(args_str)

    _disc_service = DiscoveryService(args.zk_server_ip)
    _disc_service.master_election("/svc-monitor", os.getpid(),
                                  run_svc_monitor, args)
Esempio n. 2
0
def main(args_str=None):
    if not args_str:
        args_str = ' '.join(sys.argv[1:])
    args = parse_args(args_str)

    _disc_service = DiscoveryService(args.zk_server_ip)
    _disc_service.master_election("/svc-monitor", os.getpid(), run_svc_monitor,
                                  args)
    def __init__(self, zk_server_ip):
        while True:
            try:
                self._zk_client = DiscoveryService(zk_server_ip)
                break
            except gevent.event.Timeout as e:
                pass

        self._subnet_allocators = {}
class VncZkClient(object):
    _SUBNET_PATH = "/api-server/subnets/"

    def __init__(self, zk_server_ip):
        while True:
            try:
                self._zk_client = DiscoveryService(zk_server_ip)
                break
            except gevent.event.Timeout as e:
                pass

        self._subnet_allocators = {}
    # end __init__

    def create_subnet_allocator(self, subnet, first, last):
        # TODO handle subnet resizing change, ignore for now
        if subnet not in self._subnet_allocators:
            self._subnet_allocators[subnet] = IndexAllocator(
                self._zk_client, self._SUBNET_PATH+subnet+'/',
                size=last-first, start_idx=first, reverse=True)
    # end create_subnet_allocator

    def delete_subnet_allocator(self, subnet):
        IndexAllocator.delete_all(self._zk_client,
                                  self._SUBNET_PATH+subnet+'/')
    # end delete_subnet_allocator

    def _get_subnet_allocator(self, subnet):
        return self._subnet_allocators.get(subnet)
    # end _get_subnet_allocator

    def subnet_alloc_req(self, subnet, addr=None):
        allocator = self._get_subnet_allocator(subnet)
        try:
            if addr is not None:
                if allocator.read(addr) is not None:
                    return addr
                else:
                    return allocator.reserve(addr, '')
            else:
                return allocator.alloc('')
        except ResourceExhaustionError:
            return None
    # end subnet_alloc_req

    def subnet_free_req(self, subnet, addr):
        allocator = self._get_subnet_allocator(subnet)
        if allocator:
            allocator.delete(addr)
    # end subnet_free_req

    def create_fq_name_to_uuid_mapping(self, obj_type, fq_name, id):
        fq_name_str = ':'.join(fq_name)
        zk_path = '/fq-name-to-uuid/%s:%s' %(obj_type.replace('-', '_'),
                                             fq_name_str)
        self._zk_client.create_node(zk_path, id)
    # end create_fq_name_to_uuid_mapping

    def fq_name_to_uuid(self, obj_type, fq_name):
        fq_name_str = ':'.join(fq_name)
        zk_path = '/fq-name-to-uuid/%s:%s' %(obj_type.replace('-', '_'),
                                             fq_name_str)

        return self._zk_client.read_node(zk_path)
    # end fq_name_to_uuid

    def delete_fq_name_to_uuid_mapping(self, obj_type, fq_name):
        fq_name_str = ':'.join(fq_name)
        zk_path = '/fq-name-to-uuid/%s:%s' %(obj_type.replace('-', '_'),
                                             fq_name_str)
        self._zk_client.delete_node(zk_path)