Exemple #1
0
    def update_resource_tags(tag_action, resource, tags):
        client = tag_action.session.client(
            'azure.mgmt.resource.ResourceManagementClient')

        # resource group type
        if is_resource_group(resource):
            params_patch = ResourceGroupPatchable(tags=tags)
            client.resource_groups.update(
                resource['name'],
                params_patch,
            )
        # other Azure resources
        else:
            # deserialize the original object
            az_resource = GenericResource.deserialize(resource)

            if not tag_action.manager.tag_operation_enabled(az_resource.type):
                raise NotImplementedError(
                    'Cannot tag resource with type {0}'.format(
                        az_resource.type))
            api_version = tag_action.session.resource_api_version(
                resource['id'])

            # create a PATCH object with only updates to tags
            tags_patch = GenericResource(tags=tags)

            client.resources.update_by_id(resource['id'], api_version,
                                          tags_patch)
Exemple #2
0
    def update_resource_tags(tag_action, resource, tags):
        client = tag_action.session.client('azure.mgmt.resource.ResourceManagementClient')

        # resource group type
        if tag_action.manager.type == 'resourcegroup':
            params_patch = ResourceGroupPatchable(
                tags=tags
            )
            client.resource_groups.update(
                resource['name'],
                params_patch,
            )
        # other Azure resources
        else:
            # generic armresource tagging isn't supported yet Github issue #2637
            if tag_action.manager.type == 'armresource':
                raise NotImplementedError('Cannot tag generic ARM resources.')

            api_version = tag_action.session.resource_api_version(resource['id'])

            # deserialize the original object
            az_resource = GenericResource.deserialize(resource)

            # create a GenericResource object with the required parameters
            generic_resource = GenericResource(location=az_resource.location,
                                               tags=tags,
                                               properties=az_resource.properties,
                                               kind=az_resource.kind,
                                               managed_by=az_resource.managed_by,
                                               identity=az_resource.identity)

            client.resources.update_by_id(resource['id'], api_version, generic_resource)
Exemple #3
0
    def process(self, resources):
        session = utils.local_session(self.manager.session_factory)
        client = self.manager.get_client('azure.mgmt.resource.ResourceManagementClient')

        for resource in resources:
            # get existing tags
            tags = resource.get('tags', {})

            # add or update tags
            new_tags = self.data.get('tags') or {self.data.get('tag'): self.data.get('value')}
            for key in new_tags:
                tags[key] = new_tags[key]

            # resource group type
            if self.manager.type == 'resourcegroup':
                params_patch = ResourceGroupPatchable(
                    tags=tags
                )
                client.resource_groups.update(
                    resource['name'],
                    params_patch,
                )
            # other Azure resources
            else:
                az_resource = GenericResource.deserialize(resource)
                api_version = session.resource_api_version(az_resource.id)
                az_resource.tags = tags

                client.resources.create_or_update_by_id(resource['id'], api_version, az_resource)
Exemple #4
0
    def process(self, resources):
        session = utils.local_session(self.manager.session_factory)
        client = self.manager.get_client(
            'azure.mgmt.resource.ResourceManagementClient')

        for resource in resources:
            # get existing tags
            tags = resource.get('tags', {})

            # add or update tags
            new_tags = self.data.get('tags') or {
                self.data.get('tag'): self.data.get('value')
            }
            for key in new_tags:
                tags[key] = new_tags[key]

            # resource group type
            if self.manager.type == 'resourcegroup':
                params_patch = ResourceGroupPatchable(tags=tags)
                client.resource_groups.update(
                    resource['name'],
                    params_patch,
                )
            # other Azure resources
            else:
                az_resource = GenericResource.deserialize(resource)
                api_version = session.resource_api_version(az_resource.id)
                az_resource.tags = tags

                client.resources.create_or_update_by_id(
                    resource['id'], api_version, az_resource)
    def update_resource_tags(tag_action, resource, tags):
        client = tag_action.session.client(
            'azure.mgmt.resource.ResourceManagementClient')

        # resource group type
        if tag_action.manager.type == 'resourcegroup':
            params_patch = ResourceGroupPatchable(tags=tags)
            client.resource_groups.update(
                resource['name'],
                params_patch,
            )
        # other Azure resources
        else:
            # deserialize the original object
            az_resource = GenericResource.deserialize(resource)

            if not tag_action.manager.tag_operation_enabled(az_resource.type):
                raise NotImplementedError(
                    'Cannot tag resource with type {0}'.format(
                        az_resource.type))
            api_version = tag_action.session.resource_api_version(
                resource['id'])

            # create a GenericResource object with the required parameters
            generic_resource = GenericResource(
                location=az_resource.location,
                tags=tags,
                properties=az_resource.properties,
                kind=az_resource.kind,
                managed_by=az_resource.managed_by,
                identity=az_resource.identity)

            client.resources.update_by_id(resource['id'], api_version,
                                          generic_resource)
Exemple #6
0
    def _process_resource(self, resource):
        resource['sku']['capacity'] = self.capacity
        resource['sku']['tier'] = self.tier
        resource['sku']['name'] = self.tier

        az_resource = GenericResource.deserialize(resource)

        api_version = self.session.resource_api_version(resource['id'])

        # create a GenericResource object with the required parameters
        generic_resource = GenericResource(sku=az_resource.sku)

        self.client.resources.update_by_id(resource['id'], api_version, generic_resource)
Exemple #7
0
def update_resource_tags(self, session, client, resource, tags):
    # resource group type
    if self.manager.type == 'resourcegroup':
        params_patch = ResourceGroupPatchable(
            tags=tags
        )
        client.resource_groups.update(
            resource['name'],
            params_patch,
        )
    # other Azure resources
    else:
        az_resource = GenericResource.deserialize(resource)
        api_version = session.resource_api_version(az_resource.id)
        az_resource.tags = tags

        client.resources.create_or_update_by_id(resource['id'], api_version, az_resource)
def update_resource_tags(self, resource, tags):

    # resource group type
    if self.manager.type == 'resourcegroup':
        params_patch = ResourceGroupPatchable(
            tags=tags
        )
        self.client.resource_groups.update(
            resource['name'],
            params_patch,
        )
    # other Azure resources
    else:
        az_resource = GenericResource.deserialize(resource)
        api_version = self.session.resource_api_version(az_resource.id)
        az_resource.tags = tags

        self.client.resources.create_or_update_by_id(resource['id'], api_version, az_resource)
Exemple #9
0
    def update_resource_tags(tag_action, resource, tags):
        client = tag_action.session.client(
            'azure.mgmt.resource.ResourceManagementClient')

        # resource group type
        if tag_action.manager.type == 'resourcegroup':
            params_patch = ResourceGroupPatchable(tags=tags)
            client.resource_groups.update(
                resource['name'],
                params_patch,
            )
        # other Azure resources
        else:
            # generic armresource tagging isn't supported yet Github issue #2637
            if tag_action.manager.type == 'armresource':
                raise NotImplementedError('Cannot tag generic ARM resources.')

            api_version = tag_action.session.resource_api_version(
                resource['id'])

            # deserialize the original object
            az_resource = GenericResource.deserialize(resource)

            # create a GenericResource object with the required parameters
            generic_resource = GenericResource(
                location=az_resource.location,
                tags=tags,
                properties=az_resource.properties,
                kind=az_resource.kind,
                managed_by=az_resource.managed_by,
                sku=az_resource.sku,
                identity=az_resource.identity)

            try:
                client.resources.update_by_id(resource['id'], api_version,
                                              generic_resource)
            except Exception as e:
                log.error("Failed to update tags for the resource.\n"
                          "Type: {0}.\n"
                          "Name: {1}.\n"
                          "Error: {2}".format(resource['type'],
                                              resource['name'], e))
Exemple #10
0
def update_resource_tags(self, resource, tags):

    # resource group type
    if self.manager.type == 'resourcegroup':
        params_patch = ResourceGroupPatchable(tags=tags)
        self.client.resource_groups.update(
            resource['name'],
            params_patch,
        )
    # other Azure resources
    else:
        if self.manager.type == 'armresource':
            raise NotImplementedError('Cannot tag generic ARM resources.')

        az_resource = GenericResource.deserialize(resource)
        api_version = self.session.resource_api_version(az_resource.id)
        az_resource.tags = tags

        self.client.resources.create_or_update_by_id(resource['id'],
                                                     api_version, az_resource)
Exemple #11
0
    def process(self, resources):
        session = utils.local_session(self.manager.session_factory)
        client = session.client('azure.mgmt.resource.ResourceManagementClient')

        for resource in resources:
            id = resource['id']

            tags = self.data.get('tags') or resource.get('tags', {})
            tag = self.data.get('tag')
            value = self.data.get('value')

            if tag and value:
                tags[tag] = value

            az_resource = GenericResource.deserialize(resource)
            api_version = session.resource_api_version(az_resource)
            az_resource.tags = tags

            client.resources.create_or_update_by_id(id, api_version,
                                                    az_resource)
Exemple #12
0
    def update_resource_tags(tag_action, resource, tags):
        client = tag_action.session.client('azure.mgmt.resource.ResourceManagementClient')

        # resource group type
        if tag_action.manager.type == 'resourcegroup':
            params_patch = ResourceGroupPatchable(
                tags=tags
            )
            client.resource_groups.update(
                resource['name'],
                params_patch,
            )
        # other Azure resources
        else:
            if tag_action.manager.type == 'armresource':
                raise NotImplementedError('Cannot tag generic ARM resources.')

            az_resource = GenericResource.deserialize(resource)
            api_version = tag_action.session.resource_api_version(az_resource.id)
            az_resource.tags = tags

            client.resources.create_or_update_by_id(resource['id'], api_version, az_resource)