-
Notifications
You must be signed in to change notification settings - Fork 130
/
manage_app_service_plan.py
86 lines (72 loc) · 2.37 KB
/
manage_app_service_plan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.web import WebSiteManagementClient
from azure.mgmt.resource import ResourceManagementClient
def main():
SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None)
GROUP_NAME = "testgroupx"
APP_SERVICE_PLAN = "appserviceplanxxyyzz"
# Create client
# # For other authentication approaches, please see: https://pypi.org/project/azure-identity/
resource_client = ResourceManagementClient(
credential=DefaultAzureCredential(),
subscription_id=SUBSCRIPTION_ID
)
web_client = WebSiteManagementClient(
credential=DefaultAzureCredential(),
subscription_id=SUBSCRIPTION_ID
)
# Create resource group
resource_client.resource_groups.create_or_update(
GROUP_NAME,
{"location": "eastus"}
)
# Create app service plan
app_service_plan = web_client.app_service_plans.begin_create_or_update(
GROUP_NAME,
APP_SERVICE_PLAN,
{
"kind": "app",
"location": "eastus",
"sku": {
"name": "P1",
"tier": "Premium",
"size": "P1",
"family": "P",
"capacity": "1"
}
}
).result()
print("Create app service plan:\n{}".format(app_service_plan))
# Get app service plan
app_service_plan = web_client.app_service_plans.get(
GROUP_NAME,
APP_SERVICE_PLAN
)
print("Get app service plan:\n{}".format(app_service_plan))
# Update app service plan
app_service_plan = web_client.app_service_plans.update(
GROUP_NAME,
APP_SERVICE_PLAN,
{
"kind": "app"
}
)
print("Update app service plan:\n{}".format(app_service_plan))
# Delete app service plan
app_service_plan = web_client.app_service_plans.delete(
GROUP_NAME,
APP_SERVICE_PLAN
)
print("Delete app service plan.\n")
# Delete Group
resource_client.resource_groups.begin_delete(
GROUP_NAME
).result()
if __name__ == "__main__":
main()