def del_port(self, switch_name_ovsdb, port_name): self.vtep_obj = vtep_command_manager() self.client = self.vtep_obj.connect_host('10.8.20.112', 'root', 'ubuntu') exec_unbind_cmd = 'cd /home/ubuntu;./vtep-ctl del-port %s %s' % ( switch_name_ovsdb, port_name) stdin, stdout, stderr = self.client.exec_command(exec_unbind_cmd)
def del_ucast_ovsdb(self,mac,ls_name,host_ip,user_name,password): vtep_obj = vtep_command_manager() client = vtep_obj.connect_host(str(host_ip),str(user_name),str(password)) exec_dells_cmd = 'cd /home/ubuntu;./vtep-ctl -p %s -c %s -C %s del-ucast-remote %s %s' % ( self.cer_pkey,self.cer_path,self.cer_base_path,ls_name,mac) self.log.info('Executing %s delete command on ovsdb' % (exec_dells_cmd)) stdin, stdout, stderr = client.exec_command(exec_dells_cmd.replace('\n','').strip())
def add_ucast_ovsdb(mac, ls_name, ip): vtep_obj = vtep_command_manager() print "ip is ", ip client = vtep_obj.connect_host('10.8.20.112', 'root', 'ubuntu') exec_addls_cmd = 'cd /home/ubuntu;./vtep-ctl add-ucast-remote %s %s %s' % ( ls_name, mac, ip) stdin, stdout, stderr = client.exec_command(exec_addls_cmd)
def unbind_ls(self, switch_name_ovsdb, port_name, ovs_vlan_list): self.vtep_obj = vtep_command_manager() self.client = self.vtep_obj.connect_host('10.8.20.112', 'root', 'ubuntu') for vlan in ovs_vlan_list: exec_unbind_cmd = 'cd /home/ubuntu;./vtep-ctl unbind-ls %s %s %s' % ( switch_name_ovsdb, port_name, vlan) stdin, stdout, stderr = self.client.exec_command(exec_unbind_cmd)
def unbind_ls(switch_name_ovsdb, port_name, ovs_vlan_list): vtep_obj = vtep_command_manager() client = vtep_obj.connect_host('10.8.20.112', 'root', 'ubuntu') for vlan in ovs_vlan_list: # import pdb;pdb.set_trace() exec_unbind_cmd = 'cd /home/ubuntu;./vtep-ctl unbind-ls %s %s %s' % ( switch_name_ovsdb, port_name, vlan) stdin, stdout, stderr = client.exec_command(exec_unbind_cmd)
def unbind_ls(self, switch_name_ovsdb, port_name, ovs_vlan_list,host_ip,user_name,password): self.vtep_obj = vtep_command_manager() self.client = self.vtep_obj.connect_host( str(host_ip),str(user_name),str(password)) self.log.info("Unbinding VLANS") for vlan in ovs_vlan_list: exec_unbind_cmd = 'cd /home/ubuntu;./vtep-ctl -p %s -c %s -C %s unbind-ls %s %s %s' % ( self.cer_pkey,self.cer_path,self.cer_base_path,switch_name_ovsdb, port_name, vlan) stdin, stdout, stderr = self.client.exec_command(exec_unbind_cmd.replace('\n','').strip()) self.log.info("Unbinded vlan for switch name :%s port_name: %s vlan: %s " % (switch_name_ovsdb, port_name, vlan))
def del_ucast_ovsdb(self, mac, ls_name, host_ip, user_name, password): vtep_obj = vtep_command_manager() client = vtep_obj.connect_host(str(host_ip), str(user_name), str(password)) exec_dells_cmd = 'cd /home/ubuntu;./vtep-ctl -p %s -c %s -C %s del-ucast-remote %s %s' % ( self.cer_pkey, self.cer_path, self.cer_base_path, ls_name, mac) self.log.info('Executing %s delete command on ovsdb' % (exec_dells_cmd)) stdin, stdout, stderr = client.exec_command( exec_dells_cmd.replace('\n', '').strip())
def bind_ls(switch_name_ovsdb, port_name, ovs_vlan_list, ls_dict): vtep_obj = vtep_command_manager() client = vtep_obj.connect_host('10.8.20.112', 'root', 'ubuntu') for vlan in ovs_vlan_list: for key in ls_dict.keys(): if vlan == key: ls_name = ls_dict[key].replace('\n', '') # import pdb;pdb.set_trace() exec_bind_cmd = 'cd /home/ubuntu;./vtep-ctl bind-ls %s %s %s %s' % ( switch_name_ovsdb, port_name.replace('\n', ''), vlan, ls_name) stdin, stdout, stderr = client.exec_command(exec_bind_cmd)
def add_ucast_ovsdb(self,mac,ls_name,ip,host_ip,user_name,password,status): vtep_obj = vtep_command_manager() client = vtep_obj.connect_host(str(host_ip),str(user_name),str(password)) self.log.info("Adding data to ucast ovsdb table ") try: socket.inet_aton(ip) exec_addls_cmd = 'cd /home/ubuntu;./vtep-ctl -p %s -c %s -C %s add-ucast-remote %s %s %s' % ( self.cer_pkey,self.cer_path,self.cer_base_path,ls_name,mac,ip) self.log.info('Executing %s add command on ovsdb' % (exec_addls_cmd)) stdin, stdout, stderr = client.exec_command(exec_addls_cmd.replace('\n','').strip()) except: status.append('False') sys.stdout.write("Invalid add_ucast_remote ip \n") self.log.info('Invalid add_ucast_remote_ip \n')
def get_ovsdb_data(self): mig_obj = MigrationScript() host_ip = '10.8.20.51' req_url = "http://%s:9696/v2.0/l2-gateways.json" % (host_ip) headers = mig_obj.get_headers() gw_list = requests.get(req_url, headers=headers) l2_gw_list = gw_list.text l2_gw_dict = json.loads(l2_gw_list) port_list = [] mapped_port_list = [] sw_list = [] spv = {} vtep_obj = vtep_command_manager() port_dict_bindings, switch_details = vtep_obj.get_ovsdb_bindings() return port_dict_bindings, switch_details
def unbind_ls(self, switch_name_ovsdb, port_name, ovs_vlan_list, host_ip, user_name, password): self.vtep_obj = vtep_command_manager() self.client = self.vtep_obj.connect_host(str(host_ip), str(user_name), str(password)) self.log.info("Unbinding VLANS") for vlan in ovs_vlan_list: exec_unbind_cmd = 'cd /home/ubuntu;./vtep-ctl -p %s -c %s -C %s unbind-ls %s %s %s' % ( self.cer_pkey, self.cer_path, self.cer_base_path, switch_name_ovsdb, port_name, vlan) stdin, stdout, stderr = self.client.exec_command( exec_unbind_cmd.replace('\n', '').strip()) self.log.info( "Unbinded vlan for switch name :%s port_name: %s vlan: %s " % (switch_name_ovsdb, port_name, vlan))
def add_ucast_ovsdb(self, mac, ls_name, ip, host_ip, user_name, password, status): vtep_obj = vtep_command_manager() client = vtep_obj.connect_host(str(host_ip), str(user_name), str(password)) self.log.info("Adding data to ucast ovsdb table ") try: socket.inet_aton(ip) exec_addls_cmd = 'cd /home/ubuntu;./vtep-ctl -p %s -c %s -C %s add-ucast-remote %s %s %s' % ( self.cer_pkey, self.cer_path, self.cer_base_path, ls_name, mac, ip) self.log.info('Executing %s add command on ovsdb' % (exec_addls_cmd)) stdin, stdout, stderr = client.exec_command( exec_addls_cmd.replace('\n', '').strip()) except: status.append('False') sys.stdout.write("Invalid add_ucast_remote ip \n") self.log.info('Invalid add_ucast_remote_ip \n')
with open(self.CREDS_FILE, 'rb') as fp: reader = csv.reader(fp, delimiter=',') for row in reader: if 'switch_ip' in row: continue else: creds_list.append(row) return creds_list except: sys.stdout.write("Error in reading csv file:", self.CREDS_FILE) if __name__ == '__main__': perfrest = PerformRestore() spv, prt_id_name_dict, ls_key_name_dict,ucast_mysql_dict,ls_id_dict = perfrest.fetch_t1_timestamp_data() vtep_obj = vtep_command_manager() creds_list = perfrest.get_ovsdb_creds() for cred_list in creds_list: ucast_status = False status = [] status.append('True') port_dict_bindings = [] switch_details = [] ucast_ovsdb_data = [] ls_ovsdb_data = [] try: host_ip = cred_list[0] socket.inet_aton(host_ip) user_name = cred_list[1] password = cred_list[2]
reader = csv.reader(fp, delimiter=',') for row in reader: if 'switch_ip' in row: continue else: creds_list.append(row) return creds_list except: sys.stdout.write("Error in reading csv file:", self.CREDS_FILE) if __name__ == '__main__': perfrest = PerformRestore() spv, prt_id_name_dict, ls_key_name_dict, ucast_mysql_dict, ls_id_dict = perfrest.fetch_t1_timestamp_data( ) vtep_obj = vtep_command_manager() creds_list = perfrest.get_ovsdb_creds() for cred_list in creds_list: ucast_status = False status = [] status.append('True') port_dict_bindings = [] switch_details = [] ucast_ovsdb_data = [] ls_ovsdb_data = [] try: host_ip = cred_list[0] socket.inet_aton(host_ip) user_name = cred_list[1] password = cred_list[2]