Esempio n. 1
0
File: zpm.py Progetto: cczona/zpm
def deploy_project(args):
    version = args.auth_version
    conn = _get_zerocloud_conn(args)

    # We can now reset the auth for the web UI, if needed
    if args.no_ui_auth:
        version = '0.0'

    tar = tarfile.open(args.zapp)
    zapp = yaml.safe_load(tar.extractfile('zapp.yaml'))

    path = '%s/%s' % (args.target, os.path.basename(args.zapp))
    container, obj = path.split('/', 1)
    conn.put_object(container, obj, gzip.open(args.zapp).read())

    swift_url = _get_swift_zapp_url(conn.url, path)

    job = _prepare_job(tar, zapp, swift_url)
    path = '%s/%s.json' % (args.target, zapp['meta']['name'])
    container, obj = path.split('/', 1)
    conn.put_object(container, obj, json.dumps(job))

    deploy = {'version': version}
    if version == '0.0':
        deploy['swiftUrl'] = conn.url
    elif version == '1.0':
        deploy['authUrl'] = args.auth
        deploy['username'] = args.user
        deploy['password'] = args.key
    else:
        # TODO(mg): inserting the username and password in the
        # uploaded file makes testing easy, but should not be done in
        # production. See issue #44.
        deploy['authUrl'] = args.os_auth_url
        deploy['tenant'] = args.os_tenant_name
        deploy['username'] = args.os_username
        deploy['password'] = args.os_password
    auth_opts = jinja2.Markup(json.dumps(deploy))
    for path in _find_ui_uploads(zapp, tar):
        # Upload UI files after expanding deployment parameters
        tmpl = jinja2.Template(tar.extractfile(path).read())
        output = tmpl.render(auth_opts=auth_opts)
        container, obj = ('%s/%s' % (args.target, path)).split('/', 1)
        conn.put_object(container, obj, output)

    if args.execute:
        job_details = BytesIO()
        pprint.pprint(job, stream=job_details)
        job_details.seek(0)
        LOG.debug('job template:\n%s' % job_details.read())
        LOG.info('executing')
        conn.post_job(job)

    LOG.info('app deployed to\n  %s/%s/' % (conn.url, args.target))
Esempio n. 2
0
File: zpm.py Progetto: cczona/zpm
def _post_job(url, token, json_data, http_conn=None, response_dict=None):
    # Modelled after swiftclient.client.post_account.
    headers = {'X-Auth-Token': token,
               'Accept': 'application/json',
               'X-Zerovm-Execute': '1.0',
               'Content-Type': 'application/json'}

    if http_conn:
        parsed, conn = http_conn
    else:
        parsed, conn = swiftclient.http_connection(url)

    conn.request('POST', parsed.path, json_data, headers)
    resp = conn.getresponse()
    body = resp.read()
    swiftclient.http_log((url, 'POST'), {'headers': headers}, resp, body)
    swiftclient.store_response(resp, response_dict)

    LOG.debug('response status: %s' % resp.status)
    print(body)