def getSubOperations(self,cmd,operation):
     import commandConfigure
     _rds = commandConfigure.rds()
     operations = None
     if cmd.lower() == 'rds' and operation.lower() ==_rds.importDBInstance.lower():
         operations = ['CreateDBInstance']
     return operations 
 def exportDBInstance(self, cmd, operation, version):
     rdsConfigure = commandConfigure.rds()
     if cmd.lower() == rdsConfigure.cmdName.lower() and operation.lower() ==rdsConfigure.exportDBInstance.lower():
         pass
     else :
         return None
     _keyValues = self.parser.getCliKeyValues()
     filename, errorMsg = self.getFileName(_keyValues)
     if filename is None:
         import cliError
         errorClass = cliError.error()
         errorClass.printInFormat(errorClass.CliException, errorMsg)
         return
     operation = self.operations[0]
     if self.apiHandler.isAvailableOperation(cmd, operation, version):
         cmdInstance, mclassname = self.apiHandler.getInstanceByCmdOperation(cmd, operation, version)
         if not cmdInstance is None:
             newkeyValues = self.parser.getOpenApiKeyValues(_keyValues)
             if self.apiHandler.needSetDefaultRegion(cmdInstance, newkeyValues):
                 newkeyValues["RegionId"] = [self.extensionHandler.getUserRegion()]
             self.apiHandler.setAttr(cmdInstance, newkeyValues) # set all key values in instance
             self.apiHandler.changeEndPoint(cmdInstance, newkeyValues)
             try:
                 result = self.apiHandler.getResponse(cmd,operation, mclassname, cmdInstance, newkeyValues)
                 # result = cmdInstance.getResponse()
                 # result = self._optimizeResult(result)
                 if("Code" in result):
                     response.display_response("error", result, "json")
                 else:
                     if not filename == None:
                         self.exportInstanceToFile(result,filename)
                     else:
                         print 'Filename is needed'
             except Exception,e:
                 print(e)
 def getSubOperations(self,cmd,operation):
     import commandConfigure
     _rds = commandConfigure.rds()
     operations = None
     if cmd.lower() == 'rds' and operation.lower() ==_rds.importDBInstance.lower():
         operations = ['CreateDBInstance']
     return operations 
Exemple #4
0
    def handlerExtensionOperation(self,cmd,operation,version):
        defaultOperations=['configversion','showversions']
        if operation.lower() in defaultOperations:
            import aliyunSdkConfigure
            aliyunSdkConfigure.handleSdkVersion(cmd,operation,version)
        if cmd.lower() == 'ecs':
            import commandConfigure
            import advance.ecsExportHandler
            import advance.ecsImportHandler
            ecsConfigure = commandConfigure.ecs()
            _ecsImportHandler = advance.ecsImportHandler.EcsImportHandler()
            _ecsExportHandler = advance.ecsExportHandler.EcsExportHandler()
            if  operation.lower() == ecsConfigure.importInstance.lower():
                _ecsImportHandler.ImportInstance(cmd,operation,version)
            elif operation.lower() == ecsConfigure.exportInstance.lower():
                _ecsExportHandler.exportInstance(cmd,operation,version)

        if cmd.lower() == 'rds':
            import commandConfigure
            import advance.rdsExportHandler
            import advance.rdsImportHandler
            rdsConfigure = commandConfigure.rds()
            rdsExportDBInstanceHandler = advance.rdsExportHandler.RdsExportDBInstanceHanlder()
            rdsImportDBInstanceHanlder = advance.rdsImportHandler.RdsImportDBInstanceHandler()
            if operation.lower() == rdsConfigure.exportDBInstance.lower():
                rdsExportDBInstanceHandler.exportDBInstance(cmd,operation,version)
            elif operation.lower() == rdsConfigure.importDBInstance.lower():
                rdsImportDBInstanceHanlder.importInstance(cmd, operation, version)
Exemple #5
0
 def getExtensionOperationsFromCmdLower(self, cmd):
     if cmd is None:
         return None
     defaultExtensionOpers=set(['configversion','showversions'])
     if cmd.lower() == "ecs":
         ecsExtensionOpers=set(['exportinstance', 'importinstance'])
         defaultExtensionOpers.update(ecsExtensionOpers)
     if cmd.lower() == "rds":
         rdsConfigure = commandConfigure.rds()
         rdsExtensionOpers = set()
         for item in rdsConfigure.extensionOperations:
             rdsExtensionOpers.add(item.lower())
         defaultExtensionOpers.update(rdsExtensionOpers)
     return defaultExtensionOpers
Exemple #6
0
 def getExtensionOperationsFromCmd(self, cmd):
     if cmd is None:
         return None
     defaultExtensionOpers=set(['ConfigVersion','ShowVersions'])
     if cmd.lower() == "ecs":
         ecsConfigure = commandConfigure.ecs()
         cmdSet = set()
         for item in ecsConfigure.extensionOperations:
             cmdSet.add(item)
         defaultExtensionOpers.update(cmdSet)
     if cmd.lower() == "rds":
         rdsConfigure = commandConfigure.rds()
         cmdSet = set()
         for item in rdsConfigure.extensionOperations:
             cmdSet.add(item)
         defaultExtensionOpers.update(cmdSet)
     return defaultExtensionOpers
 def exportDBInstance(self, cmd, operation, version):
     rdsConfigure = commandConfigure.rds()
     if cmd.lower() == rdsConfigure.cmdName.lower() and operation.lower(
     ) == rdsConfigure.exportDBInstance.lower():
         pass
     else:
         return None
     _keyValues = self.parser.getCliKeyValues()
     filename, errorMsg = self.getFileName(_keyValues)
     if filename is None:
         import cliError
         errorClass = cliError.error()
         errorClass.printInFormat(errorClass.CliException, errorMsg)
         return
     operation = self.operations[0]
     if self.apiHandler.isAvailableOperation(cmd, operation, version):
         cmdInstance, mclassname = self.apiHandler.getInstanceByCmdOperation(
             cmd, operation, version)
         if not cmdInstance is None:
             newkeyValues = self.parser.getOpenApiKeyValues(_keyValues)
             if self.apiHandler.needSetDefaultRegion(
                     cmdInstance, newkeyValues):
                 newkeyValues["RegionId"] = [
                     self.extensionHandler.getUserRegion()
                 ]
             self.apiHandler.setAttr(
                 cmdInstance,
                 newkeyValues)  # set all key values in instance
             self.apiHandler.changeEndPoint(cmdInstance, newkeyValues)
             try:
                 result = self.apiHandler.getResponse(
                     cmd, operation, mclassname, cmdInstance, newkeyValues)
                 self.apiHandler.responseOptimize(result, cmd, operation)
                 # result = cmdInstance.getResponse()
                 # result = self._optimizeResult(result)
                 if ("Code" in result):
                     response.display_response("error", result, "json")
                 else:
                     if not filename == None:
                         self.exportInstanceToFile(result, filename)
                     else:
                         print 'Filename is needed'
             except Exception, e:
                 print(e)
Exemple #8
0
 def showOperationError(self, cmd, operation):
     keyValues=self.openApiDataHandler.parser._getKeyValues()
     version = self.openApiDataHandler.getSdkVersion(cmd,keyValues)
     versions=self.openApiDataHandler.getAllVersionsByCmdName(cmd)
     if version not in versions:
             error = cliError.error()
             error.printInFormat("Wrong version", "The sdk version is not exit.")
             return None
     self.showUsage()
     print "["+cmd+"]","valid operations as follows:\n"
     operations = self.openApiDataHandler.getApiOperations(cmd, version)
     extensions = self.openApiDataHandler.getExtensionOperationsFromCmd(cmd)
     operations.update(extensions)
     import commandConfigure
     if cmd.lower() == 'rds':
         rdsConfigure = commandConfigure.rds()
         operations.add(rdsConfigure.exportDBInstance)
         operations.add(rdsConfigure.importDBInstance)
     self.printAsFormat(operations)
Exemple #9
0
 def showOperationError(self, cmd, operation):
     keyValues = self.openApiDataHandler.parser._getKeyValues()
     version = self.openApiDataHandler.getSdkVersion(cmd, keyValues)
     versions = self.openApiDataHandler.getAllVersionsByCmdName(cmd)
     if version not in versions:
         error = cliError.error()
         error.printInFormat("Wrong version",
                             "The sdk version is not exit.")
         return None
     self.showUsage()
     print "[" + cmd + "]", "valid operations as follows:\n"
     operations = self.openApiDataHandler.getApiOperations(cmd, version)
     extensions = self.openApiDataHandler.getExtensionOperationsFromCmd(cmd)
     operations.update(extensions)
     import commandConfigure
     if cmd.lower() == 'rds':
         rdsConfigure = commandConfigure.rds()
         operations.add(rdsConfigure.exportDBInstance)
         operations.add(rdsConfigure.importDBInstance)
     self.printAsFormat(operations)