Esempio n. 1
0
def patch_volume(instance,
                 usage_threshold=None,
                 service_level=None,
                 tags=None,
                 vault_id=None,
                 backup_enabled=False,
                 backup_policy_id=None,
                 policy_enforced=False,
                 throughput_mibps=None):
    params = VolumePatch(
        usage_threshold=None
        if usage_threshold is None else int(usage_threshold) * gib_scale,
        service_level=service_level,
        data_protection=None
        if vault_id is None else VolumePatchPropertiesDataProtection(
            backup=VolumeBackupProperties(vault_id=vault_id,
                                          backup_enabled=backup_enabled,
                                          backup_policy_id=backup_policy_id,
                                          policy_enforced=policy_enforced)),
        tags=tags)
    if throughput_mibps is not None:
        params.throughput_mibps = throughput_mibps
    _update_mapper(
        instance, params,
        ['service_level', 'usage_threshold', 'tags', 'data_protection'])
    return params
Esempio n. 2
0
def patch_volume(instance,
                 usage_threshold=None,
                 service_level=None,
                 tags=None,
                 vault_id=None,
                 backup_enabled=False,
                 backup_policy_id=None,
                 policy_enforced=False,
                 throughput_mibps=None,
                 snapshot_policy_id=None,
                 is_def_quota_enabled=None,
                 default_user_quota=None,
                 default_group_quota=None):
    data_protection = None
    backup = None
    snapshot = None
    if vault_id is not None:
        backup = VolumeBackupProperties(vault_id=vault_id,
                                        backup_enabled=backup_enabled,
                                        backup_policy_id=backup_policy_id,
                                        policy_enforced=policy_enforced)
    if snapshot_policy_id is not None:
        snapshot = VolumeSnapshotProperties(
            snapshot_policy_id=snapshot_policy_id)

    if backup is not None or snapshot is not None:
        data_protection = VolumePatchPropertiesDataProtection(
            backup=backup, snapshot=snapshot)

    params = VolumePatch(usage_threshold=None if usage_threshold is None else
                         int(usage_threshold) * gib_scale,
                         service_level=service_level,
                         data_protection=data_protection,
                         tags=tags,
                         is_default_quota_enabled=is_def_quota_enabled,
                         default_user_quota_in_ki_bs=default_user_quota,
                         default_group_quota_in_ki_bs=default_group_quota)
    if throughput_mibps is not None:
        params.throughput_mibps = throughput_mibps
    _update_mapper(
        instance, params,
        ['service_level', 'usage_threshold', 'tags', 'data_protection'])
    return params
Esempio n. 3
0
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)