1# coding: utf-8
2
3#-------------------------------------------------------------------------
4# Copyright (c) Microsoft Corporation. All rights reserved.
5# Licensed under the MIT License. See License.txt in the project root for
6# license information.
7#--------------------------------------------------------------------------
8
9# Current Operation Coverage:
10#   InstancePools: 0/6
11
12import unittest
13
14import azure.mgmt.sql
15from devtools_testutils import AzureMgmtTestCase, RandomNameResourceGroupPreparer
16
17AZURE_LOCATION = 'eastus'
18
19class MgmtSqlTest(AzureMgmtTestCase):
20
21    def setUp(self):
22        super(MgmtSqlTest, self).setUp()
23        self.mgmt_client = self.create_mgmt_client(
24            azure.mgmt.sql.SqlManagementClient
25        )
26
27        if self.is_live:
28            from azure.mgmt.network import NetworkManagementClient
29            self.network_client = self.create_mgmt_client(
30                NetworkManagementClient
31            )
32
33    def create_virtual_network(self, group_name, location, network_name, subnet_name):
34
35        azure_operation_poller = self.network_client.virtual_networks.begin_create_or_update(
36            group_name,
37            network_name,
38            {
39                'location': location,
40                'address_space': {
41                    'address_prefixes': ['10.0.0.0/16']
42                }
43            },
44        )
45        result_create = azure_operation_poller.result()
46
47        async_subnet_creation = self.network_client.subnets.begin_create_or_update(
48            group_name,
49            network_name,
50            subnet_name,
51            {'address_prefix': '10.0.0.0/24'}
52        )
53        subnet_info = async_subnet_creation.result()
54
55        return subnet_info
56
57    @unittest.skip("unavailable")
58    @RandomNameResourceGroupPreparer(location=AZURE_LOCATION)
59    def test_instance_pool(self, resource_group):
60
61        SUBSCRIPTION_ID = self.settings.SUBSCRIPTION_ID
62        RESOURCE_GROUP = resource_group.name
63        VIRTUAL_NETWORK_NAME = "myVirtualNetwork"
64        SUBNET_NAME = "InstancePool"
65        INSTANCE_POOL_NAME = "myinstancepool"
66
67        if self.is_live:
68            self.create_virtual_network(RESOURCE_GROUP, AZURE_LOCATION, VIRTUAL_NETWORK_NAME, SUBNET_NAME)
69
70#--------------------------------------------------------------------------
71        # /InstancePools/put/Create an instance pool with min properties.[put]
72#--------------------------------------------------------------------------
73        BODY = {
74          "location": "westeurope",
75          "sku": {
76            "name": "GP_Gen5",
77            "tier": "GeneralPurpose",
78            "family": "Gen5"
79          },
80          "v_cores": 8,
81          "subnet_id": "/subscriptions/" + SUBSCRIPTION_ID + "/resourceGroups/" + RESOURCE_GROUP + "/providers/Microsoft.Network/virtualNetworks/" + VIRTUAL_NETWORK_NAME + "/subnets/" + SUBNET_NAME,
82          "license_type": "LicenseIncluded"
83        }
84        result = self.mgmt_client.instance_pools.begin_create_or_update(resource_group_name=RESOURCE_GROUP, instance_pool_name=INSTANCE_POOL_NAME, parameters=BODY)
85        result = result.result()
86
87#--------------------------------------------------------------------------
88        # /InstancePools/get/Get an instance pool[get]
89#--------------------------------------------------------------------------
90        result = self.mgmt_client.instance_pools.get(resource_group_name=RESOURCE_GROUP, instance_pool_name=INSTANCE_POOL_NAME)
91
92#--------------------------------------------------------------------------
93        # /InstancePools/get/List instance pools by resource group[get]
94#--------------------------------------------------------------------------
95        result = self.mgmt_client.instance_pools.list_by_resource_group(resource_group_name=RESOURCE_GROUP)
96
97#--------------------------------------------------------------------------
98        # /InstancePools/get/List instance pools in the subscription[get]
99#--------------------------------------------------------------------------
100        result = self.mgmt_client.instance_pools.list()
101
102#--------------------------------------------------------------------------
103        # /InstancePools/patch/Patch an instance pool[patch]
104#--------------------------------------------------------------------------
105        BODY = {
106          "tags": {
107            "x": "y"
108          }
109        }
110        result = self.mgmt_client.instance_pools.begin_update(resource_group_name=RESOURCE_GROUP, instance_pool_name=INSTANCE_POOL_NAME, parameters=BODY)
111        result = result.result()
112
113#--------------------------------------------------------------------------
114        # /InstancePools/delete/Delete an instance pool[delete]
115#--------------------------------------------------------------------------
116        result = self.mgmt_client.instance_pools.begin_delete(resource_group_name=RESOURCE_GROUP, instance_pool_name=INSTANCE_POOL_NAME)
117        result = result.result()
118