Пример #1
0
    def test_copy_bool_user_tags(self):
        tags = [{'Key': 'test-key', 'Value': 'test-value'}]
        resource = {
            'Tags': tags
        }

        copy_tags = True
        user_tags = []

        final_tags = coalesce_copy_user_tags(resource, copy_tags, user_tags)
        self.assertEqual(final_tags, tags)

        copy_tags = False
        user_tags = {'test-key-1': 'test-value'}

        final_tags = coalesce_copy_user_tags(resource, copy_tags, user_tags)
        self.assertEqual(final_tags, [{'Key': 'test-key-1', 'Value': 'test-value'}])
Пример #2
0
 def test_empty_resource_tags(self):
     resource = {}
     copy_tags = ['test-key-1']
     user_tags = {'user-key': 'test-value'}
     final_tags = coalesce_copy_user_tags(resource, copy_tags, user_tags)
     self.assertEqual(final_tags, [{
         'Key': 'user-key',
         'Value': 'test-value'
     }])
Пример #3
0
    def test_copy_asterisk_user_tags(self):
        tags = [{
            'Key': 'test-key-1',
            'Value': 'test-value'
        }, {
            'Key': 'test-key',
            'Value': 'test-value'
        }]

        resource = {'Tags': tags}

        copy_tags = ['*']
        user_tags = []
        final_tags = coalesce_copy_user_tags(resource, copy_tags, user_tags)
        self.assertEqual(final_tags, tags)
Пример #4
0
 def process(self, resources):
     client = local_session(self.manager.session_factory).client('fsx')
     user_tags = self.data.get('tags', {})
     copy_tags = self.data.get('copy-tags', True)
     for r in resources:
         tags = coalesce_copy_user_tags(r, copy_tags, user_tags)
         try:
             if tags:
                 client.create_backup(FileSystemId=r['FileSystemId'],
                                      Tags=tags)
             else:
                 client.create_backup(FileSystemId=r['FileSystemId'])
         except client.exceptions.BackupInProgress as e:
             self.log.warning('Unable to create backup for: %s - %s' %
                              (r['FileSystemId'], e))
Пример #5
0
    def process(self, resources):
        client = local_session(self.manager.session_factory).client('fsx')

        skip_snapshot = self.data.get('skip-snapshot', False)
        copy_tags = self.data.get('copy-tags', True)
        user_tags = self.data.get('tags', [])

        for r in resources:
            tags = coalesce_copy_user_tags(r, copy_tags, user_tags)
            config = {'SkipFinalBackup': skip_snapshot}
            if tags and not skip_snapshot:
                config['FinalBackupTags'] = tags
            try:
                client.delete_file_system(FileSystemId=r['FileSystemId'],
                                          WindowsConfiguration=config)
            except client.exceptions.BadRequest as e:
                self.log.warning('Unable to delete: %s - %s' %
                                 (r['FileSystemId'], e))
Пример #6
0
    def process(self, resources):
        client = local_session(self.manager.session_factory).client('fsx')

        skip_snapshot = self.data.get('skip-snapshot', False)
        copy_tags = self.data.get('copy-tags', True)
        user_tags = self.data.get('tags', [])

        for r in resources:
            tags = coalesce_copy_user_tags(r, copy_tags, user_tags)
            config = {'SkipFinalBackup': skip_snapshot}
            if tags and not skip_snapshot:
                config['FinalBackupTags'] = tags
            try:
                client.delete_file_system(
                    FileSystemId=r['FileSystemId'],
                    WindowsConfiguration=config
                )
            except client.exceptions.BadRequest as e:
                self.log.warning('Unable to delete: %s - %s' % (r['FileSystemId'], e))
Пример #7
0
 def process(self, resources):
     client = local_session(self.manager.session_factory).client('fsx')
     user_tags = self.data.get('tags', {})
     copy_tags = self.data.get('copy-tags', True)
     for r in resources:
         tags = coalesce_copy_user_tags(r, copy_tags, user_tags)
         try:
             if tags:
                 client.create_backup(
                     FileSystemId=r['FileSystemId'],
                     Tags=tags
                 )
             else:
                 client.create_backup(
                     FileSystemId=r['FileSystemId']
                 )
         except client.exceptions.BackupInProgress as e:
             self.log.warning(
                 'Unable to create backup for: %s - %s' % (r['FileSystemId'], e))
Пример #8
0
    def test_copy_list_user_tags(self):
        tags = [
            {
                'Key': 'test-key-1',
                'Value': 'test-value'
            },
            {
                'Key': 'test-key',
                'Value': 'test-value'
            }
        ]
        resource = {
            'Tags': tags
        }

        copy_tags = ['test-key-1']
        user_tags = []

        final_tags = coalesce_copy_user_tags(resource, copy_tags, user_tags)
        self.assertEqual(final_tags, [{'Key': 'test-key-1', 'Value': 'test-value'}])
Пример #9
0
    def test_copy_user_tags_conflict(self):
        tags = [
            {
                'Key': 'test-key-1',
                'Value': 'test-value'
            },
            {
                'Key': 'test-key',
                'Value': 'test-value'
            }
        ]

        resource = {
            'Tags': tags
        }

        copy_tags = ['*']
        user_tags = [{'Key': 'test-key', 'Value': 'test-value-user'}]
        final_tags = coalesce_copy_user_tags(resource, copy_tags, user_tags)
        self.assertEqual(len(final_tags), 2)
        self.assertTrue({'Key': 'test-key-1', 'Value': 'test-value'} in final_tags)
        self.assertTrue({'Key': 'test-key', 'Value': 'test-value-user'} in final_tags)
Пример #10
0
 def test_empty_response(self):
     resource = {}
     user_tags = {}
     copy_tags = []
     final_tags = coalesce_copy_user_tags(resource, copy_tags, user_tags)
     self.assertEqual(final_tags, [])
Пример #11
0
 def test_empty_resource_tags(self):
     resource = {}
     copy_tags = ['test-key-1']
     user_tags = {'user-key': 'test-value'}
     final_tags = coalesce_copy_user_tags(resource, copy_tags, user_tags)
     self.assertEqual(final_tags, [{'Key': 'user-key', 'Value': 'test-value'}])