def node_create(): if args.gui: handle = SocketSend() handle.send_result(stor_action.create_node,args.node, args.ip, args.nodetype) elif args.node and args.nodetype and args.ip: stor_action.create_node(args.node, args.ip, args.nodetype) else: parser_create.print_help()
def case_show(self, args, js): # 读取所有json文档的数据 def judge_s(js): data = js.read_data_json() return data if args.json in ['json']: print(js.read_data_json()) handle = SocketSend() handle.send_result(judge_s, js) else: self.iscsi_show.print_help()
def create_diskless_resource(): list_diskless_forbid = [args.auto, args.num, args.storagepool, args.add_mirror,args.size] if not args.node: return if not any(list_diskless_forbid): if args.gui: handle = SocketSend() handle.send_result(stor_action.create_res_diskless,args.node, args.resource) return True else: stor_action.create_res_diskless(args.node, args.resource) return True
def storagepool_create(): if args.storagepool and args.node: if args.lvm: if args.gui: handle = SocketSend() handle.send_result(stor.create_storagepool_lvm, args.node, args.storagepool, args.lvm) else: stor.create_storagepool_lvm(args.node, args.storagepool, args.lvm) elif args.tlv: if args.gui: handle = SocketSend() handle.send_result(stor.create_storagepool_thinlv, args.node, args.storagepool, args.tlv) else: stor.create_storagepool_thinlv(args.node, args.storagepool, args.tlv) else: parser_create.print_help() else: parser_create.print_help()
def add_resource_mirror(): # 添加mirror禁止输入的参数 list_add_mirror_forbid = [args.diskless, args.size] if not args.add_mirror: return if any(list_add_mirror_forbid): return if all(list_auto_required) and not any(list_manual_required): #For GUI if args.gui: handle = SocketSend() handle.send_result(stor_action.add_mirror_auto,args.resource,args.num) return True else: stor_action.add_mirror_auto(args.resource,args.num) return True elif all(list_manual_required) and not any(list_auto_required): try: is_args_correct() except NodeLessThanSPError: print('The number of nodes does not meet the requirements') return True else: #For GUI if args.gui: handle = SocketSend() handle.send_result(stor_action.add_mirror_manual,args.resource,args.node,args.storagepool) return True else: stor_action.add_mirror_manual(args.resource,args.node,args.storagepool) return True
def stor_judge(self): args = self.args if args.vtel_sub == 'stor': if args.stor_sub in ['node', 'n']: self.case_node() elif args.stor_sub in ['resource', 'r']: self.case_resource() elif args.stor_sub in ['storagepool', 'sp']: self.case_storagepool() elif args.stor_sub in ['snap', 'sn']: self.case_snap() elif args.db: db = linstordb.LINSTORDB() handle = SocketSend() handle.send_result(db.data_base_dump) else: self.cmd.vtel_stor.print_help()
def create_normal_resource(): # 正常创建resource禁止输入的参数 list_normal_forbid = [args.diskless, args.add_mirror] if not args.size: return if any(list_normal_forbid): return try: is_vail_size(args.size) except InvalidSize: print('%s is not a valid size!' % args.size) sys.exit(0) else: pass if all(list_auto_required) and not any(list_manual_required): # For GUI if args.gui: handle = SocketSend() handle.send_result(stor.create_res_auto, args.resource, args.size, args.num) return True # CLI else: stor.create_res_auto(args.resource, args.size, args.num) return True elif all(list_manual_required) and not any(list_auto_required): try: is_args_correct() except NodeLessThanSPError: print( 'The number of nodes and storage pools do not meet the requirements' ) return True else: # For GUI if args.gui: handle = SocketSend() handle.send_result(stor.create_res_manual, args.resource, args.size, args.node, args.storagepool) return True # CLI else: stor.create_res_manual(args.resource, args.size, args.node, args.storagepool) return True
def iscsi_judge(self): js = JSON_OPERATION() args = self.args if args.iscsi in ['host', 'h']: if args.host in ['create', 'c']: if args.gui == 'gui': handle = SocketSend() handle.send_result(self.judge_hc, args, js) else: self.judge_hc(args, js) elif args.host in ['show', 's']: self.judge_hs(args, js) elif args.host in ['delete', 'd']: self.judge_hd(args, js) else: print("iscsi host (choose from 'create', 'show', 'delete')") self.cmd.iscsi_host.print_help() elif args.iscsi in ['disk', 'd']: if args.disk in ['show', 's']: self.judge_ds(args, js) else: print("iscsi disk (choose from 'show')") self.cmd.iscsi_disk.print_help() elif args.iscsi in ['hostgroup', 'hg']: if args.hostgroup in ['create', 'c']: if args.gui == 'gui': handle = SocketSend() handle.send_result(self.judge_hgc, args, js) else: self.judge_hgc(args, js) elif args.hostgroup in ['show', 's']: self.judge_hgs(args, js) elif args.hostgroup in ['delete', 'd']: self.judge_hgd(args, js) else: print( "iscsi hostgroup (choose from 'create', 'show', 'delete')") self.cmd.iscsi_hostgroup.print_help() elif args.iscsi in ['diskgroup', 'dg']: if args.diskgroup in ['create', 'c']: if args.gui == 'gui': handle = SocketSend() handle.send_result(self.judge_dgc, args, js) else: self.judge_dgc(args, js) elif args.diskgroup in ['show', 's']: self.judge_dgs(args, js) elif args.diskgroup in ['delete', 'd']: self.judge_dgd(args, js) else: print( "iscsi diskgroup (choose from 'create', 'show', 'delete')") self.cmd.iscsi_diskgroup.print_help() elif args.iscsi in ['map', 'm']: if args.map in ['create', 'c']: if args.gui == 'gui': handle = SocketSend() handle.send_result(self.judge_mc, args, js) else: self.judge_mc(args, js) elif args.map in ['show', 's']: self.judge_ms(args, js) elif args.map in ['delete', 'd']: self.judge_md(args, js) else: print("iscsi map (choose from 'create', 'show', 'delete')") self.cmd.iscsi_map.print_help() elif args.iscsi == 'show': print(js.read_data_json()) handle = SocketSend() handle.send_result(self.judge_s, js) else: print("iscsi (choose from 'host', 'disk', 'hg', 'dg', 'map')") self.cmd.vtel_iscsi.print_help()
def getdb(self): db = linstordb.LINSTORDB() handle = SocketSend() handle.send_result(db.data_base_dump) # get sql_scipt
def getdb(self): mes = SocketSend() mes.send_result(mes.sql_script)#get sql_scipt
def case_map(self, args, js): obj_map = iscsi_map() # map创建 def judge_mc(args, js): print("Map name:", args.mapname) print("Hostgroup name:", args.hg) print("Diskgroup name:", args.dg) if js.check_key('Map', args.mapname): print("The Map \"" + args.mapname + "\" already existed.") return False elif js.check_key('HostGroup', args.hg) == False: print("Can't find " + args.hg) return False elif js.check_key('DiskGroup', args.dg) == False: print("Can't find " + args.dg) return False else: if js.check_value('Map', args.dg) == True: print("The diskgroup already map") return False else: crmdata = obj_map.crm_up(js) if crmdata: mapdata = obj_map.map_data(js, crmdata, args.hg, args.dg) if obj_map.map_crm_c(mapdata): js.creat_data('Map', args.mapname, [args.hg, args.dg]) print("Create success!") return True else: return False else: return False # map查询 def judge_ms(args, js): crmdata = obj_map.crm_up(js) if args.show == 'all' or args.show == None: print("Map:") maps = js.get_data("Map") for k in maps: print(" " + "---------------") print(" " + k + ":") for v in maps[k]: print(" " + v) else: if js.check_key('Map', args.show): print(args.show + ":") maplist = js.get_data('Map').get(args.show) print(' ' + maplist[0] + ':') for i in js.get_data('HostGroup').get(maplist[0]): print(' ' + i + ': ' + js.get_data('Host').get(i)) print(' ' + maplist[1] + ':') for i in js.get_data('DiskGroup').get(maplist[1]): print(' ' + i + ': ' + js.get_data('Disk').get(i)) else: print("Fail! Can't find " + args.show) # map删除 def judge_md(args, js): print("Delete the map <", args.mapname, ">...") if js.check_key('Map', args.mapname): print( js.get_data('Map').get(args.mapname), "will probably be affected ") resname = obj_map.map_data_d(js, args.mapname) if obj_map.map_crm_d(resname): js.delete_data('Map', args.mapname) print("Delete success!") else: print("Fail! Can't find " + args.mapname) # map判断 if args.map in ['create', 'c']: if args.gui == 'gui': handle = SocketSend() handle.send_result(judge_mc, args, js) else: judge_mc(args, js) elif args.map in ['show', 's']: judge_ms(args, js) elif args.map in ['delete', 'd']: judge_md(args, js) else: print("iscsi map (choose from 'create', 'show', 'delete')") self.iscsi_map.print_help()
def case_diskgroup(self, args, js): # diskgroup创建 def judge_dgc(args, js): print("Diskgroup name:", args.diskgroupname) print("Disk name:", args.diskname) if js.check_key('DiskGroup', args.diskgroupname): print("Fail! The DiskGroup " + args.diskgroupname + " already existed.") return False else: t = True for i in args.diskname: if js.check_key('Disk', i) == False: t = False print("Fail! Can't find " + i) if t: js.creat_data('DiskGroup', args.diskgroupname, args.diskname) print("Create success!") return True else: print("Fail! Please give the true name.") return False # diskgroup查询 def judge_dgs(args, js): if args.show == 'all' or args.show == None: print("Diskgroup:") diskgroups = js.get_data("DiskGroup") for k in diskgroups: print(" " + "---------------") print(" " + k + ":") for v in diskgroups[k]: print(" " + v) else: if js.check_key('DiskGroup', args.show): print(args.show + ":") for k in js.get_data('DiskGroup').get(args.show): print(" " + k) else: print("Fail! Can't find " + args.show) # diskgroup删除 def judge_dgd(args, js): print("Delete the diskgroup <", args.diskgroupname, "> ...") if js.check_key('DiskGroup', args.diskgroupname): if js.check_value('Map', args.diskgroupname): print( "Fail! The diskgroup already map,Please delete the map" ) else: js.delete_data('DiskGroup', args.diskgroupname) print("Delete success!") else: print("Fail! Can't find " + args.diskgroupname) # diskgroup判断 if args.diskgroup in ['create', 'c']: if args.gui == 'gui': handle = SocketSend() handle.send_result(judge_dgc, args, js) else: judge_dgc(args, js) elif args.diskgroup in ['show', 's']: judge_dgs(args, js) elif args.diskgroup in ['delete', 'd']: judge_dgd(args, js) else: print("iscsi diskgroup (choose from 'create', 'show', 'delete')") self.iscsi_diskgroup.print_help()
def case_host(self, args, js): # host创建 def judge_hc(args, js): print("Host name:", args.iqnname) print("iqn:", args.iqn) if js.check_key('Host', args.iqnname): print("Fail! The Host " + args.iqnname + " already existed.") return False else: js.creat_data("Host", args.iqnname, args.iqn) print("Create success!") return True # host查询 def judge_hs(args, js): if args.show == 'all' or args.show == None: hosts = js.get_data("Host") print(" " + "{:<15}".format("Hostname") + "Iqn") print(" " + "{:<15}".format("---------------") + "---------------") for k in hosts: print(" " + "{:<15}".format(k) + hosts[k]) else: if js.check_key('Host', args.show): print(args.show, ":", js.get_data('Host').get(args.show)) else: print("Fail! Can't find " + args.show) return False return True # host删除 def judge_hd(args, js): print("Delete the host <", args.iqnname, "> ...") if js.check_key('Host', args.iqnname): if js.check_value('HostGroup', args.iqnname): print( "Fail! The host in ... hostgroup, Please delete the hostgroup first." ) return False else: js.delete_data('Host', args.iqnname) print("Delete success!") return True else: print("Fail! Can't find " + args.iqnname) return False # host判断 if args.host in ['create', 'c']: if args.gui == 'gui': handle = SocketSend() handle.send_result(judge_hc, args, js) else: judge_hc(args, js) elif args.host in ['show', 's']: judge_hs(args, js) elif args.host in ['delete', 'd']: judge_hd(args, js) else: print("iscsi host (choose from 'create', 'show', 'delete')") self.iscsi_host.print_help()