def push(server, secret, b): """ Push a blueprint to the secret and its name on the configured server. """ r = http.put('/{0}/{1}'.format(secret, b.name), b.dumps(), {'Content-Type': 'application/json'}, server=server) if 202 == r.status: pass elif 400 == r.status: logging.error('malformed blueprint') return None elif 502 == r.status: logging.error('upstream storage service failed') return None else: logging.error('unexpected {0} storing blueprint'.format(r.status)) return None if b._commit is None and 0 < len(b.sources): logging.warning('blueprint came from standard input - ' 'source tarballs will not be pushed') elif b._commit is not None: tree = git.tree(b._commit) for dirname, filename in sorted(b.sources.iteritems()): blob = git.blob(tree, filename) content = git.content(blob) logging.info('storing source tarballs - this may take a while') r = http.put('/{0}/{1}/{2}'.format(secret, b.name, filename), content, {'Content-Type': 'application/x-tar'}, server=server) if 202 == r.status: pass elif 400 == r.status: logging.error('tarball content or name not expected') return None elif 404 == r.status: logging.error('blueprint not found') return None elif 413 == r.status: logging.error('tarballs can\'t exceed 64MB') return None elif 502 == r.status: logging.error('upstream storage service failed') return None else: logging.error('unexpected {0} storing tarball'. format(r.status)) return None return '{0}/{1}/{2}'.format(server, secret, b.name)
def push(server, secret, b): """ Push a blueprint to the secret and its name on the configured server. """ r = http.put("/{0}/{1}".format(secret, b.name), b.dumps(), {"Content-Type": "application/json"}, server=server) if 202 == r.status: pass elif 400 == r.status: logging.error("malformed blueprint") return None elif 502 == r.status: logging.error("upstream storage service failed") return None else: logging.error("unexpected {0} storing blueprint".format(r.status)) return None tree = git.tree(b._commit) for dirname, filename in sorted(b.sources.iteritems()): blob = git.blob(tree, filename) content = git.content(blob) logging.info("storing source tarballs - this may take a while") r = http.put( "/{0}/{1}/{2}".format(secret, b.name, filename), content, {"Content-Type": "application/x-tar"}, server=server, ) if 202 == r.status: pass elif 400 == r.status: logging.error("tarball content or name not expected") return None elif 404 == r.status: logging.error("blueprint not found") return None elif 413 == r.status: logging.error("tarballs can't exceed 64MB") return None elif 502 == r.status: logging.error("upstream storage service failed") return None else: logging.error("unexpected {0} storing tarball".format(r.status)) return None return "{0}/{1}/{2}".format(server, secret, b.name)
def __request(self, method, url, headers, body, error): """ Launch a request and returns its response :param method: method used ex: POST, GET, DELETE, etc :param url: <IP>:<port>/<path> :param headers: headers used :param body: body in case of POST method :param error: error types :return: response """ headers['X-Auth-Token'] = utils.errorLabel (headers['X-Auth-Token'], error) url = utils.errorUrl(url, error) if error == "GET" or error == "PUT" or error == "POST" or error == "DELETE": method = error if method == "GET": response = http.get(url, headers) elif method == "POST": response = http.post(url, headers, body) elif method == "PUT": response = http.put(url, headers, body) elif method == "DELETE": response = http.delete(url, headers) #utils.printRequest(method,url,headers,body) # show request #utils.printResponse(response) # show response return response
def __update_environment(self, url, environment_payload): headers = { 'X-Auth-Token': self.token, 'Tenant-Id': self.vdc, 'Content-Type': "application/xml" } return http.put(url, headers, environment_payload)
def update_metadata_image(sdc_url, token, vdc, product, metadata_image): """It updates the product metadada for image filtered :param glance_url: the sdc url :param token: the valid token :param metadata_image: image name :param product: image name """ print 'update metadata' print product url = sdc_url+ "/catalog/product/"+product print url headers = {'X-Auth-Token': token, 'Tenant-Id': vdc, 'Accept': "application/json", 'Content-Type': 'application/json'} print headers response = http.get(url, headers) print url if response.status != 200: print 'error to get the product ' + str(response.status) return else: payload = '{"key":"image","value":"' + metadata_image + '"}' print payload response = http.put(url + "/metadatas/image", headers, payload) print response if response.status != 200: print 'error to update the product ' + product \ + ' ' + str(response.status)
def __request(self, method, url, headers, body, error): """ Launch a request and returns its response :param method: method used ex: POST, GET, DELETE, etc :param url: <IP>:<port>/<path> :param headers: headers used :param body: body in case of POST method :param error: error types :return: response """ headers['X-Auth-Token'] = utils.errorLabel(headers['X-Auth-Token'], error) url = utils.errorUrl(url, error) if error == "GET" or error == "PUT" or error == "POST" or error == "DELETE": method = error if method == "GET": response = http.get(url, headers) elif method == "POST": response = http.post(url, headers, body) elif method == "PUT": response = http.put(url, headers, body) elif method == "DELETE": response = http.delete(url, headers) #utils.printRequest(method,url,headers,body) # show request #utils.printResponse(response) # show response return response
def request(method, url, headers, body, error): headers['X-Auth-Token'] = errorLabel(headers['X-Auth-Token'], error) url = errorUrl(url, error) if error == "GET" or error == "PUT" or error == "POST" or error == "DELETE": method = error if method == "GET": response = http.get(url, headers) elif method == "POST": response = http.post(url, headers, body) elif method == "PUT": response = http.put(url, headers, body) elif method == "DELETE": response = http.delete(url, headers) printRequest(method, url, headers, body) #printResponse(response) return response
def _push_postprocessing_wafermap_to_wmds(lot, wafer): # filter all wafermaps that don't have a reference wafermaps_to_upload = filter( lambda wafermap: wafermap.formats.has_key('th01') and wafermap.formats['th01'].reference == None, wafer.wafermaps) logger.debug('Number of wafermaps to upload: %d' % len(wafermaps_to_upload)) for wafermap in wafermaps_to_upload: logger.debug('Starting the upload of %d bytes to %s' % (len(wafermap.formats['th01'].wafermap), WMDS_WEBSERVICE)) resp = requests.put(WMDS_WEBSERVICE, headers={'Content-Type': 'application/octet-stream'}, data=wafermap.formats['th01'].wafermap) logger.debug('Got response %s' % resp) if resp.status_code < 300: logger.debug('Uploaded wafermap %s-%d Postprocessing to the wmds: %s' % (lot.name, int(wafer.number), resp.text)) # the service returns the reference in the body of the put wafermap.formats['th01'].reference = resp.text else: logger.warning('Unable to upload wafermap to the wmds: %d - %s' % (resp.status_code, resp.text)) raise BaseException('Unable to push wafermap to the wmds: %d - %s' % (resp.status_code, resp.text))
def request(method, url, headers, body, error): headers['X-Auth-Token'] = errorLabel (headers['X-Auth-Token'], error) url = errorUrl(url, error) if error == "GET" or error == "PUT" or error == "POST" or error == "DELETE": method = error if method == "GET": response = http.get(url, headers) elif method == "POST": response = http.post(url, headers, body) elif method == "PUT": response = http.put(url, headers, body) elif method == "DELETE": response = http.delete(url, headers) printRequest(method,url,headers,body) #printResponse(response) return response
def __update_tier(self, url, tier_payload): headers = {'X-Auth-Token': self.token, 'Tenant-Id': self.vdc, 'Content-Type': "application/xml"} return http.put(url, headers, tier_payload)
def put_branch(self, sysNam, prjId, brNam, cmd): return http.put(sysNam, '%s/%d/repository/branches/%s/%s' % (self.path, prjId, brNam, cmd), {'id': prjId, 'branch': brNam})