Ejemplo n.º 1
0
def start(req):
    base_path = os.path.abspath(os.path.dirname(__file__))
    form = req.GET
    rows = db_manager.select(
        u"select ip, netns from stacks where deleted = '0' and manager = '1' and scid = '"
        + form['scid'] + "'")
    if form['mode'] == 'verify':
        subprocess.call([
            'sudo', 'ip', 'netns', 'exec', rows[0][1], '/usr/bin/python',
            base_path + '/scenario_verify.py', rows[0][0]
        ])
        f = open(base_path + '/../template/redirect.tmpl')
        data = f.read()
        tmpl = Template(unicode(data, 'utf-8', 'ignore'))
        body = tmpl.substitute({'url': 'index.py'})
        return HttpResponse(body)
    else:
        #		ret=subprocess.call(['sudo', 'ip', 'netns', 'exec',
        #			rows[0][1],
        #			'/usr/bin/python', base_path + '/cgi-bin/scenario_result.py' , rows[0][0]])
        #		ret = commands.getoutput('sudo ip netns exec ' + rows[0][1] +
        #				' /usr/bin/python ' + base_path + '/scenario_result.py ' + rows[0][0])
        #		f=open(base_path + '/../template/result.tmpl')
        #		data=f.read()
        #		tmpl=Template(unicode(data, 'utf-8', 'ignore'))
        #		body=tmpl.substitute({'result':ret})
        return HttpResponse(result(rows[0][1], rows[0][0]))
Ejemplo n.º 2
0
def get_netns(scid):
    rows = db_manager.select(
        u"select netns from stacks where scid='%s' and deleted=0 and manager=1"
        % scid)
    if len(rows):
        return rows[0][0]
    return '-'
Ejemplo n.º 3
0
def scenario_list():
    ret = ""
    rows = db_manager.select(
        u"select sc.uuid, sc.scenario, sc.status, lb.pool_id from scenarios as sc left outer join lb_scenario lb on sc.uuid = lb.scid"
    )
    for row in rows:
        scid = row[0]
        parameter = {"scid": scid, "lbaas": "True" if row[3] else "False"}
        ret += """<tr><td>%s</td>""" % (row[1])
        status = scenario_status(row[2])
        ret += """<td>%s""" % (status)
        if row[2] == 1:
            ret += "</td><td>%s%s%s%s%s</td>" % (
                get_btn_verify(parameter), get_btn_result(parameter),
                get_btn_delete(parameter), get_btn_enviroment(parameter),
                get_btn_log(parameter))
        elif row[2] < 0:
            ret += "</td><td>%s%s%s%s%s</td>" % (
                get_btn_verify(None), get_btn_result(None),
                get_btn_delete(parameter), get_btn_enviroment(parameter),
                get_btn_log(parameter))
        else:
            ret += """<br><progress max="100"></progress></td>"""
            ret += "</td><td>%s%s%s%s%s</td>" % (
                get_btn_verify(None), get_btn_result(None),
                get_btn_delete(None), get_btn_enviroment(None),
                get_btn_log(parameter))
        ret += """</tr>"""
    return ret
Ejemplo n.º 4
0
def delete_stack(scenario):
    rows = db_manager.select(
        u"select uuid from stacks where deleted=0 and scenario='" + scenario +
        "'")
    for uuid in rows:
        os.system("heat stack-delete " + uuid[0])
        db_wrapper.delete_stack(uuid[0])
Ejemplo n.º 5
0
def show_env(scid):
        ret=""
	rows=db_manager.select(u"select host, stack_id, ip, manager from stacks where scid='%s' and deleted=0" % scid)
        tmp=[]
        for row in rows:
                log.debug(str(row))
		ret+="""<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>""" % (row[0], row[1], row[2], 'yes' if row[3]==1 else 'no', get_vnc(row[1], row[3]))
	
	return ret
Ejemplo n.º 6
0
	def lb_delete(self):
		lb = os_lbaas.Delete()
		lb_map = {}
		members = []
		# lb_scenari x lb_vip
		rows = db_manager.select(u"select pool.pool_id, vip.uuid from lb_scenario as pool, lb_vip as vip where pool.pool_id = vip.pool_id and pool.scid = '%s'" % self.scid)
		lb_map["pool"] = {}
		lb_map["pool"]["id"] = rows[0][0]
		lb_map["vip"] = {}
		lb_map["vip"]["id"] = rows[0][1]
		# lb_scenario x lb_member
		rows = db_manager.select(u"select member.uuid from lb_scenario as pool, lb_member as member where pool.pool_id = member.pool_id and pool.scid = '%s'" % self.scid)
		for member in rows:
			members.append({"id":member[0]})
		lb_map["members"] = members
		lb.lb_delete(lb_map)
		db_wrapper.delete_lb_scenario(lb_map["pool"]["id"])
		db_wrapper.delete_lb_vip(lb_map["pool"]["id"])
		db_wrapper.delete_lb_member(lb_map["pool"]["id"])
Ejemplo n.º 7
0
def show_lbaas(scid):
	ret = ""
	ret += """<table class="sample1" style="width:60%"><caption>LBaaS</caption><tr>"""
	ret += """<th>Method</th><th>Protocol</th><th>VIP</th><th>Member IP</th>"""
	# lb_scenari x lb_vip
	rows = db_manager.select(u"select pool.method, pool.protocol, vip.vip from lb_scenario as pool, lb_vip as vip where pool.pool_id = vip.pool_id and pool.scid = '%s'" % scid)
	method = rows[0][0]
	protocol = rows[0][1]
	vip = rows[0][2]
	# lb_scenario x lb_member
	rows = db_manager.select(u"select member.ip from lb_scenario as pool, lb_member as member where pool.pool_id = member.pool_id and pool.scid = '%s'" % scid)
	members = ""
	for member in rows:
		if len(members):
			members += "<br>"
 		members += member[0]
	ret += """<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td>""" % (method, protocol, vip, members)
	ret += "</tr></table>"
	return ret
Ejemplo n.º 8
0
	def stack_delete(self):
		hcl = hc.get_client()
		rows = db_manager.select(u"select stack_id from stacks where deleted=0 and scid='%s'" % self.scid)
		for stack_id in rows:
			log.debug("delete stack : %s" % str(stack_id[0]))
			try:
				hcl.stacks.delete(stack_id[0])
			except Exception as e:
				log.error( str(type(e)) + str(e.args) + str(e.message) )
			time.sleep(5)
			db_wrapper.delete_stack(stack_id[0])
Ejemplo n.º 9
0
def show_env(scid):
    ret = ""
    rows = db_manager.select(
        u"select host, stack_id, ip, manager from stacks where scid='%s' and deleted=0"
        % scid)
    tmp = []
    for row in rows:
        log.debug(str(row))
        ret += """<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>""" % (
            row[0], row[1], row[2], 'yes' if row[3] == 1 else 'no',
            get_vnc(row[1], row[3]))

    return ret
Ejemplo n.º 10
0
 def stack_delete(self):
     hcl = hc.get_client()
     rows = db_manager.select(
         u"select stack_id from stacks where deleted=0 and scid='%s'" %
         self.scid)
     for stack_id in rows:
         log.debug("delete stack : %s" % str(stack_id[0]))
         try:
             hcl.stacks.delete(stack_id[0])
         except Exception as e:
             log.error(str(type(e)) + str(e.args) + str(e.message))
         time.sleep(5)
         db_wrapper.delete_stack(stack_id[0])
Ejemplo n.º 11
0
 def lb_delete(self):
     lb = os_lbaas.Delete()
     lb_map = {}
     members = []
     # lb_scenari x lb_vip
     rows = db_manager.select(
         u"select pool.pool_id, vip.uuid from lb_scenario as pool, lb_vip as vip where pool.pool_id = vip.pool_id and pool.scid = '%s'"
         % self.scid)
     lb_map["pool"] = {}
     lb_map["pool"]["id"] = rows[0][0]
     lb_map["vip"] = {}
     lb_map["vip"]["id"] = rows[0][1]
     # lb_scenario x lb_member
     rows = db_manager.select(
         u"select member.uuid from lb_scenario as pool, lb_member as member where pool.pool_id = member.pool_id and pool.scid = '%s'"
         % self.scid)
     for member in rows:
         members.append({"id": member[0]})
     lb_map["members"] = members
     lb.lb_delete(lb_map)
     db_wrapper.delete_lb_scenario(lb_map["pool"]["id"])
     db_wrapper.delete_lb_vip(lb_map["pool"]["id"])
     db_wrapper.delete_lb_member(lb_map["pool"]["id"])
Ejemplo n.º 12
0
def scenario_list():
	senarios = os.listdir(os.path.abspath(os.path.dirname(__file__)) + "/../../scenario")
	rows=db_manager.select(u"select scenario from scenarios")
	ret=""
	tmp=[]
	for row in rows:
		tmp.append(row[0])
	for config in senarios:
		if len(rows) > 0:
			if config not in tmp:
				ret += """<li><span onclick="set_value('scenario','%s')"><a href="" onclick="return false;">%s</a></span></li>""" % (config, config)
		else:
			ret += """<li><span onclick="set_value('scenario','%s')"><a href="" onclick="return false;">%s</a></span></li>""" % (config, config)
	return ret
Ejemplo n.º 13
0
def show_lbaas(scid):
    ret = ""
    ret += """<table class="sample1" style="width:60%"><caption>LBaaS</caption><tr>"""
    ret += """<th>Method</th><th>Protocol</th><th>VIP</th><th>Member IP</th>"""
    # lb_scenari x lb_vip
    rows = db_manager.select(
        u"select pool.method, pool.protocol, vip.vip from lb_scenario as pool, lb_vip as vip where pool.pool_id = vip.pool_id and pool.scid = '%s'"
        % scid)
    method = rows[0][0]
    protocol = rows[0][1]
    vip = rows[0][2]
    # lb_scenario x lb_member
    rows = db_manager.select(
        u"select member.ip from lb_scenario as pool, lb_member as member where pool.pool_id = member.pool_id and pool.scid = '%s'"
        % scid)
    members = ""
    for member in rows:
        if len(members):
            members += "<br>"
        members += member[0]
    ret += """<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td>""" % (
        method, protocol, vip, members)
    ret += "</tr></table>"
    return ret
Ejemplo n.º 14
0
def scenario_list():
    senarios = os.listdir(
        os.path.abspath(os.path.dirname(__file__)) + "/../../scenario")
    rows = db_manager.select(u"select scenario from scenarios")
    ret = ""
    tmp = []
    for row in rows:
        tmp.append(row[0])
    for config in senarios:
        if len(rows) > 0:
            if config not in tmp:
                ret += """<li><span onclick="set_value('scenario','%s')"><a href="" onclick="return false;">%s</a></span></li>""" % (
                    config, config)
        else:
            ret += """<li><span onclick="set_value('scenario','%s')"><a href="" onclick="return false;">%s</a></span></li>""" % (
                config, config)
    return ret
Ejemplo n.º 15
0
def scenario_list():
        ret=""
        rows=db_manager.select(u"select sc.uuid, sc.scenario, sc.status, lb.pool_id from scenarios as sc left outer join lb_scenario lb on sc.uuid = lb.scid")
        for row in rows:
		scid = row[0]
		parameter = {"scid":scid, "lbaas":"True" if row[3] else "False"}
		ret += """<tr><td>%s</td>""" % (row[1])
		status=scenario_status(row[2])
		ret += """<td>%s""" % (status)
		if row[2] == 1:
			ret += "</td><td>%s%s%s%s%s</td>" % (get_btn_verify(parameter), get_btn_result(parameter),
						 get_btn_delete(parameter), get_btn_enviroment(parameter), get_btn_log(parameter))
		elif row[2] < 0:
			ret += "</td><td>%s%s%s%s%s</td>" % (get_btn_verify(None), get_btn_result(None),
						 get_btn_delete(parameter), get_btn_enviroment(parameter), get_btn_log(parameter))
		else:
			ret += """<br><progress max="100"></progress></td>"""
			ret += "</td><td>%s%s%s%s%s</td>" % (get_btn_verify(None), get_btn_result(None), get_btn_delete(None), get_btn_enviroment(None), get_btn_log(parameter))
		ret += """</tr>"""
        return ret
Ejemplo n.º 16
0
def start(req):
	base_path = os.path.abspath(os.path.dirname(__file__))
	form=req.GET
	rows=db_manager.select(u"select ip, netns from stacks where deleted = '0' and manager = '1' and scid = '" + form['scid'] + "'")
	if form['mode'] == 'verify':
		subprocess.call(['sudo', 'ip', 'netns', 'exec',
			rows[0][1],
			'/usr/bin/python', base_path + '/scenario_verify.py' , rows[0][0]])
		f=open(base_path + '/../template/redirect.tmpl')
		data=f.read()
		tmpl=Template(unicode(data, 'utf-8', 'ignore'))
		body=tmpl.substitute({'url':'index.py'})
		return HttpResponse(body)
	else:
#		ret=subprocess.call(['sudo', 'ip', 'netns', 'exec',
#			rows[0][1],
#			'/usr/bin/python', base_path + '/cgi-bin/scenario_result.py' , rows[0][0]])
#		ret = commands.getoutput('sudo ip netns exec ' + rows[0][1] + 
#				' /usr/bin/python ' + base_path + '/scenario_result.py ' + rows[0][0])
#		f=open(base_path + '/../template/result.tmpl')
#		data=f.read()
#		tmpl=Template(unicode(data, 'utf-8', 'ignore'))
#		body=tmpl.substitute({'result':ret})
		return HttpResponse(result(rows[0][1], rows[0][0]))
Ejemplo n.º 17
0
def get_netns(scid):
        rows=db_manager.select(u"select netns from stacks where scid='%s' and deleted=0 and manager=1" % scid)
	if len(rows):
		return rows[0][0]
	return '-'
Ejemplo n.º 18
0
def select_stacks():
	sql=u"select * from stacks"
	c=db_manager.select(sql)
	print c
	for row in c:
		print row[0], row[1], row[2], row[3], row[4], row[5]
Ejemplo n.º 19
0
def delete_stack(scenario):
        rows=db_manager.select(u"select uuid from stacks where deleted=0 and scenario='" + scenario + "'")
        for uuid in rows:
                os.system("heat stack-delete " + uuid[0])
                db_wrapper.delete_stack(uuid[0])
Ejemplo n.º 20
0
def select_stacks():
    sql = u"select * from stacks"
    c = db_manager.select(sql)
    print c
    for row in c:
        print row[0], row[1], row[2], row[3], row[4], row[5]