def manage_ports(self, tgt_box_ip, tgt_ovsdb_pt, brname, ptcfg, exptcfg=None): if not exptcfg: ## if there is no ports in the box for pt in ptcfg: self.create_port(tgt_box_ip, tgt_ovsdb_pt, brname, pt) else: for pt in ptcfg: ptname = pt["name"] pttype = pt["type"] expt = None for tmp in exptcfg: if tmp["Port"] != ptname: continue expt = tmp break if expt: ## if same port already exist optstr = "" if "type" not in expt or expt["type"] != pttype: optstr = optstr + " type=" + expt["type"] if "options" in pt: if "options" not in expt: for i in pt["options"].keys(): optstr = optstr + " options:" + i + "=" + pt["options"][i] else: for i in pt["options"].keys(): if i not in expt["options"] or expt["options"][i] != pt["options"][i]: optstr = optstr + " options:" + i + "=" + pt["options"][i] iface.ovs_vsctl_set_interface(tgt_box_ip, tgt_ovsdb_pt, ptname, optstr) else: self.create_port(tgt_box_ip, tgt_ovsdb_pt, brname, pt) return
def create_port(self, tgt_box_ip, tgt_ovsdb_pt, brname, pt): ptname = pt["name"] pttype = pt["type"] if "options" in pt: ptopt = pt["options"] else: ptopt = None optstr = "" iface.ovs_vsctl_add_port(tgt_box_ip, tgt_ovsdb_pt, brname, ptname) optstr = optstr + "type=" + pttype if ptopt: if "remote_ip" in ptopt and pttype == "vxlan" or pttype == "gre": optstr = optstr + " options:df_default=true options:in_key=flow optios:out_key=flow options:local_ip=" + self.tgtipaddr + " options:remote_ip=" + \ ptopt["remote_ip"] else: for i in ptopt.keys(): optstr = optstr + " options:" + i + "=" + ptopt[i] iface.ovs_vsctl_set_interface(tgt_box_ip, tgt_ovsdb_pt, ptname, optstr) return
def manage_tunnel(self, tgt_tnl_dict, ex_br_dicts): print tgt_tnl_dict try: tnl_br_name = tgt_tnl_dict["bridge"] ex_br_dict = ex_br_dicts[tnl_br_name] except ValueError as e: print e return if "Ports" in ex_br_dict: ex_pt_list_in_br = ex_br_dict["Ports"] else: ex_pt_list_in_br = [] ex_pt_dict = {} for ex_pt in ex_pt_list_in_br: if "Port" in ex_pt: if tgt_tnl_dict["name"] == ex_pt["Port"]: ex_pt_dict = ex_pt break else: continue if ex_pt_dict is not None: optstr = "" if "type" not in ex_pt_dict["type"] or ex_pt_dict["type"] != tgt_tnl_dict["name"]: optstr = optstr + " type=" + ex_pt_dict["type"] if "options" in tgt_tnl_dict: if "options" in ex_pt_dict: for i in tgt_tnl_dict["options"].keys(): optstr = optstr + " options:" + i + "=" + tgt_tnl_dict["options"][i] else: for i in tgt_tnl_dict["options"].keys(): if i not in ex_pt_dict["options"] or ex_pt_dict["options"][i] != tgt_tnl_dict["options"][i]: optstr = optstr + " options:" + i + "=" + tgt_tnl_dict["options"][i] iface.ovs_vsctl_set_interface(self.tgt_box_ip, self.tgt_box_pt, tgt_tnl_dict["name"])