def test_c_CreateRemoveConfig(self): print('CREATE CONFIG') config = 'changelog-config-' + str(random.randint(0, 10000)) DockerSwarmTools.CreateSwarmConfig( os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'CHANGELOG.md'), config) DockerSwarmTools.RemoveSwarmConfig(config) print('DONE CREATE CONFIG')
def test_d_CreateRemoveSecret(self): print('CREATE SECRET') secret = 'changelog-secret-' + str(random.randint(0, 10000)) DockerSwarmTools.CreateSwarmSecret( os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'CHANGELOG.md'), secret) DockerSwarmTools.RemoveSwarmSecret(secret) print('DONE CREATE SECRET')
def test_e_CreateRemoveVolume(self): print('CREATE VOLUME') volume = 'test-volume-' + str(random.randint(0, 10000)) DockerSwarmTools.CreateSwarmVolume(volume) DockerSwarmTools.RemoveSwarmVolume(volume) DockerSwarmTools.CreateSwarmVolume(volume, driver='local') DockerSwarmTools.RemoveSwarmVolume(volume) print('DONE CREATE VOLUME')
def test_f_CreateRemoveStack(self): print('CREATE STACK') stack = 'test-stack-' + str(random.randint(0, 10000)) TerminalTools.LoadEnvironmentVariables( os.path.join(TestTools.TEST_SAMPLE_FOLDER, '.env')) DockerComposeTools.DockerComposeBuild( [os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'docker-compose.yml')]) DockerSwarmTools.DeployStack( os.path.join(TestTools.TEST_SAMPLE_FOLDER, 'docker-compose.yml'), stack) DockerSwarmTools.RemoveStack(stack) print('DONE CREATE STACK')
def test_b_CreateRemoveNetwork(self): print('CREATE NETWORK') network = 'my-network-' + str(random.randint(0, 10000)) DockerSwarmTools.CreateSwarmNetwork(network) DockerSwarmTools.RemoveSwarmNetwork(network) DockerSwarmTools.CreateSwarmNetwork(network, encrypted=True, driver="overlay", attachable=False, options=['--ipv6']) DockerSwarmTools.RemoveSwarmNetwork(network) print('DONE CREATE NETWORK')
def StartSwarm(arguments): DockerSwarmTools.StartSwarm() SwarmVolumes.HandleVolumes(['-volume', '-create', 'all'] + arguments) SwarmConfigs.HandleConfigs(['-config', '-create', 'all'] + arguments) SwarmSecrets.HandleSecrets(['-secret', '-create', 'all'] + arguments) SwarmNetworks.HandleNetworks(['-network', '-create', 'all'] + arguments) SwarmStacks.HandleStacks(['-stack', '-deploy', 'all'] + arguments)
def CreateVolume(volumeName, volumeProperties): if volumeProperties == None: volumeProperties = {} driver = YamlTools.TryGetFromDictionary(volumeProperties, 'driver', 'local') driverOptions = YamlTools.TryGetFromDictionary(volumeProperties, 'driverOptions', []) DockerSwarmTools.CreateSwarmVolume(volumeName, driver, driverOptions)
def Remove(self, artifacts=[]): stackFiles = self._GetFilesFromCache(artifacts) stackFilesToRemove = [] for stackFile in stackFiles: stackName, version, stackFileIsValid = StackVersionTools.GetStackNameAndVersionFromStackFile( stackFile, artifactIdentifier=self._artifactIdentifier) if not (stackFileIsValid): continue DockerSwarmTools.RemoveStack(stackName) stackFilesToRemove.append(stackFile) if self._removeFilesFromCache: for removedStackFile in stackFilesToRemove: os.remove(removedStackFile)
def CreateNetwork(networkName, networkProperties): if networkProperties == None: networkProperties = {} elif isinstance(networkProperties, bool): networkProperties = {'encrypted': networkProperties} encrypted = YamlTools.TryGetFromDictionary(networkProperties, 'encrypted', False) driver = YamlTools.TryGetFromDictionary(networkProperties, 'driver', 'overlay') attachable = YamlTools.TryGetFromDictionary(networkProperties, 'attachable', True) options = YamlTools.TryGetFromDictionary(networkProperties, 'options', []) DockerSwarmTools.CreateSwarmNetwork(networkName, encrypted, driver, attachable, options)
def Deploy(self, artifacts=[]): stackFiles = self._GetFilesFromCache(artifacts) for stackFile in stackFiles: stackName, version, stackFileIsValid = StackVersionTools.GetStackNameAndVersionFromStackFile( stackFile, artifactIdentifier=self._artifactIdentifier) if not (stackFileIsValid): continue valid = True if self.__verifyStacksOnDeploy: valid = self.__verificationHandler.VerifyStackFile(stackFile) if valid: DockerSwarmTools.DeployStack(stackFile, stackName, withRegistryAuth=True) else: warnings.warn( "Skipping deployment of stack {0} since it is invalid!". format(stackName))
def RemoveSecret(secretName): DockerSwarmTools.RemoveSwarmSecret(secretName)
def CreateSecret(secretName, secretFile): DockerSwarmTools.CreateSwarmSecret(secretFile, secretName)
def DeployStack(stackName, composeFile, environmentFiles): DockerSwarmTools.DeployStack(composeFile, stackName, environmentFiles, withRegistryAuth=True)
def test_a_StartSwarm(self): print('SWARM START') DockerSwarmTools.StartSwarm() print('DONE SWARM START')
def CreateConfig(configName, configFile): DockerSwarmTools.CreateSwarmConfig(configFile, configName)
def DeployStack(stackName, composeFile, environmentFiles): DockerSwarmTools.DeployStack(composeFile, stackName, environmentFiles)
def RemoveConfig(configName): DockerSwarmTools.RemoveSwarmConfig(configName)
def RemoveNetwork(networkName): DockerSwarmTools.RemoveSwarmNetwork(networkName)
def RemoveVolume(volumeName): DockerSwarmTools.RemoveSwarmVolume(volumeName)
def RemoveStack(stack): DockerSwarmTools.RemoveStack(stack)
def InitWithSwarmManager(swmInfrastructureFiles: []): if not(__CheckSwarmManagementYamlFileExists(yamlFiles=swmInfrastructureFiles)): DockerSwarmTools.StartSwarm() return arguments = __GetSwarmManagementArgumentsWithInfrastructureFiles(swmInfrastructureFiles) SwarmManager.StartSwarm(arguments=arguments)