def resolve_reference(cls, design_ref): """Resolve a reference to a design document. Locate a schema handler based on the URI scheme of the data reference and use that handler to get the data referenced. :param design_ref: A URI-formatted reference to a data entity """ try: design_uri = urllib.parse.urlparse(design_ref) handler = cls.scheme_handlers.get(design_uri.scheme, None) if handler is None: raise errors.InvalidDesignReference( "Invalid reference scheme %s: no handler." % design_uri.scheme) else: tries = 0 while tries < config_mgr.conf.network.http_client_retries: try: # Have to do a little magic to call the classmethod as a pointer return handler.__get__(None, cls)(design_uri) except Exception as ex: tries = tries + 1 if tries < config_mgr.conf.network.http_client_retries: LOG.debug("Retrying reference after failure: %s" % str(ex)) time.sleep(5**tries) except ValueError: raise errors.InvalidDesignReference( "Cannot resolve design reference %s: unable to parse as valid URI." % design_ref)
def resolve_reference_deckhand(self, design_uri): """Retrieve design documents from Deckhand endpoints. Return a byte array of the design document. Assumes Keystone authentication required. :param design_uri: Tuple as returned by urllib.parse for the design reference """ raise errors.InvalidDesignReference( "Deckhand references not currently supported.")
def resolve_reference(self, design_ref): """Resolve a reference to a design document. Locate a schema handler based on the URI scheme of the design reference and use that handler to get the design document referenced. :param design_ref: A URI-formatted reference to a design document """ try: design_uri = urllib.parse.urlparse(design_ref) handler = self.scheme_handlers.get(design_uri.scheme, None) if handler is None: raise errors.InvalidDesignReference( "Invalid reference scheme %s: no handler." % design_uri.scheme) else: return handler(design_uri) except ValueError: raise errors.InvalidDesignReference( "Cannot resolve design reference %s: unable to parse as valid URI." % design_ref)
def resolve_reference(cls, design_ref): """Resolve a reference to a design document. Locate a schema handler based on the URI scheme of the data reference and use that handler to get the data referenced. :param design_ref: A URI-formatted reference to a data entity """ try: design_uri = urllib.parse.urlparse(design_ref) handler = cls.scheme_handlers.get(design_uri.scheme, None) if handler is None: raise errors.InvalidDesignReference( "Invalid reference scheme %s: no handler." % design_uri.scheme) else: # Have to do a little magic to call the classmethod as a pointer return handler.__get__(None, cls)(design_uri) except ValueError: raise errors.InvalidDesignReference( "Cannot resolve design reference %s: unable to parse as valid URI." % design_ref)
def resolve_reference_ucp(cls, design_uri): """Retrieve artifacts from a Airship service endpoint. Return a byte array of the response content. Assumes Keystone authentication required. :param design_uri: Tuple as returned by urllib.parse for the design reference """ ks_sess = KeystoneUtils.get_session() (new_scheme, foo) = re.subn('^[^+]+\+', '', design_uri.scheme) url = urllib.parse.urlunparse( (new_scheme, design_uri.netloc, design_uri.path, design_uri.params, design_uri.query, design_uri.fragment)) LOG.debug("Calling Keystone session for url %s" % str(url)) resp = ks_sess.get(url, timeout=get_client_timeouts()) if resp.status_code >= 400: raise errors.InvalidDesignReference( "Received error code for reference %s: %s - %s" % (url, str(resp.status_code), resp.text)) return resp.content