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 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 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 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 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 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 GetPublishSelections(arguments): yamlData = SwarmTools.LoadYamlDataFromFiles( arguments, BuildTools.DEFAULT_BUILD_MANAGEMENT_YAML_FILES) publishProperty = YamlTools.GetProperties(PUBLISH_KEY, yamlData) if BuildTools.SELECTIONS_KEY in publishProperty: return publishProperty[BuildTools.SELECTIONS_KEY] return {}
def GetTestSelections(arguments): yamlData = SwarmTools.LoadYamlDataFromFiles( arguments, BuildTools.DEFAULT_BUILD_MANAGEMENT_YAML_FILES) testProperty = YamlTools.GetProperties(TEST_KEY, yamlData) if BuildTools.SELECTIONS_KEY in testProperty: return testProperty[BuildTools.SELECTIONS_KEY] return {}
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 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 HandleManagement(arguments): if len(arguments) == 0: print(GetInfoMsg()) return if '-help' in arguments and len(arguments) == 1: print(GetInfoMsg()) return SwarmTools.LoadEnvironmentVariables( arguments, [BuildTools.DEFAULT_BUILD_MANAGEMENT_YAML_FILE]) SwarmTools.HandleDumpYamlData( arguments, [BuildTools.DEFAULT_BUILD_MANAGEMENT_YAML_FILE]) ChangelogSelections.HandleChangelogSelections(arguments) SwarmSelections.HandleSwarmSelections(arguments) BuildSelections.HandleBuildSelections(arguments) TestSelections.HandleTestSelections(arguments) RunSelections.HandleRunSelections(arguments) PublishSelections.HandlePublishSelections(arguments)
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 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 ExposeEnvironmentVariables(envVariables: [], swmInfrastructureFiles: []): for envVariable in envVariables: if not('=' in envVariable): warnings.warn('Cannot parse environment variable {0}. It should be of form <envKey>=<envValue>'.format(envVariable)) else: key = envVariable.split('=')[0] value = envVariable.split('=')[1] os.environ[key] = value if __CheckSwarmManagementYamlFileExists(yamlFiles=swmInfrastructureFiles): arguments = __GetSwarmManagementArgumentsWithInfrastructureFiles(swmInfrastructureFiles) SwarmTools.LoadEnvironmentVariables(arguments=arguments) if os.path.isfile('.env'): load_dotenv('.env')
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 GetInfoMsg(): infoMsg = "Manage Docker Swarm\r\n" infoMsg += "Add '-start' to arguments to start swarm with all stacks deployed and properties created (networks, secrets, configs..).\r\n" infoMsg += "Add '-stop' to arguments to stop swarm with all stacks and properties removed.\r\n" infoMsg += "Add '-restart' to arguments to restart swarm.\r\n" infoMsg += "Otherwise:\r\n\r\n" infoMsg += "Deploy Or Remove Stacks:\r\n" infoMsg += SwarmStacks.GetInfoMsg() + "\r\n\r\n" infoMsg += "Create Or Remove Networks:\r\n" infoMsg += SwarmNetworks.GetInfoMsg() + "\r\n\r\n" infoMsg += "Create Or Remove Configs:\r\n" infoMsg += SwarmConfigs.GetInfoMsg() + "\r\n\r\n" infoMsg += "Create Or Remove Secrets:\r\n" infoMsg += SwarmSecrets.GetInfoMsg() + "\r\n\r\n" infoMsg += "Create Or Remove Volumes:\r\n" infoMsg += SwarmVolumes.GetInfoMsg() + "\r\n\r\n" infoMsg += "Additional Info:\r\n" infoMsg += SwarmTools.GetInfoMsg() + "\r\n\r\n" infoMsg += "Add '-help' to arguments to print this info again.\r\n\r\n" return infoMsg
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 GetVolumes(arguments): yamlData = SwarmTools.LoadYamlDataFromFiles(arguments) return YamlTools.GetProperties('volumes', yamlData)
def GetChangelogSelection(arguments): yamlData = SwarmTools.LoadYamlDataFromFiles( arguments, [BuildTools.DEFAULT_BUILD_MANAGEMENT_YAML_FILE]) return SwarmTools.GetProperties(arguments, CHANGELOG_KEY, GetInfoMsg(), yamlData)
def test_getInforMsg_success(self): self.assertIsNotNone(SwarmTools.GetInfoMsg())
def GetStacks(arguments): yamlData = SwarmTools.LoadYamlDataFromFiles(arguments) return YamlTools.GetProperties('stacks', yamlData)
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]
def GetConfigs(arguments): yamlData = SwarmTools.LoadYamlDataFromFiles(arguments) return YamlTools.GetProperties('configs', yamlData)