def source(dirname, filename, gen_content, url): """ Extract a source tarball. """ if dirname in lut['sources']: s.add('MD5SUM="$(find "{0}" -printf %T@\\\\n | md5sum)"', args=(dirname,)) if url is not None: s.add_list(('curl -o "{0}" "{1}"',), ('wget -O "{0}" "{1}"',), args=(filename, url), operator='||') if '.zip' == pathname[-4:]: s.add('unzip "{0}" -d "{1}"', args=(filename, dirname)) else: s.add('mkdir -p "{1}" && tar xf "{0}" -C "{1}"', args=(filename, dirname)) elif secret is not None: s.add_list(('curl -O "{0}/{1}/{2}/{3}"',), ('wget "{0}/{1}/{2}/{3}"',), args=(server, secret, b.name, filename), operator='||') s.add('mkdir -p "{1}" && tar xf "{0}" -C "{1}"', args=(filename, dirname)) elif gen_content is not None: s.add('mkdir -p "{1}" && tar xf "{0}" -C "{1}"', args=(filename, dirname)) s.add_source(filename, git.blob(tree, filename)) for manager, service in lut['sources'][dirname]: s.add_list(('[ "$MD5SUM" != "$(find "{0}" -printf %T@\\\\n ' '| md5sum)" ]',), ('{1}=1',), args=(dirname, manager.env_var(service)), operator='&&')
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)