Exemple #1
0
    async def file_service_properties_async(self):
        # Instantiate the ShareServiceClient from a connection string
        from azure.storage.fileshare.aio import ShareServiceClient
        file_service = ShareServiceClient.from_connection_string(
            self.connection_string)

        # [START set_service_properties]
        # Create service properties
        from azure.storage.fileshare import Metrics, CorsRule, RetentionPolicy

        # Create metrics for requests statistics
        hour_metrics = Metrics(enabled=True,
                               include_apis=True,
                               retention_policy=RetentionPolicy(enabled=True,
                                                                days=5))
        minute_metrics = Metrics(enabled=True,
                                 include_apis=True,
                                 retention_policy=RetentionPolicy(enabled=True,
                                                                  days=5))

        # Create CORS rules
        cors_rule1 = CorsRule(['www.xyz.com'], ['GET'])
        allowed_origins = ['www.xyz.com', "www.ab.com", "www.bc.com"]
        allowed_methods = ['GET', 'PUT']
        max_age_in_seconds = 500
        exposed_headers = [
            "x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc",
            "x-ms-meta-bcd"
        ]
        allowed_headers = [
            "x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz",
            "x-ms-meta-foo"
        ]
        cors_rule2 = CorsRule(allowed_origins,
                              allowed_methods,
                              max_age_in_seconds=max_age_in_seconds,
                              exposed_headers=exposed_headers,
                              allowed_headers=allowed_headers)

        cors = [cors_rule1, cors_rule2]

        async with file_service:
            # Set the service properties
            await file_service.set_service_properties(hour_metrics,
                                                      minute_metrics, cors)
            # [END set_service_properties]

            # [START get_service_properties]
            properties = await file_service.get_service_properties()
Exemple #2
0
    def test_set_hour_metrics(self, resource_group, location, storage_account, storage_account_key):
        self._setup(storage_account, storage_account_key)
        hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5))

        # Act
        self.fsc.set_service_properties(hour_metrics=hour_metrics)

        # Assert
        received_props = self.fsc.get_service_properties()
        self._assert_metrics_equal(received_props['hour_metrics'], hour_metrics)
    async def test_set_minute_metrics_async(self, storage_account_name, storage_account_key):
        self._setup(storage_account_name, storage_account_key)
        minute_metrics = Metrics(enabled=True, include_apis=True,
                                 retention_policy=RetentionPolicy(enabled=True, days=5))

        # Act
        await self.fsc.set_service_properties(minute_metrics=minute_metrics)

        # Assert
        received_props = await self.fsc.get_service_properties()
        self._assert_metrics_equal(received_props['minute_metrics'], minute_metrics)
Exemple #4
0
    def test_set_hour_metrics(self):
        # Arrange
        hour_metrics = Metrics(enabled=True,
                               include_apis=True,
                               retention_policy=RetentionPolicy(enabled=True,
                                                                days=5))

        # Act
        self.fsc.set_service_properties(hour_metrics=hour_metrics)

        # Assert
        received_props = self.fsc.get_service_properties()
        self._assert_metrics_equal(received_props['hour_metrics'],
                                   hour_metrics)
    async def _test_set_minute_metrics_async(self):
        # Arrange
        minute_metrics = Metrics(enabled=True,
                                 include_apis=True,
                                 retention_policy=RetentionPolicy(enabled=True,
                                                                  days=5))

        # Act
        await self.fsc.set_service_properties(minute_metrics=minute_metrics)

        # Assert
        received_props = await self.fsc.get_service_properties()
        self._assert_metrics_equal(received_props['minute_metrics'],
                                   minute_metrics)
    def set_service_properties(self, service):

        print('1. Get File service properties')
        props = service.get_service_properties()

        retention = RetentionPolicy(enabled=True, days=5)
        hour_metrics = Metrics(enabled=True,
                               include_apis=True,
                               retention_policy=retention)
        minute_metrics = Metrics(enabled=False)

        try:
            print('2. Ovewrite File service properties')
            service.set_service_properties(hour_metrics=hour_metrics,
                                           minute_metrics=minute_metrics)

        finally:
            print(
                '3. Revert File service properties back to the original ones')
            service.set_service_properties(
                hour_metrics=props['hour_metrics'],
                minute_metrics=props['minute_metrics'])

        print('4. Set File service properties completed')