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

    # Script
    print "Deploy a server with the openshift client tools"
    start_time = time.time()

    # Connect to the ComodIT API
    client = Client(config.endpoint, config.username, config.password)
    env = client.get_environment(config.organization, "Openshift")

    # Lookup nfs server
    try:
        broker = env.get_host("Openshift Broker")
    except EntityNotFoundException:
        print "Could not find the broker"
        sys.exit(-1)

    # Deploy the client
    name = "Openshift Client"
    node = create_host(env, name, config.platform, config.distribution, [])
    print "Deploying %s" % name
    node.provision()

    # Wait for host to be deployed
    print "Waiting for host %s to be deployed" % node.name
    node.wait_for_state("READY", config.time_out)
    if node.state == "PROVISIONING":
        raise Exception("Timed out waiting for host to be deployed.")

    # Get network details
    node_ip = node.get_instance().wait_for_property("ip.eth0", config.time_out)

    # Add dns record for this new host
    setting = broker.get_application("openshift-bind-server").get_setting("dns_records")
    setting.value.append({"host": "client", "type": "A", "ttl": "180", "target": node_ip})
    setting.update()

    # Configure network
    print "Reconfiguring network"
    node.install("openshift-dhcp-dns-config", {"hostname": "client"})
    track_changes(node)

    # Install openshift-client
    print "Installing Openshift Client"
    node.install("openshift-client", {})
    track_changes(node)

    # Cleanup changes
    node.changes().clear()

    public_hostname = node.get_instance().wait_for_address(config.time_out)
    print "Openshift client deployed at %s" % public_hostname

    total_time = time.time() - start_time
    print "Deployment time: " + str(total_time)
Пример #2
0
def deploy():

    # Script
    start_time = time.time()

    # Connect to the ComodIT API
    client = Client(config.endpoint, config.username, config.password)
    env = client.get_environment(config.organization, 'Openshift')
    
    # Configure environment
    try:
      env.settings().create("domain", config.domain)
    except:
      print "Did not reconfigure domain since a setting was already defined. Run teardown if you wanted to cleanup first"

    # Deploy Openshift Broker
    try:
      broker = env.get_host('Openshift Broker')
    except EntityNotFoundException:
      broker = create_host(env, 'Openshift Broker', config.platform, config.distribution, [])
      print "Deploying Openshift Broker"
      broker.provision()
      broker.refresh()

    # Wait for Broker to be deployed and retrieve IP
    if broker.state == "PROVISIONING":
      print "Waiting for Broker to be deployed"
      broker.wait_for_state('READY', config.time_out)
      if broker.state == "PROVISIONING":
          raise Exception("Timed out waiting for host to be provisioned.")

    # Get the broker IP address
    broker_ip = broker.get_instance().wait_for_property("ip.eth0", config.time_out)
    if broker_ip is None:
        raise Exception("Failed to retrieve the host IP")

    # Configure broker
    print "Installing the Bind server"
    broker.install("openshift-bind-server", {"dns_records": [{"host":"broker", "type": "A", "ttl": "180", "target": broker_ip}]})
    track_changes(broker)

    # Update environment settings with nameserver
    env.settings().create("nameserver", broker_ip)

    # Configure Network
    print "Reconfiguring network"
    broker.install("openshift-dhcp-dns-config", {"hostname": "broker"})
    track_changes(broker)
    
    # Install Mongo
    print "Installing MongoDB"
    mongo_pw = generate_id(12)
    broker.install("openshift-mongodb", {"smallfiles": True, "secure": True, "users": [{"database": "openshift", "username": "******", "password": mongo_pw}]})
    track_changes(broker)

    # Install RabbitMQ
    print "Installing RabbitMQ"
    broker.install("openshift-rabbitmq-server", {})
    track_changes(broker)

    # Install Mcollective client
    print "Installing MCollective Client"
    broker.install("openshift-mcollective-client", {})
    track_changes(broker)

    # Install Broker
    print "Installing Openshift Broker"
    broker.install("openshift-broker", {"mongo_database": "openshift", "mongo_user": "******", "mongo_password": mongo_pw})
    track_changes(broker)

    # Cleanup changes
    broker.changes().clear()

    # Get broker public hostname
    public_hostname = broker.get_instance().wait_for_address(config.time_out)
    print "Openshift broker deployed at %s" % public_hostname

    total_time = time.time() - start_time
    print "Deployment time: " + str(total_time)
Пример #3
0
def scale():

    # Script
    print "Adding a node to openshift cluster"
    start_time = time.time()

    # Connect to the ComodIT API
    client = Client(config.endpoint, config.username, config.password)
    env = client.get_environment(config.organization, "Openshift")

    # Lookup broker server
    try:
        broker = env.get_host("Openshift Broker")
    except EntityNotFoundException:
        print "Could not find the broker"
        sys.exit(-1)

    # Fetch broker public key
    public_key = broker.get_instance().get_file_content("/etc/openshift/rsync_id_rsa.pub").read()

    # Lookup next index
    index = 0
    for h in env.hosts():
        name = h.name
        if name.startswith("Openshift Node"):
            i = int(name[15:].rstrip())
            if i > index:
                index = i
    index += 1

    # Deploy the required number of hosts
    name = "Openshift Node %s" % index
    node = create_host(env, name, config.platform, config.distribution, [])
    print "Deploying %s" % name
    node.provision()

    # Wait for host to be deployed
    print "Waiting for host %s to be deployed" % node.name
    node.wait_for_state("READY", config.time_out)
    if node.state == "PROVISIONING":
        raise Exception("Timed out waiting for host to be deployed.")

    # Fetch network details
    node_ip = node.get_instance().wait_for_property("ip.eth0", config.time_out)
    hostname = "node-%s" % index

    # Add dns record for this new host
    setting = broker.get_application("openshift-bind-server").get_setting("dns_records")
    setting.value.append({"host": hostname, "type": "A", "ttl": "180", "target": node_ip})
    setting.update()

    # Configure network
    print "Reconfiguring network"
    node.install("openshift-dhcp-dns-config", {"hostname": hostname})
    track_changes(node)

    # Install mcollective
    print "Installing mcollective server"
    node.install(
        "openshift-mcollective-node",
        {
            "mcollective_stomp_host": "broker." + config.domain,
            "mcollective_stomp_username": "******",
            "mcollective_stomp_password": "******",
        },
    )
    track_changes(node)

    # Install cartridges
    print "Installing openshift-cartridges"
    node.install("openshift-cartridges", {})
    track_changes(node)

    # Install openshift-node
    print "Installing Openshift Node"
    public_ip = node.get_instance().wait_for_property("publicIp", config.time_out)
    try:
        public_hostname = socket.gethostbyaddr(public_ip)
    except:
        public_hostname = node.get_instance().wait_for_address(config.time_out)

    node.install(
        "openshift-node",
        {
            "broker_host": "broker." + config.domain,
            "public_hostname": public_hostname[0],
            "public_ip": public_ip,
            "unsercure_port": "80",
            "keys": [public_key],
        },
    )
    track_changes(node)

    # Cleanup changes
    node.changes().clear()

    total_time = time.time() - start_time
    print "Deployment time: " + str(total_time)