forked from Azure-Samples/azure-samples-python-management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_wcfrelay.py
94 lines (80 loc) · 2.46 KB
/
manage_wcfrelay.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
87
88
89
90
91
92
93
94
# --------------------------------------------------------------------------
# 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.relay import RelayAPI
from azure.mgmt.resource import ResourceManagementClient
def main():
SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None)
GROUP_NAME = "testgroupx"
WCFRELAY = "wcfrelayxxyyzz"
NAMESPACE = "namespacexxyze"
# Create client
# # For other authentication approaches, please see: https://pypi.org/project/azure-identity/
resource_client = ResourceManagementClient(
credential=DefaultAzureCredential(),
subscription_id=SUBSCRIPTION_ID
)
relay_client = RelayAPI(
credential=DefaultAzureCredential(),
subscription_id=SUBSCRIPTION_ID
)
# Create resource group
resource_client.resource_groups.create_or_update(
GROUP_NAME,
{"location": "eastus"}
)
# - init depended resources -
# Create namespace
namespace = relay_client.namespaces.begin_create_or_update(
GROUP_NAME,
NAMESPACE,
{
"location": "eastus",
"tags": {
"tag1": "value1",
"tag2": "value2"
},
"sku": {
"tier": "standard"
}
}
).result()
print("Create namespace:\n{}".format(namespace))
# - end -
# Create wcfrelay
wcfrelay = relay_client.wcf_relays.create_or_update(
GROUP_NAME,
NAMESPACE,
WCFRELAY,
{
"relay_type": "NetTcp",
"requires_client_authorization": True,
"requires_transport_security": True,
"user_metadata": "User dta for WcfRelay"
}
)
print("Create wcfrelay:\n{}".format(wcfrelay))
# Get wcfrelay
wcfrelay = relay_client.wcf_relays.get(
GROUP_NAME,
NAMESPACE,
WCFRELAY
)
print("Get wcfrelay:\n{}".format(wcfrelay))
# Delete wcfrelay
wcfrelay = relay_client.wcf_relays.delete(
GROUP_NAME,
NAMESPACE,
WCFRELAY
)
print("Delete wcfrelay.\n")
# Delete Group
resource_client.resource_groups.begin_delete(
GROUP_NAME
).result()
if __name__ == "__main__":
main()