python 使用juju魅力部署单节点Cloud Foundry设置的脚本。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 使用juju魅力部署单节点Cloud Foundry设置的脚本。相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python
import os
import yaml
import commands
import time


def run(command):
    print "Executing: %s" % command
    os.system(command)


def get_status_hash():
    return yaml.load(commands.getoutput('juju status'))


def wait_for_machine(machine_number,
                     required_state='started',
                     retries=40,
                     timeout=2):
    while True:
        status_hash = get_status_hash()
        current_state = status_hash['machines'][machine_number]['agent-state']
        retries = retries - 1
        print "retries: %s" % retries
        print "current_state: %s" % current_state
        if (current_state == required_state) or (retries == 0):
            if retries == 0:
                raise BaseException("Machine %s is not "
                                    "available." % machine_number)
            else:
                break
        time.sleep(timeout)

environment_name = commands.getoutput('juju switch')
print("!!! Destroying %s environment" % environment_name)
run('juju destroy-environment %s' % environment_name)

print("!!! Bootstraping %s environment" % environment_name)
run('juju bootstrap')

print("!!! Creating machine for deploy.")
run('juju add-machine --constraints arch=amd64 --constraints mem=2G '
    '--series trusty')

juju_status_hash = yaml.load(commands.getoutput('juju status'))
machine_number = juju_status_hash['machines'].keys()[-1]
wait_for_machine(machine_number)

charms = {'cf-nats': 'nats',
          'cf-go-router': 'router',
          'cf-cloud-controller': 'cc',
          'cf-dea': 'dea',
          'cf-uaa': 'uaa'}

for charm_name in charms.keys():
    service_name = charms[charm_name]
    os.chdir(charm_name)
    run('juju deploy --to %s --repository=../../. '
        'local:trusty/%s %s '
        '--show-log' % (machine_number, charm_name, service_name))
    os.chdir('..')

for service_name in ['router', 'cc', 'dea', 'uaa']:
    run('juju add-relations nats %s' % service_name)

for service_name in ['cc', 'dea', 'uaa']:
    run('juju add-relations router %s' % service_name)

以上是关于python 使用juju魅力部署单节点Cloud Foundry设置的脚本。的主要内容,如果未能解决你的问题,请参考以下文章

Spring Cloud学习笔记-004

Ceph单节点部署

Spring-Cloud之Eureka注册中心环境搭建(单节点)

MongoDB 2.6复制集单节点部署

MongoDB 3.2复制集单节点部署

Clickhouse 单节点部署多个实例