def create_azure_netapp_volume(self): """ Create a volume for the given Azure NetApp Account :return: None """ options = dict() for attr in ('protocol_types', 'service_level', 'size'): value = self.parameters.get(attr) if value is not None: if attr == 'size': attr = 'usage_threshold' value *= ONE_GIB options[attr] = value rules = self.get_export_policy_rules() if rules is not None: options['export_policy'] = rules subnet_id = '/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s'\ % (self.netapp_client.config.subscription_id, self.parameters['resource_group'] if self.parameters.get('vnet_resource_group_for_subnet') is None else self.parameters['vnet_resource_group_for_subnet'], self.parameters['virtual_network'], self.parameters['subnet_name']) volume_body = Volume(location=self.parameters['location'], creation_token=self.parameters['file_path'], subnet_id=subnet_id, **options) try: result = self.netapp_client.volumes.create_or_update( body=volume_body, resource_group_name=self.parameters['resource_group'], account_name=self.parameters['account_name'], pool_name=self.parameters['pool_name'], volume_name=self.parameters['name']) # waiting till the status turns Succeeded while result.done() is not True: result.result(10) except (CloudError, ValidationError) as error: self.module.fail_json( msg= 'Error creating volume %s for Azure NetApp account %s and subnet ID %s: %s' % (self.parameters['name'], self.parameters['account_name'], subnet_id, to_native(error)), exception=traceback.format_exc())
def create_volume_from_snapshot(client, resource_group_name, anf_account_name, capacitypool_name, volume, snapshot_id, volume_name, tags=None): volume_body = Volume( snapshot_id=snapshot_id, export_policy=volume.export_policy, usage_threshold=volume.usage_threshold, creation_token=volume_name, location=volume.location, service_level=volume.service_level, subnet_id=volume.subnet_id, protocol_types=volume.protocol_types) return client.volumes.create_or_update(volume_body, resource_group_name, anf_account_name, capacitypool_name, volume_name).result()
def test_update_volume(self): # this can be reverted to set_bodiless_matcher() after tests are re-recorded and don't contain these headers set_custom_default_matcher( compare_bodies=False, excluded_headers= "Authorization,Content-Length,x-ms-client-request-id,x-ms-request-id" ) volume = create_volume(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1, live=self.is_live) assert "Premium" == volume.service_level assert 100 * GIGABYTE == volume.usage_threshold volume_body = Volume( usage_threshold=200 * GIGABYTE, creation_token=TEST_VOL_1, service_level="Premium", # cannot differ from pool location=LOCATION, subnet_id="/subscriptions/" + SUBSID + "/resourceGroups/" + TEST_RG + "/providers/Microsoft.Network/virtualNetworks/" + VNET + "/subnets/default") volume = self.client.volumes.begin_create_or_update( TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1, volume_body).result() assert "Premium" == volume.service_level # unchanged assert 200 * GIGABYTE == volume.usage_threshold delete_volume(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1, live=self.is_live) delete_pool(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, live=self.is_live) delete_account(self.client, TEST_RG, TEST_ACC_1, live=self.is_live)
def create_volume(client, resource_group_name, anf_account_name, capacitypool_name, volume_name, volume_usage_quota, service_level, subnet_id, location, tags=None): volume_body = Volume(usage_threshold=volume_usage_quota, creation_token=volume_name, location=location, service_level=service_level, subnet_id=subnet_id) return client.volumes.create_or_update(volume_body, resource_group_name, anf_account_name, capacitypool_name, volume_name).result()
def create_volume(cmd, client, account_name, pool_name, volume_name, resource_group_name, location, file_path, usage_threshold, vnet, subnet='default', service_level=None, protocol_types=None, tags=None): subs_id = get_subscription_id(cmd.cli_ctx) # determine vnet - supplied value can be name or ARM resource Id if is_valid_resource_id(vnet): resource_parts = parse_resource_id(vnet) vnet = resource_parts['resource_name'] # default the resource group of the subnet to the volume's rg unless the subnet is specified by id subnet_rg = resource_group_name # determine subnet - supplied value can be name or ARM reource Id if is_valid_resource_id(subnet): resource_parts = parse_resource_id(subnet) subnet = resource_parts['resource_name'] subnet_rg = resource_parts['resource_group'] # if NFSv4 is specified then the export policy must reflect this # the RP ordinarily only creates a default setting NFSv3. Export # policy is not settable directly on creation in CLI only via the # add export policy subcommand if (protocol_types is not None) and ("NFSv4.1" in protocol_types): rules = [] export_policy = ExportPolicyRule(rule_index=1, unix_read_only=False, unix_read_write=True, cifs=False, nfsv3=False, nfsv41=True, allowed_clients="0.0.0.0/0") rules.append(export_policy) volume_export_policy = VolumePropertiesExportPolicy(rules=rules) else: volume_export_policy = None subnet_id = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s" % (subs_id, subnet_rg, vnet, subnet) body = Volume( usage_threshold=int(usage_threshold) * gib_scale, creation_token=file_path, service_level=service_level, location=location, subnet_id=subnet_id, protocol_types=protocol_types, export_policy=volume_export_policy, tags=tags) return client.create_or_update(body, resource_group_name, account_name, pool_name, volume_name)
def test_update_volume(self): raise unittest.SkipTest("Skipping Volume test") volume = create_volume(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1, live=self.is_live) self.assertEqual("Premium", volume.service_level) self.assertEqual(100 * GIGABYTE, volume.usage_threshold) volume_body = Volume( usage_threshold=200 * GIGABYTE, creation_token=TEST_VOL_1, service_level="Premium", # cannot differ from pool location=LOCATION, subnet_id="/subscriptions/" + SUBSID + "/resourceGroups/" + TEST_RG + "/providers/Microsoft.Network/virtualNetworks/" + VNET + "/subnets/default") volume = self.client.volumes.create_or_update(volume_body, TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1).result() self.assertEqual("Premium", volume.service_level) # unchanged self.assertEqual(200 * GIGABYTE, volume.usage_threshold) delete_volume(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1, live=self.is_live) delete_pool(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, live=self.is_live) delete_account(self.client, TEST_RG, TEST_ACC_1, live=self.is_live)
def create_dp_volume(client, source_volume, rg=TEST_REMOTE_RG, account_name=TEST_ACC_2, pool_name=TEST_POOL_2, volume_name=TEST_VOL_2, location=REMOTE_LOCATION, volume_only=False, live=False): if not volume_only: pool = create_pool(client, rg, account_name, pool_name, location, False) if live: time.sleep(10) # data protection and replication object replication = ReplicationObject(endpoint_type="dst", remote_volume_resource_id=source_volume.id, replication_schedule="_10minutely") data_protection = VolumePropertiesDataProtection(replication=replication) default_protocol_type = {"NFSv3"} volume_body = Volume( location=location, usage_threshold=100 * GIGABYTE, protocol_types=default_protocol_type, creation_token=volume_name, subnet_id="/subscriptions/" + SUBSID + "/resourceGroups/" + rg + "/providers/Microsoft.Network/virtualNetworks/" + REMOTE_VNET + "/subnets/default", volume_type="DataProtection", data_protection=data_protection) destination_volume = client.volumes.create_or_update( volume_body, rg, account_name, pool_name, volume_name).result() return destination_volume
def create_azure_netapp_volume(self): """ Create a volume for the given Azure NetApp Account :return: None """ volume_body = Volume( location=self.parameters['location'], creation_token=self.parameters['file_path'], service_level=self.parameters['service_level'] if self.parameters.get('service_level') is not None else 'Premium', usage_threshold=(self.parameters['size'] if self.parameters.get( 'size') is not None else 100) * ONE_GIB, subnet_id= '/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s' % (self.netapp_client.config.subscription_id, self.parameters['resource_group'] if self.parameters.get('vnet_resource_group_for_subnet') is None else self.parameters['vnet_resource_group_for_subnet'], self.parameters['virtual_network'], self.parameters['subnet_id'])) try: result = self.netapp_client.volumes.create_or_update( body=volume_body, resource_group_name=self.parameters['resource_group'], account_name=self.parameters['account_name'], pool_name=self.parameters['pool_name'], volume_name=self.parameters['name']) # waiting till the status turns Succeeded while result.done() is not True: result.result(10) except CloudError as error: self.module.fail_json( msg= 'Error creating volume %s for Azure NetApp account %s and subnet ID %s: %s' % (self.parameters['name'], self.parameters['account_name'], self.parameters['subnet_id'], to_native(error)), exception=traceback.format_exc())
def create_volume(cmd, client, account_name, pool_name, volume_name, resource_group_name, location, creation_token, usage_threshold, vnet, subnet='default', service_level=None, protocol_types=None, tags=None): subs_id = get_subscription_id(cmd.cli_ctx) # determine vnet - supplied value can be name or ARM resource Id if is_valid_resource_id(vnet): resource_parts = parse_resource_id(vnet) vnet = resource_parts['resource_name'] # determine subnet - supplied value can be name or ARM reource Id if is_valid_resource_id(subnet): resource_parts = parse_resource_id(subnet) subnet = resource_parts['resource_name'] subnet_id = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s" % (subs_id, resource_group_name, vnet, subnet) body = Volume( usage_threshold=int(usage_threshold) * gib_scale, creation_token=creation_token, service_level=service_level, location=location, subnet_id=subnet_id, protocol_types=protocol_types, tags=tags) return client.create_or_update(body, resource_group_name, account_name, pool_name, volume_name)
def test_update_volume(self): volume = create_volume(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1, live=self.is_live) self.assertEqual(volume.service_level, "Premium") self.assertEqual(volume.usage_threshold, 100 * GIGABYTE) volume_body = Volume( usage_threshold=100 * GIGABYTE, creation_token=TEST_VOL_1, service_level="Standard", location=LOCATION, subnet_id="/subscriptions/" + SUBSID + "/resourceGroups/" + TEST_RG + "/providers/Microsoft.Network/virtualNetworks/" + VNET + "/subnets/default") volume = self.client.volumes.create_or_update(volume_body, TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1).result() self.assertEqual(volume.service_level, "Standard") delete_volume(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, TEST_VOL_1, live=self.is_live) delete_pool(self.client, TEST_RG, TEST_ACC_1, TEST_POOL_1, live=self.is_live) delete_account(self.client, TEST_RG, TEST_ACC_1, live=self.is_live)
def create_volume(client, resource_group_name, anf_account_name, capacitypool_name, volume_name, volume_usage_quota, service_level, subnet_id, location, tags=None): """Creates a volume within a capacity pool Function that in this example creates a NFSv4.1 volume within a capacity pool, as a note service level needs to be the same as the capacity pool. This function also defines the volume body as the configuration settings of the new volume. Args: client (NetAppManagementClient): Azure Resource Provider Client designed to interact with ANF resources resource_group_name (string): Name of the resource group where the volume will be created, it needs to be the same as the account anf_account_name (string): Name of the Azure NetApp Files Account where the capacity pool holding the volume exists capacitypool_name (string): Capacity pool name where volume will be created volume_name (string): Volume name volume_usage_quota (long): Volume size in bytes, minimum value is 107374182400 (100GiB), maximum value is 109951162777600 (100TiB) service_level (string): Volume service level, needs to be the same as the capacity pool, valid values are "Ultra","Premium","Standard" subnet_id (string): Subnet resource id of the delegated to ANF Volumes subnet location (string): Azure short name of the region where resource will be deployed, needs to be the same as the account tags (object): Optional. Key-value pairs to tag the resource, default value is None. E.g. {'cc':'1234','dept':'IT'} Returns: Volume: Returns the newly created volume resource """ rule_list = [ ExportPolicyRule(allowed_clients="0.0.0.0/0", cifs=False, nfsv3=False, nfsv41=True, rule_index=1, unix_read_only=False, unix_read_write=True) ] export_policies = VolumePropertiesExportPolicy(rules=rule_list) volume_body = Volume(usage_threshold=volume_usage_quota, creation_token=volume_name, location=location, service_level=service_level, subnet_id=subnet_id, protocol_types=["NFSv4.1"], export_policy=export_policies, tags=tags) return client.volumes.begin_create_or_update(resource_group_name, anf_account_name, capacitypool_name, volume_name, volume_body).result()
def create_volume(cmd, client, account_name, pool_name, volume_name, resource_group_name, location, file_path, usage_threshold, vnet, subnet='default', service_level=None, protocol_types=None, volume_type=None, endpoint_type=None, replication_schedule=None, remote_volume_resource_id=None, tags=None, snapshot_id=None, snapshot_policy_id=None, backup_policy_id=None, backup_enabled=None, backup_id=None, policy_enforced=None, vault_id=None, kerberos_enabled=None, security_style=None, throughput_mibps=None, kerberos5_r=None, kerberos5_rw=None, kerberos5i_r=None, kerberos5i_rw=None, kerberos5p_r=None, kerberos5p_rw=None, has_root_access=None, snapshot_dir_visible=None, smb_encryption=None, smb_continuously_avl=None, encryption_key_source=None, rule_index=None, unix_read_only=None, unix_read_write=None, cifs=None, allowed_clients=None, ldap_enabled=None): subs_id = get_subscription_id(cmd.cli_ctx) # default the resource group of the subnet to the volume's rg unless the subnet is specified by id subnet_rg = resource_group_name # determine vnet - supplied value can be name or ARM resource Id if is_valid_resource_id(vnet): resource_parts = parse_resource_id(vnet) vnet = resource_parts['resource_name'] subnet_rg = resource_parts['resource_group'] # determine subnet - supplied value can be name or ARM reource Id if is_valid_resource_id(subnet): resource_parts = parse_resource_id(subnet) subnet = resource_parts['resource_name'] subnet_rg = resource_parts['resource_group'] # if NFSv4 is specified then the export policy must reflect this # the RP ordinarily only creates a default setting NFSv3. if (protocol_types is not None) and ("NFSv4.1" in protocol_types): rules = [] if allowed_clients is None: raise CLIError( "Parameter allowed-clients needs to be set when protocol-type is NFSv4.1" ) if rule_index is None: raise CLIError( "Parameter rule-index needs to be set when protocol-type is NFSv4.1" ) export_policy = ExportPolicyRule(rule_index=rule_index, unix_read_only=unix_read_only, unix_read_write=unix_read_write, cifs=cifs, nfsv3=False, nfsv41=True, allowed_clients=allowed_clients, kerberos5_read_only=kerberos5_r, kerberos5_read_write=kerberos5_rw, kerberos5i_read_only=kerberos5i_r, kerberos5i_read_write=kerberos5i_rw, kerberos5p_read_only=kerberos5p_r, kerberos5p_read_write=kerberos5p_rw, has_root_access=has_root_access) rules.append(export_policy) volume_export_policy = VolumePropertiesExportPolicy(rules=rules) else: volume_export_policy = None data_protection = None replication = None snapshot = None backup = None # Make sure volume_type is set correctly if replication parameters are set if endpoint_type is not None and replication_schedule is not None and remote_volume_resource_id is not None: volume_type = "DataProtection" if volume_type == "DataProtection": replication = ReplicationObject( endpoint_type=endpoint_type, replication_schedule=replication_schedule, remote_volume_resource_id=remote_volume_resource_id) if snapshot_policy_id is not None: snapshot = VolumeSnapshotProperties( snapshot_policy_id=snapshot_policy_id) if backup_policy_id is not None: backup = VolumeBackupProperties(backup_policy_id=backup_policy_id, policy_enforced=policy_enforced, vault_id=vault_id, backup_enabled=backup_enabled) if replication is not None or snapshot is not None or backup is not None: data_protection = VolumePropertiesDataProtection( replication=replication, snapshot=snapshot, backup=backup) subnet_id = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s" % ( subs_id, subnet_rg, vnet, subnet) body = Volume(usage_threshold=int(usage_threshold) * gib_scale, creation_token=file_path, service_level=service_level, location=location, subnet_id=subnet_id, protocol_types=protocol_types, export_policy=volume_export_policy, volume_type=volume_type, data_protection=data_protection, backup_id=backup_id, kerberos_enabled=kerberos_enabled, throughput_mibps=throughput_mibps, snapshot_directory_visible=snapshot_dir_visible, security_style=security_style, tags=tags, snapshot_id=snapshot_id, smb_encryption=smb_encryption, smb_continuously_available=smb_continuously_avl, encryption_key_source=encryption_key_source, ldap_enabled=ldap_enabled) return client.begin_create_or_update(resource_group_name, account_name, pool_name, volume_name, body)
def clone(self, cloud_volume, snapshot, volume_name, export_path, cidr, auth, client_id, verbose): credentials = auth subscription_id = client_id if export_path: print("Error - setting the EXPORT_PATH not surrently supported") sys.exit(2) if cidr: print("Error - setting the CIDR not surrently supported") sys.exit(2) # validate arguments if not subscription_id: print("Error - \"subscription_id\" unknown, specify in " + \ "configiuration file") sys.exit(2) if not volume_name: print("Error - VOLUME_NAME is a required argument") sys.exit(2) volume = self.get_volume(volume_name, subscription_id, credentials, False) if volume: print("Error - volume '" + volume_name + "' already exists") sys.exit(2) if not cloud_volume: print("Error - CLOUD_VOLUME is a required argument") sys.exit(2) volume = self.get_volume(cloud_volume, subscription_id, credentials, verbose) if not volume: print("Error - volume '" + cloud_volume + "' not found") sys.exit(2) if not snapshot: print("Error - SNAPSHOT is a required argument") sys.exit(2) snapshot_id = self.get_snapshot_id(subscription_id, credentials, volume, snapshot, verbose) if not snapshot_id: print("Error - snapshot '" + snapshot + "' not found") sys.exit(2) anf_client = AzureNetAppFilesManagementClient(credentials, subscription_id) resource_group, netapp_account, capacity_pool = \ self.parse_volume_id(volume) volume_body = Volume(location=volume.location, usage_threshold=volume.usage_threshold, snapshot_id=snapshot_id, creation_token=volume_name, service_level=volume.service_level, subnet_id=volume.subnet_id) start_time = datetime.datetime.now() try: anf_client.volumes.create_or_update(volume_body, resource_group, netapp_account, capacity_pool, volume_name) elapsed = datetime.datetime.now() - start_time print("Created clone '" + volume_name + "' in " + \ str(elapsed.total_seconds()) + " seconds") except: print("Error - clone failed to initialize: '" + volume_name + "'")