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)
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)
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)
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)
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)
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
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)
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)
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)
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)
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)