def HandleSwarmSelections(arguments): if len(arguments) == 0: return if not (CheckSwarmInArguments(arguments)) and not ( CheckSwarmCommandInArguments(arguments)): return if '-help' in arguments: print(GetInfoMsg()) return if CheckSwarmInArguments(arguments) and not ( CheckSwarmCommandInArguments(arguments)): print(GetInfoMsg()) swarmSelectionsToDeploy = SwarmTools.GetArgumentValues(arguments, '-swarm') swarmSelectionsToDeploy += SwarmTools.GetArgumentValues(arguments, '-s') if not (CheckSwarmInArguments(arguments)) and CheckSwarmCommandInArguments( arguments): swarmSelectionsToDeploy += SwarmTools.GetArgumentValues( arguments, '-start') swarmSelectionsToDeploy += SwarmTools.GetArgumentValues( arguments, '-stop') swarmSelectionsToDeploy += SwarmTools.GetArgumentValues( arguments, '-restart') swarmSelections = GetSwarmSelections(arguments) DeploySwarmSelections(swarmSelectionsToDeploy, swarmSelections, GetSwarmCommand(arguments))
def GetDockerBuildManagementYamlData(arguments): yamlFiles = SwarmTools.GetArgumentValues(arguments, '-file') yamlFiles += SwarmTools.GetArgumentValues(arguments, '-f') if len(yamlFiles) == 0: yamlFiles.append('build-management.yml') yamlData = SwarmTools.GetYamlData(yamlFiles) return yamlData
def test_getArgumentValues_common_selections(self): selections = ['selection1', 'selection2', 'selection3'] arguments = ['-run'] + ['-build'] + selections print(arguments) selectedRuns = SwarmTools.GetArgumentValues(arguments, '-run') selectedBuilds = SwarmTools.GetArgumentValues(arguments, '-build') print(selectedRuns) print(selectedBuilds) self.assertEqual(len(selections), len(selectedRuns)) self.assertListEqual(selections, selectedRuns) self.assertEqual(len(selections), len(selectedBuilds)) self.assertListEqual(selections, selectedBuilds)
def test_getArgumentValues_specific_selections(self): runSelections = ['run1', 'run2', 'run3'] buildSelections = ['build1', 'build2'] arguments = ['-run'] + runSelections + ['-build'] + buildSelections print(arguments) selectedRuns = SwarmTools.GetArgumentValues(arguments, '-run') selectedBuilds = SwarmTools.GetArgumentValues(arguments, '-build') print(selectedRuns) print(selectedBuilds) self.assertEqual(len(runSelections), len(selectedRuns)) self.assertEqual(len(buildSelections), len(selectedBuilds)) self.assertListEqual(runSelections, selectedRuns) self.assertListEqual(buildSelections, selectedBuilds)
def HandleBuildSelections(arguments): if len(arguments) == 0: return if not('-build' in arguments): return if '-help' in arguments: print(GetInfoMsg()) return selectionsToBuild = SwarmTools.GetArgumentValues(arguments, '-build') selectionsToBuild += SwarmTools.GetArgumentValues(arguments, '-b') buildSelections = GetBuildSelections(arguments) BuildSelections(selectionsToBuild, buildSelections)
def HandleRunSelections(arguments): if len(arguments) == 0: return if not ('-run' in arguments): return if '-help' in arguments: print(GetInfoMsg()) return selectionsToRun = SwarmTools.GetArgumentValues(arguments, '-run') selectionsToRun += SwarmTools.GetArgumentValues(arguments, '-r') runSelections = GetRunSelections(arguments) RunSelections(selectionsToRun, runSelections)
def HandleSwarmSelections(arguments): if len(arguments) == 0: return if not('-start' in arguments or '-stop' in arguments or '-restart' in arguments or '-swarm' in arguments): return if '-help' in arguments: print(GetInfoMsg()) return swarmSelectionsToDeploy = SwarmTools.GetArgumentValues(arguments, '-swarm') swarmSelectionsToDeploy += SwarmTools.GetArgumentValues(arguments, '-s') swarmSelections = GetSwarmSelections(arguments) DeploySwarmSelections(swarmSelectionsToDeploy, swarmSelections, GetPrefix(arguments))
def HandlePromoteSelections(arguments): if len(arguments) == 0: return if not ('-promote' in arguments): return if '-help' in arguments: print(GetInfoMsg()) return selectionsToPromote = SwarmTools.GetArgumentValues(arguments, '-promote') selectionsToPromote += SwarmTools.GetArgumentValues(arguments, '-pr') promoteSelections = GetPromoteSelections(arguments) PromoteSelections(selectionsToPromote, promoteSelections)
def HandlePublishSelections(arguments): if len(arguments) == 0: return if not ('-publish' in arguments): return if '-help' in arguments: print(GetInfoMsg()) return selectionsToPublish = SwarmTools.GetArgumentValues(arguments, '-publish') selectionsToPublish += SwarmTools.GetArgumentValues(arguments, '-p') publishSelections = GetPublishSelections(arguments) PublishSelections(selectionsToPublish, publishSelections)
def HandleTestSelections(arguments): if len(arguments) == 0: return if not ('-test' in arguments): return if '-help' in arguments: print(GetInfoMsg()) return selectionsToTest = SwarmTools.GetArgumentValues(arguments, '-test') selectionsToTest += SwarmTools.GetArgumentValues(arguments, '-t') testSelections = GetTestSelections(arguments) TestSelections(selectionsToTest, testSelections)
def GetAllowMissingCertificateFilePathFromArguments(arguments): argValues = SwarmTools.GetArgumentValues( arguments, '-allowMissingCertificateFilePath') if len(argValues) == 0: return False value = str.lower(argValues[0]) return value == "true" or value == "1" or value == "on" or value == "yes" or value == "enabled"
def RestartSwarm(arguments): StopSwarm(arguments) secTimeout = 10 restartArguments = SwarmTools.GetArgumentValues(arguments, '-restart') if len(restartArguments) > 0 and restartArguments[0].isdigit(): secTimeout = int(restartArguments[0]) SwarmTools.TimeoutCounter(secTimeout) StartSwarm(arguments)
def HandleConfigs(arguments): if len(arguments) == 0: return if not ('-config' in arguments): return if '-help' in arguments: print(GetInfoMsg()) return configsToCreate = SwarmTools.GetArgumentValues(arguments, '-create') configsToCreate += SwarmTools.GetArgumentValues(arguments, '-c') configsToRemove = SwarmTools.GetArgumentValues(arguments, '-remove') configsToRemove += SwarmTools.GetArgumentValues(arguments, '-rm') configs = GetConfigs(arguments) CreateConfigs(configsToCreate, configs) RemoveConfigs(configsToRemove, configs)
def HandleSecrets(arguments): if len(arguments) == 0: return if not ('-secret' in arguments): return if '-help' in arguments: print(GetInfoMsg()) return secretsToCreate = SwarmTools.GetArgumentValues(arguments, '-create') secretsToCreate += SwarmTools.GetArgumentValues(arguments, '-c') secretsToRemove = SwarmTools.GetArgumentValues(arguments, '-remove') secretsToRemove += SwarmTools.GetArgumentValues(arguments, '-rm') secrets = GetSecrets(arguments) CreateSecrets(secretsToCreate, secrets) RemoveSecrets(secretsToRemove, secrets)
def HandleNetworks(arguments): if len(arguments) == 0: return if not ('-network' in arguments): return if '-help' in arguments: print(GetInfoMsg()) return networksToCreate = SwarmTools.GetArgumentValues(arguments, '-create') networksToCreate += SwarmTools.GetArgumentValues(arguments, '-c') networksToRemove = SwarmTools.GetArgumentValues(arguments, '-remove') networksToRemove += SwarmTools.GetArgumentValues(arguments, '-rm') networks = GetNetworks(arguments) CreateNetworks(networksToCreate, networks) RemoveNetworks(networksToRemove, networks)
def HandleVolumes(arguments): if len(arguments) == 0: return if not ('-volume' in arguments): return if '-help' in arguments: print(GetInfoMsg()) return volumesToCreate = SwarmTools.GetArgumentValues(arguments, '-create') volumesToCreate += SwarmTools.GetArgumentValues(arguments, '-c') volumesToRemove = SwarmTools.GetArgumentValues(arguments, '-remove') volumesToRemove += SwarmTools.GetArgumentValues(arguments, '-rm') volumes = GetVolumes(arguments) CreateVolumes(volumesToCreate, volumes) RemoveVolumes(volumesToRemove, volumes)
def HandleStacks(arguments): if len(arguments) == 0: return if not ('-stack' in arguments): return if '-help' in arguments: print(GetInfoMsg()) return stacksToDeploy = SwarmTools.GetArgumentValues(arguments, '-deploy') stacksToDeploy += SwarmTools.GetArgumentValues(arguments, '-d') stacksToRemove = SwarmTools.GetArgumentValues(arguments, '-remove') stacksToRemove += SwarmTools.GetArgumentValues(arguments, '-rm') stacks = GetStacks(arguments) yamlData = SwarmTools.LoadYamlDataFromFiles(arguments) environmentFiles = SwarmTools.GetEnvironmnetVariablesFiles( arguments, yamlData) DeployStacks(stacksToDeploy, stacks, environmentFiles) RemoveStacks(stacksToRemove, stacks)
def GetPositionalActionArguments(arguments, index): actionArgs = [] newIndex = index + 1 if arguments[index].startswith('-'): actionArgs.append(arguments[index]) if SwarmSelections.CheckSwarmInArguments(actionArgs) \ and index + 1 < len(arguments) \ and SwarmSelections.CheckSwarmCommandInArguments([arguments[index + 1]]): actionArgs.append(arguments[index + 1]) newIndex += 1 if len(actionArgs) > 0: selections = SwarmTools.GetArgumentValues(arguments[index:], actionArgs[-1]) actionArgs += selections return actionArgs, newIndex
def GetPackageInputUnsignedFolderFromArguments(arguments): argValues = SwarmTools.GetArgumentValues(arguments, '-packageInputUnsignedFolder') if len(argValues) == 0: return PACKAGE_INPUT_UNSIGNED_FOLDER return argValues[0]
def GetPackageOutputSignedFolderFromArguments(arguments): argValues = SwarmTools.GetArgumentValues(arguments, '-packageOutputSignedFolder') if len(argValues) == 0: return PACKAGE_OUTPUT_SIGNED_FOLDER return argValues[0]
def GetCertificatePathFromArguments(arguments): certificates = SwarmTools.GetArgumentValues(arguments, '-c') if len(certificates) == 0: return CERTIFICATE_FILE_PATH return certificates[0]
def GetPasswordFromArguments(arguments): passwords = SwarmTools.GetArgumentValues(arguments, '-p') if len(passwords) == 0: return 'xxxx' return passwords[0]