Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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))
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 7
0
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"
Ejemplo n.º 8
0
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 {}
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
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))
Ejemplo n.º 16
0
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')
Ejemplo n.º 17
0
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
Ejemplo n.º 18
0
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
Ejemplo n.º 19
0
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)
Ejemplo n.º 20
0
def GetVolumes(arguments):
    yamlData = SwarmTools.LoadYamlDataFromFiles(arguments)
    return YamlTools.GetProperties('volumes', yamlData)
Ejemplo n.º 21
0
def GetChangelogSelection(arguments):
    yamlData = SwarmTools.LoadYamlDataFromFiles(
        arguments, [BuildTools.DEFAULT_BUILD_MANAGEMENT_YAML_FILE])
    return SwarmTools.GetProperties(arguments, CHANGELOG_KEY, GetInfoMsg(),
                                    yamlData)
Ejemplo n.º 22
0
 def test_getInforMsg_success(self):
     self.assertIsNotNone(SwarmTools.GetInfoMsg())
Ejemplo n.º 23
0
def GetStacks(arguments):
    yamlData = SwarmTools.LoadYamlDataFromFiles(arguments)
    return YamlTools.GetProperties('stacks', yamlData)
Ejemplo n.º 24
0
def GetPackageInputUnsignedFolderFromArguments(arguments):
    argValues = SwarmTools.GetArgumentValues(arguments,
                                             '-packageInputUnsignedFolder')
    if len(argValues) == 0:
        return PACKAGE_INPUT_UNSIGNED_FOLDER
    return argValues[0]
Ejemplo n.º 25
0
def GetPackageOutputSignedFolderFromArguments(arguments):
    argValues = SwarmTools.GetArgumentValues(arguments,
                                             '-packageOutputSignedFolder')
    if len(argValues) == 0:
        return PACKAGE_OUTPUT_SIGNED_FOLDER
    return argValues[0]
Ejemplo n.º 26
0
def GetCertificatePathFromArguments(arguments):
    certificates = SwarmTools.GetArgumentValues(arguments, '-c')
    if len(certificates) == 0:
        return CERTIFICATE_FILE_PATH
    return certificates[0]
Ejemplo n.º 27
0
def GetPasswordFromArguments(arguments):
    passwords = SwarmTools.GetArgumentValues(arguments, '-p')
    if len(passwords) == 0:
        return 'xxxx'
    return passwords[0]
Ejemplo n.º 28
0
def GetConfigs(arguments):
    yamlData = SwarmTools.LoadYamlDataFromFiles(arguments)
    return YamlTools.GetProperties('configs', yamlData)