def test_configurations_resourcegroup(self, resource_group): resourceGroupName = resource_group.name # create a new configuration to update exclude to True input = ConfigData() input.properties = ConfigDataProperties(exclude=True) # update the configuration self.client.configurations.create_in_resource_group( config_contract = input, resource_group = resourceGroupName) # retrieve the configurations output = list(self.client.configurations.list_by_resource_group(resource_group = resourceGroupName).value)[0] # it should be identical to what we just set self.assertEqual(output.properties.exclude, True) # restore the default configuration input.properties = ConfigDataProperties(exclude=False) self.client.configurations.create_in_resource_group( config_contract = input, resource_group = resourceGroupName) # retrieve the configurations output = list(self.client.configurations.list_by_resource_group(resource_group = resourceGroupName).value)[0] # it should be identical to what we just set self.assertEqual(output.properties.exclude, False)
def main(): SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) GROUP_NAME = "testgroupx" CONFIGURATION = "default" # Create client # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ resource_client = ResourceManagementClient( credential=DefaultAzureCredential(), subscription_id=SUBSCRIPTION_ID) advisor_client = AdvisorManagementClient( credential=DefaultAzureCredential(), subscription_id=SUBSCRIPTION_ID) # Create resource group resource_client.resource_groups.create_or_update(GROUP_NAME, {"location": "eastus"}) # create a new configuration to update exclude to True input = ConfigData() input.exclude = True # Create configuration configuration = advisor_client.configurations.create_in_resource_group( configuration_name=CONFIGURATION, resource_group=GROUP_NAME, config_contract=input) print("Create configuration:\n{}".format(configuration)) # Get configuration configurations = advisor_client.configurations.list_by_resource_group( resource_group=GROUP_NAME, ) print("Get configuration:\n{}".format(list(configurations)[0])) # Delete Group resource_client.resource_groups.begin_delete(GROUP_NAME).result()
def test_configurations_resourcegroup(self, resource_group): resourceGroupName = resource_group.name # create a new configuration to update exclude to True input = ConfigData() input.properties = ConfigDataProperties(exclude=True) # update the configuration self.client.configurations.create_in_resource_group( config_contract = input, resource_group = resourceGroupName) # retrieve the configurations output = list(self.client.configurations.list_by_resource_group(resource_group = resourceGroupName))[0] # it should be identical to what we just set self.assertEqual(output.properties.exclude, True) # restore the default configuration input.properties = ConfigDataProperties(exclude=False) self.client.configurations.create_in_resource_group( config_contract = input, resource_group = resourceGroupName) # retrieve the configurations output = list(self.client.configurations.list_by_resource_group(resource_group = resourceGroupName))[0] # it should be identical to what we just set self.assertEqual(output.properties.exclude, False)
def test_configurations_subscription(self): # create a new configuration to update low CPU threshold to 20 input = ConfigData() input.properties = ConfigDataProperties(low_cpu_threshold=20) # update the configuration response = self.client.configurations.create_in_subscription(input) # retrieve the configurations output = list( self.client.configurations.list_by_subscription().value)[0] # it should be identical to what we just set self.assertEqual(output.properties.low_cpu_threshold, "20") # restore the default configuration input.properties = ConfigDataProperties(low_cpu_threshold=5) response = self.client.configurations.create_in_subscription(input) # retrieve the configurations output = list( self.client.configurations.list_by_subscription().value)[0] # it should be identical to what we just set self.assertEqual(output.properties.low_cpu_threshold, "5")
def configure_advisor_threshold(): creds = ServicePrincipalCredentials(client_id=client_id, secret=secret, tenant=tenant) creds.set_token() client = AdvisorManagementClient(credentials=creds, subscription_id=subscription_id) # create a new configuration to update low CPU threshold to 20 cfg = ConfigData() cfg.properties = ConfigDataProperties(low_cpu_threshold=20, exclude=False) # update the configuration client.configurations.create_in_subscription(cfg)
def cli_advisor_set_configurations(client, resource_group_name=None, low_cpu_threshold=None, exclude=None, include=None): cfg = ConfigData() cfg.properties = ConfigDataProperties() cfg.properties.low_cpu_threshold = low_cpu_threshold cfg.properties.exclude = exclude if include: cfg.properties.exclude = False if resource_group_name: return client.create_in_resource_group( config_contract=cfg, resource_group=resource_group_name) return client.create_in_subscription(cfg)
def test_configurations_subscription(self): # create a new configuration to update low CPU threshold to 20 input = ConfigData() input.properties = ConfigDataProperties(low_cpu_threshold=20) # update the configuration response = self.client.configurations.create_in_subscription(input) # retrieve the configurations output = list(self.client.configurations.list_by_subscription().value)[0] # it should be identical to what we just set self.assertEqual(output.properties.low_cpu_threshold, "20") # restore the default configuration input.properties = ConfigDataProperties(low_cpu_threshold=5) response = self.client.configurations.create_in_subscription(input) # retrieve the configurations output = list(self.client.configurations.list_by_subscription().value)[0] # it should be identical to what we just set self.assertEqual(output.properties.low_cpu_threshold, "5")
def test_configurations_resourcegroup(self, resource_group): resourceGroupName = resource_group.name configurationName = "default" # create a new configuration to update exclude to True input = ConfigData() input.exclude = True # update the configuration self.client.configurations.create_in_resource_group( configuration_name=configurationName, resource_group=resourceGroupName, config_contract=input) # retrieve the configurations output = list( self.client.configurations.list_by_resource_group( resource_group=resourceGroupName))[0] # it should be identical to what we just set assert output.exclude == True # restore the default configuration input.exclude = False self.client.configurations.create_in_resource_group( configuration_name=configurationName, resource_group=resourceGroupName, config_contract=input) # retrieve the configurations output = list( self.client.configurations.list_by_resource_group( resource_group=resourceGroupName))[0] # it should be identical to what we just set assert output.exclude == False
def test_configurations_subscription(self): # create a new configuration to update low CPU threshold to 20 input = ConfigData() input.low_cpu_threshold = 20 # update the configuration response = self.client.configurations.create_in_subscription(input) # retrieve the configurations output = list(self.client.configurations.list_by_subscription())[0] # it should be identical to what we just set assert output.low_cpu_threshold == "20" # restore the default configuration input.low_cpu_threshold = 5 response = self.client.configurations.create_in_subscription(input) # retrieve the configurations output = list(self.client.configurations.list_by_subscription())[0] # it should be identical to what we just set assert output.low_cpu_threshold == "5"