Ejemplo n.º 1
0
 def lookup_pool(self, respool_path):
     request = respool.LookupRequest(path=respool.ResourcePoolPath(
         value=respool_path))
     try:
         resp = self.client.respool_svc.LookupResourcePoolID(
             request,
             metadata=self.client.resmgr_metadata,
             timeout=default_timeout,
         )
         return resp.id.value
     except Exception as e:
         print_fail("Failed to get resource pool by path  %s: %s" %
                    (respool_path, str(e)))
         raise
Ejemplo n.º 2
0
    def ensure_respool(self):
        # lookup respool
        request = respool.LookupRequest(path=respool.ResourcePoolPath(
            value="/" + RESPOOL_PATH))
        resp = self.peloton_client.respool_svc.LookupResourcePoolID(
            request,
            metadata=self.peloton_client.resmgr_metadata,
            timeout=default_timeout,
        )

        respool_id = resp.id.value

        if not respool_id:
            raise ResPoolNotFoundException

        return respool_id
Ejemplo n.º 3
0
    def ensure_exists(self):
        """
        creates a resource pool if it doesn't exist based on the config
        :return: resource pool ID
        """
        respool_name = self.config.respool_config.name
        request = respool.LookupRequest(
            path=respool.ResourcePoolPath(value=RESPOOL_ROOT + respool_name)
        )
        resp = self.client.respool_svc.LookupResourcePoolID(
            request,
            metadata=self.client.resmgr_metadata,
            timeout=self.config.rpc_timeout_sec,
        )
        if resp.id.value is None or resp.id.value == u"":
            request = respool.CreateRequest(config=self.config.respool_config)
            attempts = 0
            while attempts < self.config.max_retry_attempts:
                attempts += 1
                resp = self.client.respool_svc.CreateResourcePool(
                    request,
                    metadata=self.client.resmgr_metadata,
                    timeout=self.config.rpc_timeout_sec,
                )
                if resp.HasField("error"):
                    log.debug(
                        "failed to create respool %s (%s)",
                        respool_name,
                        resp.error,
                    )
                    time.sleep(self.config.sleep_time_sec)
                    continue
                break
            else:
                assert False, resp
            id = resp.result.value
            log.info("created respool %s (%s)", respool_name, id)
        else:
            id = resp.id.value
            log.info("found respool %s (%s)", respool_name, id)

        assert id
        self.id = id
        return self.id
Ejemplo n.º 4
0
    def ensure_exists(self):
        """
        creates a resource pool if it doesn't exist based on the config
        :return: resource pool ID
        """
        respool_name = self.config.respool_config.name
        request = respool.LookupRequest(
            path=respool.ResourcePoolPath(value=RESPOOL_ROOT + respool_name), )
        resp = self.client.respool_svc.LookupResourcePoolID(
            request,
            metadata=self.client.resmgr_metadata,
            timeout=self.config.rpc_timeout_sec,
        )
        if resp.id.value is None or resp.id.value == u'':
            request = respool.CreateRequest(
                config=self.config.respool_config, )
            deadline = time.time() + self.config.rpc_timeout_sec
            while time.time() < deadline:
                resp = self.client.respool_svc.CreateResourcePool(
                    request,
                    metadata=self.client.resmgr_metadata,
                    timeout=self.config.rpc_timeout_sec,
                )
                if resp.HasField('error'):
                    time.sleep(0.5)
                    continue
                break
            else:
                assert False, resp
            id = resp.result.value
            log.info('created respool %s (%s)', respool_name, id)
        else:
            id = resp.id.value
            log.info('found respool %s (%s)', respool_name, id)

        assert id
        self.id = id
        return self.id