def create_volume(cmd, client, account_name, pool_name, volume_name, resource_group_name, location, service_level, creation_token, usage_threshold, subnet_id, tag=None, export_policy=None): rules = build_export_policy_rules(export_policy) volume_export_policy = VolumePropertiesExportPolicy( rules=rules) if rules != [] else None body = Volume(usage_threshold=int(usage_threshold), creation_token=creation_token, service_level=service_level, location=location, subnet_id=subnet_id, tags=generate_tags(tag), export_policy=volume_export_policy) return client.create_or_update(body, resource_group_name, account_name, pool_name, volume_name)
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): 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 # if we have a data protection volume requested then build the component if volume_type == "DataProtection": replication = ReplicationObject( endpoint_type=endpoint_type, replication_schedule=replication_schedule, remote_volume_resource_id=remote_volume_resource_id ) data_protection = VolumePropertiesDataProtection(replication=replication) else: data_protection = 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, volume_type=volume_type, data_protection=data_protection, tags=tags, snapshot_id=snapshot_id) return client.create_or_update(body, resource_group_name, account_name, pool_name, volume_name)
def add_export_policy_rule(cmd, instance, allowed_clients, rule_index, unix_read_only, unix_read_write, cifs, nfsv3, nfsv41): rules = [] export_policy = ExportPolicyRule(rule_index=rule_index, unix_read_only=unix_read_only, unix_read_write=unix_read_write, cifs=cifs, nfsv3=nfsv3, nfsv41=nfsv41, allowed_clients=allowed_clients) rules.append(export_policy) for rule in instance.export_policy.rules: rules.append(rule) volume_export_policy = VolumePropertiesExportPolicy(rules=rules) params = VolumePatch( export_policy=volume_export_policy, service_level=instance.service_level, usage_threshold=instance.usage_threshold) _update_mapper(instance, params, ['export_policy']) return params
def add_export_policy_rule(instance, allowed_clients, rule_index, unix_read_only, unix_read_write, cifs, nfsv3, nfsv41, kerberos5_r=None, kerberos5_rw=None, kerberos5i_r=None, kerberos5i_rw=None, kerberos5p_r=None, kerberos5p_rw=None, has_root_access=None, chown_mode=None): rules = [] export_policy = ExportPolicyRule(rule_index=rule_index, unix_read_only=unix_read_only, unix_read_write=unix_read_write, cifs=cifs, nfsv3=nfsv3, nfsv41=nfsv41, allowed_clients=allowed_clients, kerberos5_read_only=kerberos5_r, kerberos5_read_write=kerberos5_rw, kerberos5_i_read_only=kerberos5i_r, kerberos5_i_read_write=kerberos5i_rw, kerberos5_p_read_only=kerberos5p_r, kerberos5_p_read_write=kerberos5p_rw, has_root_access=has_root_access, chown_mode=chown_mode) rules.append(export_policy) for rule in instance.export_policy.rules: rules.append(rule) volume_export_policy = VolumePropertiesExportPolicy(rules=rules) params = VolumePatch(export_policy=volume_export_policy, service_level=instance.service_level, usage_threshold=instance.usage_threshold) _update_mapper(instance, params, ['export_policy']) return params
def remove_export_policy_rule(instance, rule_index): rules = [] # Note this commented out way created a patch request that included some mount target properties causing validation issues server side # need to investigate why, leave this for now remove after this has been ivestigated before next release please # look for the rule and remove # for rule in instance.export_policy.rules: # if rule.rule_index == int(rule_index): # instance.export_policy.rules.remove(rule) # return instance for rule in instance.export_policy.rules: if rule.rule_index != int(rule_index): rules.append(rule) volume_export_policy = VolumePropertiesExportPolicy(rules=rules) params = VolumePatch(export_policy=volume_export_policy, service_level=instance.service_level, usage_threshold=instance.usage_threshold) _update_mapper(instance, params, ['export_policy']) return params
def patch_volume(cmd, instance, service_level=None, usage_threshold=None, tag=None, export_policy=None): # the export policy provided replaces any existing eport policy rules = build_export_policy_rules(export_policy) volume_export_policy = VolumePropertiesExportPolicy( rules=rules) if rules != [] else None params = VolumePatch(usage_threshold=None if usage_threshold is None else int(usage_threshold), service_level=service_level, tags=generate_tags(tag), export_policy=volume_export_policy) _update_mapper( instance, params, ['service_level', 'usage_threshold', 'tags', 'export_policy']) return params
def get_export_policy_rules(self): # ExportPolicyRule(rule_index: int=None, unix_read_only: bool=None, unix_read_write: bool=None, # kerberos5_read_only: bool=False, kerberos5_read_write: bool=False, kerberos5i_read_only: bool=False, # kerberos5i_read_write: bool=False, kerberos5p_read_only: bool=False, kerberos5p_read_write: bool=False, # cifs: bool=None, nfsv3: bool=None, nfsv41: bool=None, allowed_clients: str=None, has_root_access: bool=True ptypes = self.parameters.get('protocol_types') if ptypes is None: return None ptypes = [x.lower() for x in ptypes] if 'nfsv4.1' in ptypes: ptypes.append('nfsv41') else: return None # only create a policy when NFSv4 is used (for now) options = dict(rule_index=1, allowed_clients='0.0.0.0/0', unix_read_write=True) for protocol in ('cifs', 'nfsv3', 'nfsv41'): options[protocol] = protocol in ptypes if options: return VolumePropertiesExportPolicy( rules=[ExportPolicyRule(**options)]) return None
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)