# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
# pylint: disable=too-many-lines

from azure.cli.testsdk import *


class QumuloScenario(ScenarioTest):

    @ResourceGroupPreparer(location='eastus')
    def test_file_system(self):
        email = self.cmd('account show').get_output_in_json()['user']['name']
        self.kwargs.update({
            'vnet': self.create_random_name('vnet', 10),
            'subnet': self.create_random_name('subnet', 15),
            'sys_name': self.create_random_name('sys', 10),
            'email': email
        })
        self.cmd('network vnet create -n {vnet} -g {rg} --address-prefix 20.0.0.0/24')
        subnet_id = self.cmd('network vnet subnet create -n {subnet} -g {rg} --address-prefix 20.0.0.0/24 --vnet-name {vnet} --delegations Qumulo.Storage/fileSystems').get_output_in_json()['id']
        self.kwargs.update({
            'subnet_id': subnet_id
        })
        self.cmd('qumulo storage file-system create -n {sys_name} -g {rg} --admin-password Password01! '
                 '--delegated-subnet-id {subnet_id} --initial-capacity 50 '
                 '--marketplace-details {{offerId:qumulo-saas-mpp,planId:qumulo-on-azure-v1%%gmz7xq9ge3py%%P1M,publisherId:qumulo1584033880660}} '
                 '--storage-sku Standard --user-details "{{email:{email}}}" '
                 '--availability-zone 1 --tags {{tag:test}}',
                 checks=[
                     self.check('name', '{sys_name}'),
                     self.check('marketplaceDetails.planId', 'qumulo-on-azure-v1%%gmz7xq9ge3py%%P1M'),
                     self.check('marketplaceDetails.offerId', 'qumulo-saas-mpp'),
                     self.check('marketplaceDetails.publisherId', 'qumulo1584033880660'),
                     self.check('delegatedSubnetId', '{subnet_id}'),
                     self.check('storageSku', 'Standard'),
                     self.check('initialCapacity', 50),
                     self.check('availabilityZone', '1'),
                     self.check('tags.tag', 'test')
                 ])
        self.cmd('qumulo storage file-system show -n {sys_name} -g {rg}', checks=[
            self.check('name', '{sys_name}'),
            self.check('marketplaceDetails.planId', 'qumulo-on-azure-v1%%gmz7xq9ge3py%%P1M'),
            self.check('marketplaceDetails.offerId', 'qumulo-saas-mpp'),
            self.check('marketplaceDetails.publisherId', 'qumulo1584033880660'),
            self.check('delegatedSubnetId', '{subnet_id}'),
            self.check('storageSku', 'Standard'),
            self.check('initialCapacity', 50),
            self.check('availabilityZone', '1'),
            self.check('tags.tag', 'test')
        ])
        self.cmd('qumulo storage file-system list -g {rg}', checks=[
            self.check('[0].name', '{sys_name}'),
            self.check('[0].marketplaceDetails.planId', 'qumulo-on-azure-v1%%gmz7xq9ge3py%%P1M'),
            self.check('[0].marketplaceDetails.offerId', 'qumulo-saas-mpp'),
            self.check('[0].marketplaceDetails.publisherId', 'qumulo1584033880660'),
            self.check('[0].delegatedSubnetId', '{subnet_id}'),
            self.check('[0].storageSku', 'Standard'),
            self.check('[0].initialCapacity', 50),
            self.check('[0].availabilityZone', '1'),
            self.check('[0].tags.tag', 'test')
        ])
        self.cmd('qumulo storage file-system delete -n {sys_name} -g {rg} -y')
