def update_pool_resource(self, pool): try: new_pool = self._clients.octavia().pool_show(pool["id"]) except Exception as e: if getattr(e, "status_code", 400) == 404: raise exceptions.GetResourceNotFound(resource=pool) raise exceptions.GetResourceFailure(resource=pool, err=e) return new_pool
def update_loadbalancer_resource(self, lb): try: new_lb = self.clients("neutron").show_loadbalancer(lb["id"]) except Exception as e: if getattr(e, "status_code", 400) == 404: raise exceptions.GetResourceNotFound(resource=lb) raise exceptions.GetResourceFailure(resource=lb, err=e) return new_lb["loadbalancer"]
def update_loadbalancer_resource(self, lb): try: new_lb = self._clients.octavia().load_balancer_show(lb["id"]) except Exception as e: if getattr(e, "status_code", 400) == 404: raise exceptions.GetResourceNotFound(resource=lb) raise exceptions.GetResourceFailure(resource=lb, err=e) return new_lb
def _get_floating_ip(self, fip_id, do_raise=False): try: fip = self.client.floating_ips.get(fip_id) except nova_exceptions.NotFound: if not do_raise: return None raise exceptions.GetResourceNotFound( resource="Floating IP %s" % fip_id) return fip.id
def get_image(self, image): """Get specified image. :param image: ID or object with ID of image to obtain. """ image_id = getattr(image, "id", image) try: return self._clients.glance("2").images.get(image_id) except glance_exc.HTTPNotFound: raise exceptions.GetResourceNotFound(resource=image)
def _get_from_manager(resource): # catch client side errors try: res = resource.manager.get(resource.id) except Exception as e: if getattr(e, "code", 400) == 404: raise exceptions.GetResourceNotFound(resource=resource) raise exceptions.GetResourceFailure(resource=resource, err=e) # catch abnormal status, such as "no valid host" for servers status = get_status(res) if status in ("DELETED", "DELETE_COMPLETE"): raise exceptions.GetResourceNotFound(resource=res) if status in error_statuses: raise exceptions.GetResourceErrorStatus(resource=res, status=status, fault="") return res
def test_wait_deletion_404(self, mock_time, mock_sleep): # resource manager returns 404, wait_for_status catch and accept that res = mock.MagicMock() notfound = exceptions.GetResourceNotFound(resource=None) upd = mock.MagicMock(side_effect=notfound) ret = utils.wait_for_status(resource=res, ready_statuses=["deleted"], check_deletion=True, update_resource=upd) self.assertIsNone(ret)
def get_image(self, image): """Get specified image. :param image: ID or object with ID of image to obtain. """ image_id = getattr(image, "id", image) try: aname = "glance_v%s.get_image" % self.version with atomic.ActionTimer(self, aname): return self._get_client().images.get(image_id) except glance_exc.HTTPNotFound: raise exceptions.GetResourceNotFound(resource=image)
def _get_access_from_share(self, share, access_id): """Get access from share :param share: :class: `Share` :param access_id: The id of the access we want to get :returns: The access object from the share :raises GetResourceNotFound: if the access is not in the share """ try: return next(access for access in share.access_list() if access.id == access_id) except StopIteration: raise exceptions.GetResourceNotFound(resource=access_id)
def _get_cluster(self, cluster): """Get cluster details. :param cluster: cluster to get :returns: object of cluster """ try: return self.admin_clients("senlin").get_cluster(cluster.id) except Exception as e: if getattr(e, "code", getattr(e, "http_status", 400)) == 404: raise exceptions.GetResourceNotFound(resource=cluster.id) raise exceptions.GetResourceFailure(resource=cluster.id, err=e)
def _get_from_manager(resource): # catch client side errors try: res = resource.manager.get(resource.id) except Exception as e: if getattr(e, 'code', 400) == 404: raise exceptions.GetResourceNotFound(resource=resource) raise exceptions.GetResourceFailure(resource=resource, err=e) # catch abnormal status, such as "no valid host" for servers status = res.status.upper() if status == "DELETED": raise exceptions.GetResourceNotFound(resource=res) if status in error_statuses: if isinstance(res.manager, servers.ServerManager): msg = res.fault['message'] else: msg = '' raise exceptions.GetResourceErrorStatus(resource=res, status=status, fault=msg) return res
def load_balancer_show(self, lb_id): """Show a load balancer :param string lb: dict of the load balancer to show :return: A dict of the specified load balancer's settings """ try: new_lb = self._clients.octavia().load_balancer_show(lb_id) except Exception as e: if getattr(e, "code", 400) == 404: raise exceptions.GetResourceNotFound(resource=lb_id) raise exceptions.GetResourceFailure(resource=lb_id, err=e) return new_lb
def _get_domain_id(self, domain_name_or_id): from keystoneclient import exceptions as kc_exceptions try: # First try to find domain by ID return self._clients.keystone("3").domains.get( domain_name_or_id).id except kc_exceptions.NotFound: # Domain not found by ID, try to find it by name domains = self._clients.keystone("3").domains.list( name=domain_name_or_id) if domains: return domains[0].id # Domain not found by name raise exceptions.GetResourceNotFound( resource="KeystoneDomain(%s)" % domain_name_or_id)
def get_image(self, image): """Gets image. This serves to fetch the latest data on the image for the various wait_for_*() functions. Must raise rally.exceptions.GetResourceNotFound if the resource is not found or deleted. """ # NOTE(stpierre): This function actually has a single # implementation that works for both Glance v1 and Glance v2, # but since we need to use this function in both wrappers, it # gets implemented here. try: return self.client.images.get(image.id) except glance_exc.HTTPNotFound: raise exceptions.GetResourceNotFound(resource=image)
def _update_resource(self, resource): try: manager = getattr(resource, "manager", None) if manager: res = manager.get(resource.id) else: if isinstance(resource, block.Volume): attr = "volumes" elif isinstance(resource, block.VolumeSnapshot): attr = "volume_snapshots" elif isinstance(resource, block.VolumeBackup): attr = "backups" res = getattr(self._get_client(), attr).get(resource.id) except Exception as e: if getattr(e, "code", getattr(e, "http_status", 400)) == 404: raise exceptions.GetResourceNotFound(resource=resource) raise exceptions.GetResourceFailure(resource=resource, err=e) return res
def setup(self): multihost_uuid = self.task["deployment_uuid"] controller_name = self.config["controller"] multihost_info = get_ovn_multihost_info(multihost_uuid, controller_name) self.context["ovn_multihost"] = multihost_info try: controller_dep = db.deployment_get(controller_name) except exceptions.DeploymentNotFound: raise try: res = db.resource_get_all(controller_dep["uuid"], type=ResourceType.CONTROLLER)[0] except: raise exceptions.GetResourceNotFound(resource="controller") self.context["controller"] = res["info"]
def get_fip(*args, **kwargs): for i in fip_found: return "fip_id" raise exceptions.GetResourceNotFound(resource="")
def _update_image(self, image): try: return self.get_image(image) except glance_exc.HTTPNotFound: raise exceptions.GetResourceNotFound(resource=image)
def update_resource(self): raise exceptions.GetResourceNotFound(resource=None)
def _get_image(self, image): try: return self.client.images.get(image.id) except glance_exc.HTTPNotFound: raise exceptions.GetResourceNotFound(resource=image)