Beispiel #1
0
def clean_up():
    # Connect to the ComodIT API
    client = Client(config.endpoint, config.username, config.password)
    org = client.get_organization(config.organization)

    print "Cleaning up ComodIT..."

    # Delete environment (if empty)
    env = org.environments().delete('Openshift')

    # Delete applications
    org.applications().delete('openshift-bind-server')
    org.applications().delete('openshift-broker')
    org.applications().delete('openshift-client')
    org.applications().delete('openshift-dhcp-dns-config')
    org.applications().delete('openshift-mcollective-client')
    org.applications().delete('openshift-mcollective-node')
    org.applications().delete('openshift-mongodb')
    org.applications().delete('openshift-cartridges')
    org.applications().delete('openshift-node')
    org.applications().delete('openshift-rabbitmq-server')



    print "Done."
Beispiel #2
0
def downscale(count):
    # Script
    print "Down-scaling render farm"
    start_time = time.time()

    client = Client(config.endpoint, config.username, config.password)
    env = client.get_environment(config.organization, "Render Farm")

    for i in range(int(count)):
        # Lookup highest index
        index = 0
        for h in env.hosts():
            name = h.name
            if name.startswith("Render"):
                i = int(name[14:].rstrip())
                if i > index:
                    index = i

        # Remove host from load balancer
        name = "Render Server %s" % index
        host = env.get_host(name)

        # Delete host
        try:
            print "Deleting instance of", host.name
            host.get_instance().delete()
            host.delete()
        except Exception as e:
            print "Could not delete host ", host.name
            print e
Beispiel #3
0
def scale_osds(count):
    # Script
    print "Up-scaling Ceph cluster (OSDs)"
    start_time = time.time()

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

    latest_id = get_latest_id('Object Store ', env)
    if latest_id < 0:
        raise Exception("No OSD found")

    conf_app = [{"name": "Ceph Configuration", "settings": {}}]
    osd_hosts = []
    for i in xrange(latest_id + 1, latest_id + count + 1):
        osd = create_host(env, 'Object Store ' + str(i), config.platform, config.distribution, conf_app)
        print "Deploying Object Store " + str(i)
        osd.provision()
        osd_hosts.append(osd)

    print "Waiting for all hosts to be deployed..."
    for h in osd_hosts:
        h.wait_for_state(Host.State.READY, config.time_out)

    osd_ips = []
    osd_names = []
    for h in osd_hosts:
        osd_ips.append(h.get_instance().wait_for_property("ip.eth0", config.time_out))
        osd_names.append(get_short_hostname(h.get_instance().wait_for_property("hostname", config.time_out)))

    for i in xrange(0, len(osd_ips)):
        print "OSD %i has IP %s and hostname %s" % (latest_id + i + 1, osd_ips[i], osd_names[i])

    print "Configure cluster..."
    next_id = latest_id + 1
    osds = env.get_setting("osds").value
    for name in osd_names:
        osds.append({"id": str(next_id), "host": name})
        next_id += 1

    env.settings().update("osds", osds)
    time.sleep(3)

    print "Installing OSD(s)..."
    i = 0
    next_id = latest_id + 1
    for h in osd_hosts:
        h.install("Ceph Object Store", {"osd_id": str(next_id), "osd_hostname": osd_names[i]})
        next_id += 1
        i += 1
        time.sleep(3)

    for h in osd_hosts:
        h.wait_for_pending_changes()

    total_time = time.time() - start_time
    print "Up-scaling time: " + str(total_time)
Beispiel #4
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)
Beispiel #5
0
def deploy():

    # Script
    print "Deploying Development Host"
    start_time = time.time()

    # Connect to the ComodIT API
    client = Client(config["api"], config["username"], config["password"])
    org = client.get_organization(config["organization"])
    env = org.get_environment("Development")

    # Deploy host
    host = create_host(env, config["vm"]["name"], config["platform"], config["distribution"], [])
    host.provision()

    # Download gPXE ISO
    if not config["vm"]["iso"] or not os.path.exists(config["vm"]["iso"]):
        config["vm"]["iso"] = download_iso(
            config["gpxe_url"],
            config["vm"]["name"],
            org.access_key,
            org.secret_key,
            org.name,
            urlparse(config["api"]).netloc,
        )

    # Define the vm
    print "Creating the virtual machine"
    success = create_combox(config["vm"])
    if not success:
        sys.exit(-1)

    # Start the vm
    print "Starting the virtual machine"
    fork_cmd('virtualbox --startvm "%s"' % config["vm"]["name"])

    # Wait for server to be ready
    print "Waiting for host to be ready"
    host.wait_for_state("READY", config["time_out"])

    # Wait for hostname to be ready
    print "Waiting for hostname to be ready"
    host.get_instance().wait_for_address()

    # Install applications
    for app in config["applications"]:
        app_name = app["name"].split("/")[-1]
        print "Installing application %s" % app_name
        host.install(app_name, app["settings"])
        host.wait_for_state("READY", config["time_out"])

    # Goodbye
    total_time = time.time() - start_time
    print "Deployment time: " + str(total_time)
Beispiel #6
0
def teardown():
    # Script
    print "Teardown of Blender Render Farm"

    client = Client(config.endpoint, config.username, config.password)
    env = client.get_environment(config.organization, "Render Farm")

    for h in env.hosts():
        try:
            print "Deleting instance of", h.name
            h.get_instance().delete()
        except Exception as e:
            print "Could not delete host ", h.name
        h.delete()
Beispiel #7
0
def clean_up():
    # Connect to the ComodIT API
    client = Client(config.endpoint, config.username, config.password)
    org = client.get_organization(config.organization)

    print "Cleaning up ComodIT..."

    # Delete environment (if empty)
    env = org.environments().delete('Render Farm')

    # Delete applications
    org.applications().delete('NFS Server')
    org.applications().delete('NFS Client')
    org.applications().delete('Blender')

    print "Done."
Beispiel #8
0
def cleanup():
    # Connect to the ComodIT API
    client = Client(config['api'], config['username'], config['password'])
    org = client.get_organization(config['organization'])

    print "Cleaning up ComodIT..."

    # Delete applications
    for app in config['applications']:
        print "Removing application %s" % app["name"]
        app_name = app['name'].split('/')[-1]
        try:
            org.applications().delete(app_name)
        except Exception as e:
            print "Failed to remove application %s with error %s." % app['name'], e

    print "Done."
Beispiel #9
0
def scale(count):

    # Script
    print "Up-scaling render farm cluster"
    start_time = time.time()

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

    # Lookup nfs server
    try:
        nfs_master = env.get_host('NFS Server')
    except EntityNotFoundException:
        print "Could not find the NFS Master"
        sys.exit(-1)

    # Lookup next index
    index = 0
    for h in env.hosts():
        name = h.name
        if name.startswith('Render'):
            i = int(name[14:].rstrip())
            if i > index:
                index = i
    index += 1

    # Prepare NFS Configuration
    master_ip = nfs_master.get_instance().wait_for_property("ip.eth0", config.time_out)
    location = "%s:/data" % master_ip

    # Deploy the required number of hosts
    hosts = []
    for i in range(index, index + int(count)):
        name = 'Render Server %s' % i
        render_host = create_host(env, name, config.platform, config.distribution, [{"name": "NFS Client", "settings": {"shares": [{"key": "data", "location": location, "options": "rw,soft,intr,rsize=8192,wsize=8192"}]}}, {"name": "Blender", "settings": {}}])
        render_host.provision()
        hosts.append(render_host)

    # Wait and configured provisioned hosts
    for h in hosts:
        print "Waiting for host %s to be deployed" % h.name
        h.wait_for_state('READY', config.time_out)

    total_time = time.time() - start_time
    print "Deployment time: " + str(total_time)
Beispiel #10
0
def teardown():
    # Script
    print "Teardown of Openshift"

    client = Client(config.endpoint, config.username, config.password)
    env = client.get_environment(config.organization, "Openshift")

    for s in env.settings():
        env.settings().delete(s.key)

    for h in env.hosts():
        try:
            print "Deleting instance of", h.name
            h.get_instance().delete()
        except Exception as e:
            print "Could not delete host ", h.name
        h.delete()
Beispiel #11
0
def setup_organization():
    # Connect to the ComodIT API
    client = Client(config['api'], config['username'], config['password'])
    org = None

    if config['organization']:
        org = client.get_organization(config['organization'])
    else:
        orgs = client.organizations().list()
        if orgs == 1:
            org = orgs[0]
        elif orgs == 0:
            raise FatalException("No organization found.")
        else:
            raise FatalException("Multiple organization defined. "
                    "Please specify one in your ~/.comoditrc with the key "
                    "\"default_organization\"")
    return org
Beispiel #12
0
def clean_up():
    # Connect to the ComodIT API
    client = Client(config.endpoint, config.username, config.password)
    org = client.get_organization(config.organization)

    print "Cleaning up ComodIT..."

    # Delete environment (if empty)
    env = org.environments().delete('Cluster')

    # Delete applications
    org.applications().delete('Ceph Configuration')
    org.applications().delete('Ceph Monitor')
    org.applications().delete('Ceph Metadata')
    org.applications().delete('Ceph Object Store')
    org.applications().delete('Ceph Client')

    print "Done."
Beispiel #13
0
def downscale_osds(count):
    # Script
    print "Down-scaling Ceph cluster (monitors)"
    start_time = time.time()

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

    latest_id = get_latest_id('Monitor ', env)
    if latest_id < 0:
        raise Exception("No monitor found")

    if latest_id - count + 1 <= 2:
        raise Exception("Cannot down-scale to less than 3 monitors")

    mon_hosts = []
    for i in xrange(latest_id - count + 1, latest_id + 1):
        mon = env.get_host('Monitor ' + str(i))
        print "Bringing Monitor %i out of cluster..." % i
        mon.settings().create("status", "down")
        mon_hosts.append(mon)

    for h in mon_hosts:
        h.wait_for_pending_changes()

    print "Configure cluster..."
    next_id = latest_id + 1
    monitors = env.get_setting("monitors").value
    for i in xrange(0, len(monitors)):
        mon = monitors[i]
        id = int(mon["id"])
        if id >= latest_id - count + 1 and id < latest_id + 1:
            del monitors[i]
    env.settings().update("monitors", monitors)
    time.sleep(3)

    print "Deleting monitor(s)..."
    for h in mon_hosts:
        h.get_instance().delete()
        h.delete()

    total_time = time.time() - start_time
    print "Down-scaling time: " + str(total_time)
Beispiel #14
0
def downscale(count):
    # Script
    print "Down-scaling web cluster"
    start_time = time.time()

    client = Client(config.endpoint, config.username, config.password)
    env = client.get_environment(config.organization, "Cluster")

    # Lookup LB host
    try:
        lb_host = env.get_host("LB")
    except EntityNotFoundException:
        print "Could not find the Load Balancer"
        sys.exit(-1)

    for i in range(int(count)):
        # Lookup highest index
        index = 0
        for h in env.hosts():
            name = h.name
            if name.startswith("Web"):
                i = int(name[3:].rstrip())
                if i > index:
                    index = i

        # Remove host from load balancer
        name = "Web %s" % index
        web_host = env.get_host(name)

        print "Removing %s from load balancer configuration" % name
        web_hostname = web_host.get_instance().wait_for_address(config.time_out)

        setting = lb_host.get_application(data.lb["name"]).get_setting("upstream")
        setting.value.remove(web_hostname)
        setting.update()

        # Delete host
        try:
            print "Deleting instance of", web_host.name
            web_host.get_instance().delete()
            web_host.delete()
        except Exception as e:
            print "Could not delete host ", web_host.name
            print e
Beispiel #15
0
def downscale_osds(count):
    # Script
    print "Down-scaling Ceph cluster (OSDs)"
    start_time = time.time()

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

    latest_id = get_latest_id('Object Store ', env)
    if latest_id < 0:
        raise Exception("No OSD found")

    if latest_id - count + 1 <= 1:
        raise Exception("Cannot down-scale to less than 2 OSDs")

    osd_hosts = []
    for i in xrange(latest_id - count + 1, latest_id + 1):
        osd = env.get_host('Object Store ' + str(i))
        print "Bringing Object Store %i out of cluster..." % i
        osd.settings().create("status", "out")
        osd_hosts.append(osd)

    for h in osd_hosts:
        h.wait_for_pending_changes()

    print "Configure cluster..."
    next_id = latest_id + 1
    osds = env.get_setting("osds").value
    for i in xrange(0, len(osds)):
        osd = osds[i]
        id = int(osd["id"])
        if id >= latest_id - count + 1 and id < latest_id + 1:
            del osds[i]
    env.settings().update("osds", osds)
    time.sleep(3)

    print "Deleting OSD(s)..."
    for h in osd_hosts:
        h.get_instance().delete()
        h.delete()

    total_time = time.time() - start_time
    print "Down-scaling time: " + str(total_time)
Beispiel #16
0
def deploy(slaves_count):

    # Script
    print "Deploying Blender Render Farm"
    start_time = time.time()

    # Connect to the ComodIT API
    client = Client(config.endpoint, config.username, config.password)
    env = client.get_environment(config.organization, 'Render Farm')
    
    # Deploy NFS Server
    try:
      nfs_master = env.get_host('NFS Server')
    except EntityNotFoundException:
      nfs_master = create_host(env, 'NFS Server', config.platform, config.distribution, [{"name": "NFS Server", "settings": {"shares":[{"path":"/data", "source":"*", "options":"rw,sync,no_root_squash,no_subtree_check", "create": True}]}}])
      print "Deploying NFS Server"
      nfs_master.provision()

    # Deploy Blender client
    hosts = []
    for i in range(0, int(slaves_count)):
        name = 'Render Server %s' % i
        render_host = create_host(env, name, config.platform, config.distribution, [{"name":"NFS Client", "settings": {}},{"name":"Blender", "settings":{}}])
        render_host.provision()
        hosts.append(render_host)    

    # Wait for NFS Server to be deployed and retrieve IP
    print "Waiting for NFS Server to be deployed"
    nfs_master.wait_for_state('READY', config.time_out)
    master_ip = nfs_master.get_instance().wait_for_property("ip.eth0", config.time_out)
    location = "%s:/data" % master_ip   

    # Wait for slaves to be ready and configure NFS Shares
    print "Waiting for render servers to be deployed"
    for h in hosts:
        h.wait_for_state(Host.State.READY, config.time_out)
    
    # Configuring render servers
    for h in hosts:
        print "Configuring %s" % h.name
        h.get_application("NFS Client").settings().create('shares', [{"key":"data", "location": location, "options": "rw,soft,intr,rsize=8192,wsize=8192"}])

    total_time = time.time() - start_time
    print "Deployment time: " + str(total_time)
Beispiel #17
0
def teardown():
    # Script
    print "Teardown of Ceph cluster"

    client = Client(config.endpoint, config.username, config.password)
    env = client.get_environment(config.organization, "Cluster")

    for h in env.hosts():
        try:
            print "Deleting instance of", h.name
            h.get_instance().delete()
        except Exception as e:
            print "Could not delete host ", h.name
        h.delete()

    print "Deleting settings..."
    env.settings().delete('monitors')
    env.settings().delete('osds')
    env.settings().delete('mdss')
    env.settings().delete('admin_key')
Beispiel #18
0
def setup():
    # Connect to the ComodIT API
    client = Client(config.endpoint, config.username, config.password)
    org = client.get_organization(config.organization)

    print "Setting up ComodIT..."

    # Create environment (if not already present)
    try:
        org.environments().create("Render Farm", "Environment containing the render farm.")
    except:
        pass

    # Import applications
    importer = Import()
    importer.import_application(org, 'nfs-server')
    importer.import_application(org, 'nfs-client')
    importer.import_application(org, 'blender')

    print "Done."
Beispiel #19
0
def teardown():
    # Script
    print "Teardown of development environment"

    client = Client(config['api'], config['username'], config['password'])
    env = client.get_environment(config['organization'], "Development")

    # First detroy the VM
    exec_cmds(['VBoxManage controlvm "%s" poweroff' % config['vm']['name'],
               'VBoxManage unregistervm "%s" --delete' % config['vm']['name']],
              False)

    # Then delete the comodit hosts
    for h in env.hosts():
        try:
            print "Deleting instance of", h.name
            h.get_instance().delete()
        except Exception:
            print "Could not delete host ", h.name
        h.delete()
Beispiel #20
0
def setup():
    # Connect to the ComodIT API
    client = Client(config.endpoint, config.username, config.password)
    org = client.get_organization(config.organization)

    print "Setting up ComodIT..."

    # Create environment (if not already present)
    try:
        org.environments().create("Cluster", "Environment containing the web cluster.")
    except:
        pass

    # Import applications
    importer = Import()
    importer.import_application(org, 'db')
    importer.import_application(org, 'lb')
    importer.import_application(org, 'web')

    print "Done."
Beispiel #21
0
def clean_up():
    # Connect to the ComodIT API
    client = Client(config.endpoint, config.username, config.password)
    org = client.get_organization(config.organization)

    print "Cleaning up ComodIT..."

    # Delete environment (if empty)
    try:
        env = org.get_environment('Cluster')
        if len(env.hosts().list()) == 0:
            env.delete()
    except EntityNotFoundException:
        pass

    # Delete applications
    org.applications().delete(data.db['name'])
    org.applications().delete(data.lb['name'])
    org.applications().delete(data.web['name'])

    print "Done."
Beispiel #22
0
def setup():
    # Connect to the ComodIT API
    client = Client(config.endpoint, config.username, config.password)
    org = client.get_organization(config.organization)

    print "Setting up ComodIT..."

    # Create environment (if not already present)
    try:
        org.environments().create("Openshift", "Environment containing the openshift cluster.")
    except:
        pass

    # Import applications
    importer = Import()
    importer.import_application(org, 'openshift-bind-server')
    importer.import_application(org, 'openshift-broker')
    importer.import_application(org, 'openshift-client')
    importer.import_application(org, 'openshift-dhcp-dns-config')
    importer.import_application(org, 'openshift-mcollective-client')
    importer.import_application(org, 'openshift-mcollective-node')
    importer.import_application(org, 'openshift-mongodb')
    importer.import_application(org, 'openshift-node')
    importer.import_application(org, 'openshift-cartridges')
    importer.import_application(org, 'openshift-rabbitmq-server')

    # Update repositories
    if hasattr(config, "repo"):
      updaterepo(org.get_application("openshift-broker"), config.repo)
      updaterepo(org.get_application("openshift-node"), config.repo)
      updaterepo(org.get_application("openshift-client"), config.repo)

    # Append cartridges
    if hasattr(config, "cartridges"):
        app = org.get_application("openshift-cartridges")
        for cart in config.cartridges:
          app.add_package(Package({"name": cart}))
        app.update()

    print "Done."
Beispiel #23
0
def setup():
    # Connect to the ComodIT API
    client = Client(config['api'], config['username'], config['password'])
    org = client.get_organization(config['organization'])

    print "Setting up ComodIT..."

    # Create environment (if not already present)
    try:
        org.environments().create("Development", "Development environment.")
    except:
        pass

    importer = Import()
    for app in config['applications']:
        print "Uploading application %s" % app["name"]
        try:
            importer.import_application(org, app['name'])
        except Exception as e:
            print "Failed to upload applicatin %s with error %s." % (app['name'], e)

    print "Done."
Beispiel #24
0
def deploy():

    # Script
    print "Deploying Development Host"
    start_time = time.time()

    # Connect to the ComodIT API
    client = Client(config['api'], config['username'], config['password'])
    org = client.get_organization(config['organization'])
    env = org.get_environment('Development')
    try:
        plat = org.get_platform(config['platform']['name'])
    except:
        found_platform = False
        print "Looking for a physical platform..."
        for pl in org.platforms().list():
            if pl.driver.class_name == "com.guardis.cortex.server.driver.PxeDriver":
                config['platform']['name'] = pl.driver.class_name
                print "Found physical platform. Using \"%s\"" % pl.driver.name
                found_platform = True
        if not found_platform:
            sys.exit("Platform not found.")



    # Deploy host
    host = create_host(env, config['vm']['name'], config['platform'], config['distribution'], [])
    host.provision()

    # Download gPXE ISO
    if 'iso' not in config['vm'] or not os.path.exists(config['vm']['iso']):
        config['vm']['iso'] = download_iso(config['gpxe_url'],
                                           config['vm']['name'],
                                           org.access_key,
                                           org.secret_key,
                                           org.name,
                                           urlparse(config['api']).netloc)

    # Define the vm
    print "Creating the virtual machine"
    success = create_combox(config['vm'])
    if not success:
        sys.exit(-1)

    # Start the vm
    print "Starting the virtual machine"
    fork_cmd('virtualbox --startvm "%s"' % config['vm']['name'])

    # Wait for server to be ready
    print "Waiting for host to be ready"
    host.wait_for_state('READY', config['time_out'])

    # Wait for hostname to be ready
    print "Waiting for hostname to be ready"
    host.get_instance().wait_for_address()

    # Install applications
    for app in config['applications']:
        app_name = app['name'].split('/')[-1]
        print "Installing application %s" % app_name
        host.install(app_name, app['settings'])
        host.wait_for_state('READY', config['time_out'])

    # Goodbye
    total_time = time.time() - start_time
    print "Deployment time: " + str(total_time)
Beispiel #25
0
def deploy():
    # Script
    print "Deploying Ceph cluster"
    start_time = time.time()

    NUM_OF_MON = 1
    NUM_OF_OSD = 2

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


    # Initialize empty cluster
    for key in ("monitors", "osds", "mdss"):
        try:
            env.settings().create(key, [])
        except:
            pass
        time.sleep(1)
    try:
        env.settings().create("admin_key", config.admin_key)
    except:
        pass
    time.sleep(1)

    conf_app = [{"name": "Ceph Configuration", "settings": {}}]


    # Provision hosts
    mon_hosts = []
    for i in xrange(0, NUM_OF_MON):
        try:
            mon = env.get_host('Monitor ' + str(i))
        except EntityNotFoundException:
            mon = create_host(env, 'Monitor ' + str(i), config.platform, config.distribution, conf_app)
            print "Deploying Monitor " + str(i)
            mon.provision()
        mon_hosts.append(mon)

    osd_hosts = []
    for i in xrange(0, NUM_OF_OSD):
        try:
            osd = env.get_host('Object Store ' + str(i))
        except EntityNotFoundException:
            osd = create_host(env, 'Object Store ' + str(i), config.platform, config.distribution, conf_app)
            print "Deploying Object Store " + str(i)
            osd.provision()
        osd_hosts.append(osd)

    print "Waiting for all hosts to be deployed..."
    for h in mon_hosts + osd_hosts:
        h.wait_for_state(Host.State.READY, config.time_out)


    # Configure the cluster as it is now known
    mon_ips = []
    mon_names = []
    mon_addrs = []
    for h in mon_hosts:
        ip = h.get_instance().wait_for_property("ip.eth0", config.time_out)
        mon_ips.append(ip)
        mon_names.append(get_short_hostname(h.get_instance().wait_for_property("hostname", config.time_out)))
        mon_addrs.append(ip + ":6879")

    osd_ips = []
    osd_names = []
    for h in osd_hosts:
        osd_ips.append(h.get_instance().wait_for_property("ip.eth0", config.time_out))
        osd_names.append(get_short_hostname(h.get_instance().wait_for_property("hostname", config.time_out)))

    for i in xrange(0, len(mon_addrs)):
        print "Monitor %i has address %s and hostname %s" % (i, mon_addrs[i], mon_names[i])

    for i in xrange(0, len(osd_ips)):
        print "OSD %i has IP %s and hostname %s" % (i, osd_ips[i], osd_names[i])

    print

    print "Configure cluster..."
    monitors = []
    for i in xrange(0, len(mon_addrs)):
        monitors.append({"id": str(i), "host": mon_names[i], "addr": mon_addrs[i]})

    osds = []
    for i in xrange(0, len(osd_names)):
        osds.append({"id": str(i), "host": osd_names[i]})

    mdss = []
    for i in xrange(0, len(mon_names)):
        mdss.append({"id": str(i), "host": mon_names[i]})

    env.settings().update("monitors", monitors)
    time.sleep(3)
    env.settings().update("osds", osds)
    time.sleep(3)
    env.settings().update("mdss", mdss)
    time.sleep(3)
    env.settings().update("admin_key", config.admin_key)
    time.sleep(3)


    # Install Ceph
    print "Installing first monitor and meta-data service..."
    mon_hosts[0].install("Ceph Monitor", {"bootstrap": True, "mon_id": "0", "mon_addr": mon_addrs[0]})
    time.sleep(3)
    mon_hosts[0].install("Ceph Metadata", {"mds_id": "0"})
    mon_hosts[0].wait_for_pending_changes()

    print "Installing additional monitors (if any) and meta-data service(s)..."
    for i in xrange(1, len(mon_hosts)):
        mon_hosts[i].install("Ceph Metadata", {"mds_id": str(i)})
        time.sleep(3)
        mon_hosts[i].install("Ceph Monitor", {"mon_id": str(i)})
        time.sleep(3)

    for h in mon_hosts:
        h.wait_for_pending_changes()

    print "Installing OSD(s)..."
    for i in xrange(0, len(osd_hosts)):
        osd_hosts[i].install("Ceph Object Store", {"osd_id": str(i), "osd_hostname": osd_names[i]})
        time.sleep(3)

    for h in osd_hosts:
        h.wait_for_pending_changes()

    total_time = time.time() - start_time
    print "Master node's public IP: %s" % (mon_hosts[0].get_instance().wait_for_address(config.time_out))
    print "Deployment time: " + str(total_time)
Beispiel #26
0
def deploy():
    # Override email in data
    override_email(config.email)

    # Script
    print "Deploying web cluster"
    start_time = time.time()

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

    # Deploy database host
    try:
        db_host = env.get_host('DB Master')
    except EntityNotFoundException:
        db_host = create_host(env, 'DB Master', config.platform, config.distribution, [data.db])
        print "Deploying DB Master"
        db_host.provision()

    # Deploy wordpress host
    try:
        web_host = env.get_host('Web 1')
    except EntityNotFoundException:
        web_host = create_host(env, 'Web 1', config.platform, config.distribution, [data.web])
        print "Deploying Web 1"
        web_host.provision()

    # Deploy load balancer
    try:
        lb_host = env.get_host('LB')
    except EntityNotFoundException:
        lb_host = create_host(env, 'LB', config.platform, config.distribution, [data.lb])
        print "Deploying LB"
        lb_host.provision()

    # Wait for database to be deployed
    print "Waiting for Database Master to be deployed"
    db_host.wait_for_state(Host.State.READY, config.time_out)
    db_hostname = db_host.get_instance().wait_for_address(config.time_out)
    print "DB Master hostname: " + db_hostname

    # Wait for web tier to be ready and then configure it
    print "Waiting for Web Tier to be deployed"
    web_host.wait_for_state(Host.State.READY, config.time_out)
    web_hostname = web_host.get_instance().wait_for_address(config.time_out)
    print "Web Tier hostname: " + web_hostname

    print "Configuring Web Tier"
    web_host.get_application(data.web['name']).settings().create('wp_db_host', db_hostname)

    # Wait for LB to be delployed and then configure it
    print "Waiting for Load Balancer to be deployed"
    lb_host.wait_for_state(Host.State.READY, config.time_out)
    lb_hostname = lb_host.get_instance().wait_for_address(config.time_out)
    print "Load Balancer hostname: " + lb_hostname

    print "Configuring Load Balancer"
    lb_host.get_application(data.lb['name']).settings().create('upstream', [web_hostname])

    total_time = time.time() - start_time
    print "Cluster deployed - Public hostname: " + lb_hostname
    print "Deployment time: " + str(total_time)
Beispiel #27
0
def scale_mons(count):
    # Script
    print "Up-scaling Ceph cluster (monitors)"
    start_time = time.time()

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

    latest_id = get_latest_id("Monitor ", env)
    if latest_id < 0:
        raise Exception("No monitor found")

    conf_app = [{"name": "Ceph Configuration", "settings": {}}]
    mon_hosts = []
    for i in xrange(latest_id + 1, latest_id + count + 1):
        mon = create_host(env, "Monitor " + str(i), config.platform, config.distribution, conf_app)
        print "Deploying Monitor " + str(i)
        mon.provision()
        mon_hosts.append(mon)

    print "Waiting for all hosts to be deployed..."
    for h in mon_hosts:
        h.wait_for_state(Host.State.READY, config.time_out)

    mon_ips = []
    mon_names = []
    mon_addrs = []
    for h in mon_hosts:
        ip = h.get_instance().wait_for_property("ip.eth0", config.time_out)
        mon_ips.append(ip)
        mon_names.append(get_short_hostname(h.get_instance().wait_for_property("hostname", config.time_out)))
        mon_addrs.append(ip + ":6879")

    for i in xrange(0, len(mon_addrs)):
        print "Monitor %i has address %s and hostname %s" % (latest_id + i + 1, mon_addrs[i], mon_names[i])

    print "Configure cluster..."
    next_id = latest_id + 1
    monitors = env.get_setting("monitors").value
    for name in mon_names:
        monitors.append({"id": str(next_id), "host": mon_names[i], "addr": mon_addrs[i]})
        next_id += 1

    env.settings().update("monitors", monitors)
    time.sleep(3)

    print "Installing monitor(s)..."
    next_id = latest_id + 1
    for h in mon_hosts:
        h.install("Ceph Monitor", {"mon_id": str(next_id)})
        next_id += 1
        time.sleep(3)

    for h in mon_hosts:
        h.wait_for_pending_changes()

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

    if (latest_id + count + 1) % 2 == 0:
        print
        print "WARNING: you do not have an odd number of monitors (-> potential quorum problems)"
        print
Beispiel #28
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)
Beispiel #29
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)
Beispiel #30
0
 def connect(self, api_url, username, password, insecure=False):
     self._cmds = Commands(Client(api_url, username, password, insecure))
     self._cmds.set_debug(self._debug)