Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b64c7c2
NFSAAS-1708 add initial version of anf cli extension
leonardbf Feb 19, 2019
e1c85e3
Merge pull request #1 from leonardbf/NFSAAS-1708-initial-cli-extension
leonardbf Feb 19, 2019
51733d1
NFSAAS-1708 lint fixes
leonardbf Feb 19, 2019
faa9bd8
Merge pull request #2 from leonardbf/NFSAAS-1708-initial-cli-extension
leonardbf Feb 19, 2019
f1781de
NFSAAS-1708 code owner
leonardbf Feb 19, 2019
6e07811
Merge pull request #3 from leonardbf/NFSAAS-1708-initial-cli-extension
leonardbf Feb 19, 2019
5d7a03a
NFSAAS-1708 update from review comments
leonardbf Feb 20, 2019
2ea3977
Merge pull request #4 from leonardbf/NFSAAS-1708-initial-cli-extension
leonardbf Feb 20, 2019
46deb54
NFSAAS-1708 update from review comments
leonardbf Feb 20, 2019
6b6cac0
Merge pull request #5 from leonardbf/NFSAAS-1708-initial-cli-extension
leonardbf Feb 20, 2019
b3bb6e1
NFSAAS-1708 update with code review comments
leonardbf Feb 20, 2019
5c84c92
Merge pull request #6 from leonardbf/NFSAAS-1708-initial-cli-extension
leonardbf Feb 20, 2019
a7becd6
NFSAAS-1708 updates from review comments
leonardbf Feb 20, 2019
3f11bc3
Merge pull request #7 from leonardbf/NFSAAS-1708-initial-cli-extension
leonardbf Feb 20, 2019
a8e625a
NFSAAS-1708 updates from review comments
leonardbf Feb 20, 2019
d4d3dd3
Merge pull request #8 from leonardbf/NFSAAS-1708-initial-cli-extension
leonardbf Feb 20, 2019
9ec6de4
NFSAAS-1708 updates from review comments (#9)
leonardbf Feb 25, 2019
898a90d
Nfsaas 1708 initial cli extension (#10)
leonardbf Feb 25, 2019
a1722a1
Nfsaas 1708 initial cli extension (#11)
leonardbf Feb 25, 2019
c92c760
Nfsaas 1708 initial cli extension (#13)
leonardbf Feb 25, 2019
e9d77d1
Nfsaas 1708 initial cli extension (#14)
leonardbf Feb 25, 2019
8ab79e3
Nfsaas 1708 initial cli extension (#16)
leonardbf Feb 25, 2019
9be88a3
Nfsaas 1708 initial cli extension (#17)
leonardbf Feb 28, 2019
e1e41ee
Merge branch 'master' into master
williexu Feb 28, 2019
a18c5ad
NFSAAS-1708 add anf to cli extension index
leonardbf Mar 4, 2019
96ca605
NFSAAS-1708 add anf to cli extension index (#18)
leonardbf Mar 4, 2019
3aff306
Merge pull request #19 from Azure/master
leonardbf Mar 4, 2019
ed571e7
NFSAAS-1708 add ANF CLI extension to index
leonardbf Mar 4, 2019
7077e9b
Merge branch 'master' into NFSAAS-1708-add-index
leonardbf Mar 4, 2019
2363324
Merge pull request #20 from leonardbf/NFSAAS-1708-add-index
leonardbf Mar 4, 2019
e804f20
NFSAAS-1708 add ANF CLI extension to index
leonardbf Mar 4, 2019
a233abf
Merge pull request #21 from leonardbf/NFSAAS-1708-add-index
leonardbf Mar 4, 2019
2777400
NFSAAS-1708 add ANF CLI extension to index (#22)
leonardbf Mar 4, 2019
d119776
Nfsaas 1708 add index (#23)
leonardbf Mar 4, 2019
187bcd4
Nfsaas 1708 add index (#24)
leonardbf Mar 4, 2019
52effa3
Nfsaas 1708 add index (#25)
leonardbf Mar 4, 2019
b066b46
Nfsaas 1708 add index (#26)
leonardbf Mar 4, 2019
25802dd
Nfsaas 1708 add index (#27)
leonardbf Mar 4, 2019
81ed105
Merge branch 'master' into master
williexu Mar 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/anf-preview/azext_anf_preview/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader
from ._help import helps # pylint: disable=unused-import
from ._help import helps # pylint: disable=unused-import


class NetAppExtensionCommandsLoader(AzCommandsLoader):
Expand Down
7 changes: 7 additions & 0 deletions src/anf-preview/azext_anf_preview/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,29 @@
# --------------------------------------------------------------------------------------------

# pylint: disable=unused-argument


def cf_netapp(cli_ctx, *kwargs):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.mgmt.netapp import AzureNetAppFilesManagementClient
return get_mgmt_service_client(cli_ctx, AzureNetAppFilesManagementClient)


def accounts_mgmt_client_factory(cli_ctx, _):
return cf_netapp(cli_ctx).accounts


def pools_mgmt_client_factory(cli_ctx, _):
return cf_netapp(cli_ctx).pools


def volumes_mgmt_client_factory(cli_ctx, _):
return cf_netapp(cli_ctx).volumes


def mount_targets_mgmt_client_factory(cli_ctx, _):
return cf_netapp(cli_ctx).mount_targets


def snapshots_mgmt_client_factory(cli_ctx, _):
return cf_netapp(cli_ctx).snapshots
1 change: 1 addition & 0 deletions src/anf-preview/azext_anf_preview/_exception_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from knack.util import CLIError


def netapp_exception_handler(ex):
from azure.mgmt.netapp.models import ErrorException
if isinstance(ex, ErrorException):
Expand Down
2 changes: 1 addition & 1 deletion src/anf-preview/azext_anf_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,4 @@
- name: Return the specified ANF snapshot
text: >
az anf snapshot show -g group --account-name aname --pool-name pname --volume-name vname --snapshot-name sname
"""
"""
1 change: 1 addition & 0 deletions src/anf-preview/azext_anf_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# pylint: disable=line-too-long


def load_arguments(self, _):
with self.argument_context('anf') as c:
c.argument('resource_group', options_list=['--resource-group', '-g'], required=True, help='The name of the resource group')
Expand Down
10 changes: 9 additions & 1 deletion src/anf-preview/azext_anf_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,39 @@ def generate_tags(tag):
tags[parts[0]] = ""
return tags


def _update_mapper(existing, new, keys):
for key in keys:
existing_value = getattr(existing, key)
new_value = getattr(new, key)
setattr(new, key, new_value if new_value is not None else existing_value)


# pylint: disable=unused-argument
def create_account(cmd, client, account_name, resource_group_name, location, tag=None):
return client.create_or_update(resource_group_name, account_name, location, generate_tags(tag))


# pylint: disable=unused-argument
def update_account(cmd, instance, tag=None):
params = NetAppAccountPatch(tags=generate_tags(tag))
return params.tags


def create_pool(cmd, client, account_name, pool_name, resource_group, location, size, service_level, tag=None):
body = CapacityPool(service_level=service_level, size=int(size), location=location, tags=generate_tags(tag))
return client.create_or_update(body, resource_group, account_name, pool_name)


def update_pool(cmd, instance, location=None, size=None, service_level=None, tag=None):
# put operation to update the record
if size != None:
if size is not None:
size = int(size)
body = CapacityPool(service_level=service_level, size=size, location=location, tags=generate_tags(tag))
_update_mapper(instance, body, ['location', 'service_level', 'size', 'tags'])
return body


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):
body = Volume(
usage_threshold=int(usage_threshold),
Expand All @@ -64,6 +70,7 @@ def create_volume(cmd, client, account_name, pool_name, volume_name, resource_gr
tags=generate_tags(tag))
return client.create_or_update(body, resource_group_name, account_name, pool_name, volume_name)


def patch_volume(cmd, instance, service_level=None, usage_threshold=None, tag=None):
params = VolumePatch(
usage_threshold=None if usage_threshold is None else int(usage_threshold),
Expand All @@ -72,6 +79,7 @@ def patch_volume(cmd, instance, service_level=None, usage_threshold=None, tag=No
_update_mapper(instance, params, ['service_level', 'usage_threshold', 'tags'])
return params


def create_snapshot(cmd, client, account_name, pool_name, volume_name, snapshot_name, file_system_id, resource_group_name, location):
body = Snapshot(location=location, file_system_id=file_system_id)
return client.create(body, resource_group_name, account_name, pool_name, volume_name, snapshot_name)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# No tidy up of tests required. The resource group is automatically removed


class AzureNetAppFilesExtAccountServiceScenarioTest(ScenarioTest):
@ResourceGroupPreparer()
def test_ext_create_delete_account(self):
Expand Down Expand Up @@ -62,12 +63,10 @@ def test_ext_get_account_by_name_ext(self):

@ResourceGroupPreparer()
def test_ext_update_account_ext(self):
account_name = self.create_random_name(prefix='cli', length=24)
account_name = self.create_random_name(prefix='cli', length=24)
tag = "Tag1=Value1"

account = self.cmd("az anf account create -g {rg} -a %s -l 'westus2'" % account_name).get_output_in_json()
account = self.cmd("az anf account update -g {rg} -a %s --tags %s" % (account_name, tag)).get_output_in_json()
assert account['name'] == account_name
assert account['tags']['Tag1'] == 'Value1'


Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer

POOL_DEFAULT="--service-level 'Premium' --size 4398046511104"
VOLUME_DEFAULT="--service-level 'Premium' --usage-threshold 107374182400"
POOL_DEFAULT = "--service-level 'Premium' --size 4398046511104"
VOLUME_DEFAULT = "--service-level 'Premium' --usage-threshold 107374182400"

# No tidy up of tests required. The resource group is automatically removed


class AzureNetAppFilesExtMountTargetServiceScenarioTest(ScenarioTest):
def setup_vnet(self, rg, vnet_name):
self.cmd("az network vnet create -n %s -g %s -l westus2" % (vnet_name, rg))
Expand All @@ -23,23 +24,21 @@ def create_volume(self, account_name, pool_name, volume_name1, rg, tags=None):
vnet_name = self.create_random_name(prefix='cli-vnet-', length=24)
creation_token = volume_name1
subnet_id = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/default" % (self.current_subscription(), rg, vnet_name)
tag = "--tags '%s'" % tags if tags != None else ""
tag = "--tags '%s'" % tags if tags is not None else ""

self.setup_vnet('{rg}', vnet_name)
account = self.cmd("az anf account create -g %s -a '%s' -l 'westus2'" % (rg, account_name)).get_output_in_json()
pool = self.cmd("az anf pool create -g %s -a %s -p %s -l 'westus2' %s %s" % (rg, account_name, pool_name, POOL_DEFAULT, tag)).get_output_in_json()
self.cmd("az anf account create -g %s -a '%s' -l 'westus2'" % (rg, account_name)).get_output_in_json()
self.cmd("az anf pool create -g %s -a %s -p %s -l 'westus2' %s %s" % (rg, account_name, pool_name, POOL_DEFAULT, tag)).get_output_in_json()
volume1 = self.cmd("az anf volume create --resource-group %s --account-name %s --pool-name %s --volume-name %s -l 'westus2' %s --creation-token %s --subnet-id %s %s" % (rg, account_name, pool_name, volume_name1, VOLUME_DEFAULT, creation_token, subnet_id, tag)).get_output_in_json()

return volume1

@ResourceGroupPreparer()
def test_ext_list_mount_targets(self):
account_name = self.create_random_name(prefix='cli-acc-', length=24)
pool_name = self.create_random_name(prefix='cli-pool-', length=24)
account_name = self.create_random_name(prefix='cli-acc-', length=24)
pool_name = self.create_random_name(prefix='cli-pool-', length=24)
volume_name = self.create_random_name(prefix='cli-vol-', length=24)
volume = self.create_volume(account_name, pool_name, volume_name, '{rg}')
self.create_volume(account_name, pool_name, volume_name, '{rg}')

volume_list = self.cmd("anf mount-target list -g {rg} -a %s -p %s -v %s" % (account_name, pool_name, volume_name)).get_output_in_json()
assert len(volume_list) == 1


Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@

from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer

POOL_DEFAULT="--service-level 'Premium' --size 4398046511104"
POOL_DEFAULT = "--service-level 'Premium' --size 4398046511104"

# No tidy up of tests required. The resource group is automatically removed


class AzureNetAppFilesExtPoolServiceScenarioTest(ScenarioTest):
@ResourceGroupPreparer()
def test_ext_create_delete_pool(self):
account_name = self.create_random_name(prefix='cli-acc-', length=24)
pool_name = self.create_random_name(prefix='cli-pool-', length=24)
account_name = self.create_random_name(prefix='cli-acc-', length=24)
pool_name = self.create_random_name(prefix='cli-pool-', length=24)
tags = "Tag1=Value1 Tag2=Value2"

account = self.cmd("az anf account create --resource-group {rg} --account-name '%s' -l 'westus2'" % account_name).get_output_in_json()
self.cmd("az anf account create --resource-group {rg} --account-name '%s' -l 'westus2'" % account_name).get_output_in_json()
pool = self.cmd("az anf pool create --resource-group {rg} --account-name %s --pool-name %s -l 'westus2' %s --tags '%s'" % (account_name, pool_name, POOL_DEFAULT, tags)).get_output_in_json()
assert pool['name'] == account_name + '/' + pool_name
assert pool['tags']['Tag1'] == 'Value1'
Expand Down Expand Up @@ -68,18 +69,16 @@ def test_ext_get_pool_by_name(self):

@ResourceGroupPreparer()
def test_ext_update_pool(self):
account_name = self.create_random_name(prefix='cli-acc-', length=24)
pool_name = self.create_random_name(prefix='cli-pool-', length=24)
account_name = self.create_random_name(prefix='cli-acc-', length=24)
pool_name = self.create_random_name(prefix='cli-pool-', length=24)
tag = "Tag1=Value1"

account = self.cmd("az anf account create -g {rg} -a %s -l 'westus2'" % account_name).get_output_in_json()
self.cmd("az anf account create -g {rg} -a %s -l 'westus2'" % account_name).get_output_in_json()

pool = self.cmd("az anf pool create -g {rg} -a %s -p %s -l 'westus2' %s" % (account_name, pool_name, POOL_DEFAULT)).get_output_in_json()

assert pool['name'] == account_name + '/' + pool_name
pool = self.cmd("az anf pool update -g {rg} -a %s -p %s --tags %s --service-level 'Standard'" % (account_name, pool_name, tag)).get_output_in_json()
assert pool['name'] == account_name + '/' + pool_name
assert pool['name'] == account_name + '/' + pool_name
assert pool['serviceLevel'] == "Standard"
assert pool['tags']['Tag1'] == 'Value1'


Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer

POOL_DEFAULT="--service-level 'Premium' --size 4398046511104"
VOLUME_DEFAULT="--service-level 'Premium' --usage-threshold 107374182400"
POOL_DEFAULT = "--service-level 'Premium' --size 4398046511104"
VOLUME_DEFAULT = "--service-level 'Premium' --usage-threshold 107374182400"

# No tidy up of tests required. The resource group is automatically removed


class AzureNetAppFilesExtSnapshotServiceScenarioTest(ScenarioTest):
def setup_vnet(self, rg, vnet_name):
self.cmd("az network vnet create -n %s -g %s -l westus2" % (vnet_name, rg))
Expand All @@ -23,19 +24,19 @@ def create_volume(self, account_name, pool_name, volume_name1, rg, tags=None):
vnet_name = self.create_random_name(prefix='cli-vnet-', length=24)
creation_token = volume_name1
subnet_id = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/default" % (self.current_subscription(), rg, vnet_name)
tag = "--tags '%s'" % tags if tags != None else ""
tag = "--tags '%s'" % tags if tags is not None else ""

self.setup_vnet('{rg}', vnet_name)
account = self.cmd("anf account create -g %s -a '%s' -l 'westus2'" % (rg, account_name)).get_output_in_json()
pool = self.cmd("anf pool create -g %s -a %s -p %s -l 'westus2' %s %s" % (rg, account_name, pool_name, POOL_DEFAULT, tag)).get_output_in_json()
self.cmd("anf account create -g %s -a '%s' -l 'westus2'" % (rg, account_name)).get_output_in_json()
self.cmd("anf pool create -g %s -a %s -p %s -l 'westus2' %s %s" % (rg, account_name, pool_name, POOL_DEFAULT, tag)).get_output_in_json()
volume1 = self.cmd("anf volume create --resource-group %s --account-name %s --pool-name %s --volume-name %s -l 'westus2' %s --creation-token %s --subnet-id %s %s" % (rg, account_name, pool_name, volume_name1, VOLUME_DEFAULT, creation_token, subnet_id, tag)).get_output_in_json()

return volume1

@ResourceGroupPreparer()
def test_ext_create_snapshots(self):
account_name = self.create_random_name(prefix='cli-acc-', length=24)
pool_name = self.create_random_name(prefix='cli-pool-', length=24)
account_name = self.create_random_name(prefix='cli-acc-', length=24)
pool_name = self.create_random_name(prefix='cli-pool-', length=24)
volume_name = self.create_random_name(prefix='cli-vol-', length=24)
snapshot_name = self.create_random_name(prefix='cli-sn-', length=24)
rg = '{rg}'
Expand All @@ -47,31 +48,28 @@ def test_ext_create_snapshots(self):
snapshot_list = self.cmd("az anf snapshot list --resource-group %s --account-name %s --pool-name %s --volume-name %s" % (rg, account_name, pool_name, volume_name)).get_output_in_json()
assert len(snapshot_list) == 1


@ResourceGroupPreparer()
def test_ext_list_snapshots(self):
account_name = self.create_random_name(prefix='cli-acc-', length=24)
pool_name = self.create_random_name(prefix='cli-pool-', length=24)
account_name = self.create_random_name(prefix='cli-acc-', length=24)
pool_name = self.create_random_name(prefix='cli-pool-', length=24)
volume_name = self.create_random_name(prefix='cli-vol-', length=24)
snapshot_name1 = self.create_random_name(prefix='cli-sn-', length=24)
snapshot_name2 = self.create_random_name(prefix='cli-sn-', length=24)
volume = self.create_volume(account_name, pool_name, volume_name, '{rg}')
snapshot = self.cmd("az anf snapshot create -g {rg} -a %s -p %s -v %s -s %s -l 'westus2' --file-system-id %s" % (account_name, pool_name, volume_name, snapshot_name1, volume['fileSystemId'])).get_output_in_json()
snapshot = self.cmd("az anf snapshot create -g {rg} -a %s -p %s -v %s -s %s -l 'westus2' --file-system-id %s" % (account_name, pool_name, volume_name, snapshot_name2, volume['fileSystemId'])).get_output_in_json()
self.cmd("az anf snapshot create -g {rg} -a %s -p %s -v %s -s %s -l 'westus2' --file-system-id %s" % (account_name, pool_name, volume_name, snapshot_name1, volume['fileSystemId'])).get_output_in_json()
self.cmd("az anf snapshot create -g {rg} -a %s -p %s -v %s -s %s -l 'westus2' --file-system-id %s" % (account_name, pool_name, volume_name, snapshot_name2, volume['fileSystemId'])).get_output_in_json()

snapshot_list = self.cmd("az anf snapshot list -g {rg} -a %s -p %s -v %s" % (account_name, pool_name, volume_name)).get_output_in_json()
assert len(snapshot_list) == 2

@ResourceGroupPreparer()
def test_ext_get_snapshot(self):
account_name = self.create_random_name(prefix='cli-acc-', length=24)
pool_name = self.create_random_name(prefix='cli-pool-', length=24)
account_name = self.create_random_name(prefix='cli-acc-', length=24)
pool_name = self.create_random_name(prefix='cli-pool-', length=24)
volume_name = self.create_random_name(prefix='cli-vol-', length=24)
snapshot_name = self.create_random_name(prefix='cli-sn-', length=24)
volume = self.create_volume(account_name, pool_name, volume_name, '{rg}')
snapshot = self.cmd("az anf snapshot create -g {rg} -a %s -p %s -v %s -s %s -l 'westus2' --file-system-id %s" % (account_name, pool_name, volume_name, snapshot_name, volume['fileSystemId'])).get_output_in_json()

snapshot = self.cmd("az anf snapshot show -g {rg} -a %s -p %s -v %s -s %s" % (account_name, pool_name, volume_name, snapshot_name)).get_output_in_json()
assert snapshot['name'] == account_name + '/' + pool_name + '/' + volume_name + '/' + snapshot_name


assert snapshot['name'] == account_name + '/' + pool_name + '/' + volume_name + '/' + snapshot_name
Loading