Azure Rest Api 开发者社区
Azure Rest Api Community for developer
我是一名开发人员并尝试使用 rest API 将 NSG 与子网分离,但找不到任何好的答案请告诉我 Azure Rest 社区 API 以便我可以在那里提出我的问题.
如果要取消NSG与子网的关联,请参考以下步骤
- 创建服务主体并将贡献者角色分配给 sp
az login
# it will create a service principal and assign a contributor rolen to the sp
az ad sp create-for-rbac -n "MyApp" --sdk-auth
- 代码
var msRestNodeAuth = require("@azure/ms-rest-nodeauth");
var { NetworkManagementClient } = require("@azure/arm-network");
const clientId = "sp clientId";
const secret = "sp clientSecret";
const domain = "hanxia.onmicrosoft.com";
const subscriptionId = "e5b0fcfa-e****e5fe29f4c68";
async function main() {
try {
const creds = await msRestNodeAuth.loginWithServicePrincipalSecret(
clientId,
secret,
domain,
);
const client = new NetworkManagementClient(creds, subscriptionId);
const resourceGroupName = "testvnet";
const virtualNetworkName = "test";
const subnetName = "default";
//get the subnet
const subnetrespose = await client.subnets.get(
resourceGroupName,
virtualNetworkName,
subnetName,
);
const subnet = subnetrespose._response.parsedBody;
console.log(subnet);
console.log("----------update-----------");
subnet.networkSecurityGroup = null;
const res = await client.subnets.createOrUpdate(
resourceGroupName,
virtualNetworkName,
subnetName,
subnet,
);
console.log(res._response.parsedBody);
} catch (error) {
console.log(error);
}
}
main();
我是一名开发人员并尝试使用 rest API 将 NSG 与子网分离,但找不到任何好的答案请告诉我 Azure Rest 社区 API 以便我可以在那里提出我的问题.
如果要取消NSG与子网的关联,请参考以下步骤
- 创建服务主体并将贡献者角色分配给 sp
az login
# it will create a service principal and assign a contributor rolen to the sp
az ad sp create-for-rbac -n "MyApp" --sdk-auth
- 代码
var msRestNodeAuth = require("@azure/ms-rest-nodeauth");
var { NetworkManagementClient } = require("@azure/arm-network");
const clientId = "sp clientId";
const secret = "sp clientSecret";
const domain = "hanxia.onmicrosoft.com";
const subscriptionId = "e5b0fcfa-e****e5fe29f4c68";
async function main() {
try {
const creds = await msRestNodeAuth.loginWithServicePrincipalSecret(
clientId,
secret,
domain,
);
const client = new NetworkManagementClient(creds, subscriptionId);
const resourceGroupName = "testvnet";
const virtualNetworkName = "test";
const subnetName = "default";
//get the subnet
const subnetrespose = await client.subnets.get(
resourceGroupName,
virtualNetworkName,
subnetName,
);
const subnet = subnetrespose._response.parsedBody;
console.log(subnet);
console.log("----------update-----------");
subnet.networkSecurityGroup = null;
const res = await client.subnets.createOrUpdate(
resourceGroupName,
virtualNetworkName,
subnetName,
subnet,
);
console.log(res._response.parsedBody);
} catch (error) {
console.log(error);
}
}
main();