Пример #1
0
def do_step(context):

    settings = context.meta['settings']
    username = settings["username"]
    home_dir = os.path.join("/home", username)
    index_file = context.meta['index-file']

    client = bosh_client.BoshClient("https://10.0.0.4:25555", "admin", "admin")
    bosh_uuid = client.get_info()['uuid']

    print "Director uuid is {0}".format(bosh_uuid)

    f = open("manifests/{0}".format(index_file))
    manifests = yaml.safe_load(f)
    f.close()

    # set the director id on the manifests
    for m in manifests['manifests']:
        with open("{0}/manifests/{1}".format(home_dir, m['file']), 'r+') as f:

            contents = f.read()
            template = Template(contents)
            contents = template.render(DIRECTOR_UUID=bosh_uuid)

            f.seek(0)
            f.write(contents)
            f.truncate()
            f.close()

    return context
Пример #2
0
def do_step(context):
    settings = context.meta['settings']
    username = settings["username"]
    home_dir = os.path.join("/home", username)
    index_file = context.meta['index-file']

    f = open("manifests/{0}".format(index_file))
    manifests = yaml.safe_load(f)
    f.close()

    client = bosh_client.BoshClient("https://10.0.0.4:25555", "admin", "admin")

    # deploy!
    for m in manifests['manifests']:
        print "Deploying {0}/manifests/{1}...".format(home_dir, m['file'])

        manifest = open("{0}/manifests/{1}".format(home_dir, m['file'])).read()
        task_id = client.create_deployment(manifest)

        task = client.wait_for_task(task_id)

        retries = 0

        while task['state'] == 'error' and retries < 5:

            retries += 1

            print "Retrying deploy for {0}/manifests/{1}...".format(home_dir, m['file'])

            task_id = client.create_deployment(manifest)
            task = client.wait_for_task(task_id)

        print "Finished deploying {0}/manifests/{1}...".format(home_dir, m['file'])

    return context
Пример #3
0
def do_step(context):
    settings = context.meta['settings']

    username = settings["username"]
    home_dir = os.path.join("/home", username)
    index_file = context.meta['index-file']

    f = open("manifests/{0}".format(index_file))
    manifests = yaml.safe_load(f)
    f.close()

    client = bosh_client.BoshClient("https://10.0.0.4:25555", "admin", "admin")

    for m in manifests['manifests']:
        print "Running errands for {0}/manifests/{1}...".format(
            home_dir, m['file'])

        try:
            for errand in m['errands']:
                print "Running errand {0}".format(errand)

                task_id = client.run_errand(m['deployment-name'], errand)
                task = client.wait_for_task(task_id)

                retries = 0

                while task['state'] == 'error' and retries < 5:

                    retries += 1

                    print "Retrying errand {0}".format(errand)

                    task_id = client.run_errand(m['deployment-name'], errand)
                    task = client.wait_for_task(task_id)

                result = client.get_task_result(task_id)
                print "Errand finished with exit code {0}".format(
                    result['exit_code'])

                print "=========== STDOUT ==========="
                print result['stdout'].encode('utf8')

                print "=========== STDERR ==========="
                print result['stderr'].encode('utf8')

        except KeyError:
            print "Ignoring KeyError exception"

    return context
Пример #4
0
def do_step(context):

    settings = context.meta['settings']

    username = settings["username"]
    home_dir = os.path.join("/home", username)

    os.environ["HOME"] = home_dir

    # deploy director
    os.environ["BOSH_INIT_LOG_LEVEL"] = 'INFO'
    os.environ["BOSH_INIT_LOG_PATH"] = './bosh-init-debug.log'

    client = bosh_client.BoshClient("https://10.0.0.4:25555", "admin", "admin")
    try:
        client.get_info()
    except requests.exceptions.ConnectionError:
        res = None

        while res != 0:
            res = call("bosh-init deploy {0}/bosh.yml".format(home_dir), shell=True)

    return context
Пример #5
0
def do_step(context):
    settings = context.meta['settings']
    index_file = context.meta['index-file']
    pivnetAPIToken = settings["pivnet-api-token"]

    f = open("manifests/{0}".format(index_file))
    manifests = yaml.safe_load(f)
    f.close()

    eula_urls = [
        "https://network.pivotal.io/api/v2/products/{0}/releases/{1}/eula_acceptance"
        .format(m['release-name'], m['release-number'])
        for m in manifests['manifests']
    ]

    release_urls = [
        "https://network.pivotal.io/api/v2/products/{0}/releases/{1}/product_files/{2}/download"
        .format(m['release-name'], m['release-number'], m['file-number'])
        for m in manifests['manifests']
    ]

    stemcell_urls = [m['stemcell'] for m in manifests['manifests']]

    # accept eula for each product
    for url in eula_urls:
        print url
        if not "concourse" in url:
            res = authorizedPost(url, pivnetAPIToken)
            code = res.getcode()

    # releases
    is_release_file = re.compile("^releases\/.+")
    if not os.path.exists("/tmp/releases"):
        os.makedirs("/tmp/releases")

    client = bosh_client.BoshClient("https://10.0.0.4:25555", "admin", "admin")
    storage_account_name = settings["STORAGE-ACCOUNT-NAME"]
    storage_access_key = settings["STORAGE-ACCESS-KEY"]

    blob_service = BlobService(storage_account_name, storage_access_key)
    blob_service.create_container(container_name='tempreleases',
                                  x_ms_blob_public_access='container')

    print "Processing releases."
    for url in release_urls:

        print "Downloading {0}.".format(url)

        if "concourse" in url:
            release_url = "https://s3-us-west-2.amazonaws.com/bosh-azure-releases/concourse.zip"
            res = urllib2.urlopen(release_url)
        else:
            res = authorizedPost(url, pivnetAPIToken)

        code = res.getcode()

        length = int(res.headers["Content-Length"])

        # content-length
        if code is 200:

            total = 0
            pcent = 0.0
            CHUNK = 16 * 1024

            with tempfile.TemporaryFile() as temp:
                while True:
                    chunk = res.read(CHUNK)
                    total += CHUNK
                    pcent = (float(total) / float(length)) * 100

                    sys.stdout.write("Download progress: %.2f%% (%.2fM)\r" %
                                     (pcent, total / 1000000.0))
                    sys.stdout.flush()

                    if not chunk:
                        break

                    temp.write(chunk)

                print "Download complete."

                z = zipfile.ZipFile(temp)
                for name in z.namelist():

                    # is this a release?
                    if is_release_file.match(name):

                        release_filename = "/tmp/{0}".format(name)

                        print "Unpacking {0}.".format(name)
                        z.extract(name, "/tmp")

                        print "Uploading {0} to Azure blob store".format(name)

                        blob_service.put_block_blob_from_path(
                            'tempreleases',
                            name,
                            "/tmp/{0}".format(name),
                            x_ms_blob_content_type='application/x-compressed')

                        os.unlink(release_filename)
                        blob_url = "http://{0}.blob.core.windows.net/{1}/{2}".format(
                            storage_account_name, 'tempreleases', name)

                        print "Uploading release {0} to BOSH director.".format(
                            name)

                        task_id = client.upload_release(blob_url)
                        client.wait_for_task(task_id)

                z.close()
                temp.close()

    blob_service.delete_container("tempreleases")

    # stemcells
    print "Processing stemcells."

    for url in stemcell_urls:
        print "Processing stemcell {0}".format(url)
        task_id = client.upload_stemcell(url)
        client.wait_for_task(task_id)

    return context