#__init__.py fromConfImportSettingsdefPack (): Response= {} forKvinchsettings. Plugins.items ():Importimportlib M_path,classname= V.rsplit ('.', Maxsplit=1) M=Importlib.import_module (m_path) CLS=getattr (m,classname) response[k]=CLS (). Execute ()returnResponse
#base.py fromConfImportSettingsclassBaseplugin (object):def __init__(self): mode_list= ['SSH','Salt',"Agent"] ifSettings. MODEinchMode_list:self.mode=settings. MODEElse: RaiseException ('configuration File Error') defssh (self,cmd):Pass defAgent (self,cmd):Pass defSalt (self,cmd):Pass defShell_cmd (self,cmd):ifSelf.mode = ='SSH': Ret=self.ssh (cmd)elifSelf.mode = ='Salt': Ret=self.salt (cmd)Else: Ret=self.agent (cmd)returnretdefExecute (self): ret= Self.shell_cmd ('View Platform Commands') ifRET = ='win': returnself.windows ()elifRET = ='Linux': returnSelf.linux ()Else: RaiseException ('support for Windows and Linux only') defLinux (self):RaiseException ('....') defwindows (self):RaiseException ('....')
#disk.py from. baseImportBasepluginclassDiskplugin (baseplugin):defwindows (self): output= Self.shell_cmd ('ipconfig') returnOutputdefLinux (self): output= Self.shell_cmd ('ifconfig') returnOutput#mem.py from. baseImportBasepluginclassMemplugin (baseplugin):defwindows (self): output= Self.shell_cmd ('asdf') #Regular Expressions returnOutputdefLinux (self): output= Self.shell_cmd ('asdf') #Regular Expressions returnOutput#nic.py from. baseImportBasepluginclassNicplugin (baseplugin):defwindows (self): output= Self.shell_cmd ('asdf') #Regular Expressions returnOutputdefLinux (self): output= Self.shell_cmd ('asdf') #Regular Expressions returnOutput
# settings.py " Agent " # Salt,ssh
02-cmdb acquisition Asset function plug-in development | CMDB