gpt4 book ai didi

azure - 列出 Azure 云中的所有实例终结点

转载 作者:行者123 更新时间:2023-12-03 03:17:46 25 4
gpt4 key购买 nike

如何列出 Azure 云中的所有端点,而不仅仅是当前角色实例上的端点?

我已尝试以下代码,但它仅列出当前 Azure 实例上的端点,而不列出任何其他 Azure 实例上的端点:

void ListCloudInstances()
{
var instances = new StringBuilder("");

foreach (var role in RoleEnvironment.Roles)
{
instances.AppendFormat("<h2>Role <em>{0}</em></h2><br/>", role.Value.Name);
if (role.Value.Instances.Count == 0)
instances.AppendFormat("<small>Role <em>{0}</em> has no role instances</small><br/><br/>", role.Value.Name);

foreach (var roleInstance in role.Value.Instances)
{
var currentRoleMarker = RoleEnvironment.CurrentRoleInstance.Id == roleInstance.Id ? " *" : String.Empty;
instances.AppendFormat("<h3>Role <em>{2}</em> instance <em>{0}</em>{1}</h3><br/>",
roleInstance.Id, currentRoleMarker, roleInstance.Role.Name);

// List some metadata about the role instance
instances.AppendFormat("<p>Role instance fault domain: {0}</p>", roleInstance.FaultDomain);
instances.AppendFormat("<p>Role for the instance: {0}</p>", roleInstance.Role.Name);
instances.AppendFormat("<p>Role instance update domain: {0}</p><br/>", roleInstance.UpdateDomain);

// List the endpoints
instances.AppendFormat("<h4>Role <em>{1}</em> instance <em>{0}</em> endpoints</h4><br/>", roleInstance.Id,
roleInstance.Role.Name);

foreach (RoleInstanceEndpoint instanceEndpoint in roleInstance.InstanceEndpoints.Values)
{
if (roleInstance.Role.Name == "Www")
instances.AppendFormat("<p><a href=\"{0}://{1}/Admin/Settings.aspx\" target=\"_blank\">{1}</a></p>",
instanceEndpoint.Protocol, instanceEndpoint.IPEndpoint);
else instances.AppendFormat("<p>Instance endpoint IP address, port, and protocol : {0} {1}</p>",
instanceEndpoint.IPEndpoint, instanceEndpoint.Protocol);
}
}
}

instances.AppendFormat("<small>* Current role instance is {0}</small>", RoleEnvironment.CurrentRoleInstance.Id);

CloudHtml.Text = instances.ToString();
}

在每个角色都有多个实例的多角色项目上运行的输出:

Role MultiThreadedWorkerRole

Role MultiThreadedWorkerRole has no role instances

Role Www

Role Www instance deployment22(203).CloudService1.Www_IN_1 *

Role instance fault domain: 1

Role for the instance: Www

Role instance update domain: 1

Role Www instance deployment22(203).CloudService1.Www_IN_1 endpoints

127.255.0.3:82

127.255.0.3:444

  • Current role instance is deployment22(203).CloudService1.Www_IN_1

如果我重新运行上述查询,我​​会随机获取从角色实例deployment22(203).CloudService1.Www_IN_0到deployment22(203).CloudService1.Www_IN_4的输出,具体取决于处理 ASP.NET Web 表单的实例运行上面的代码片段。示例:

Role MultiThreadedWorkerRole

Role MultiThreadedWorkerRole has no role instances

Role Www

Role Www instance deployment22(203).CloudService1.Www_IN_0 *

Role instance fault domain: 0

Role for the instance: Www

Role instance update domain: 0

Role Www instance deployment22(203).CloudService1.Www_IN_0 endpoints

127.255.0.2:82

127.255.0.2:444

  • Current role instance is deployment22(203).CloudService1.Www_IN_0

最佳答案

我相信关键在于 documentation of the RoleEnvironment's Roles property 上所做的以下注释-

At least one internal endpoint must be defined for a role to enable instances to be known at runtime

我刚刚尝试过创建一个具有两个角色的云项目,并使用 RoleEnvironment.Roles 迭代这些角色,没有任何内部端点,只有当前角色的实例可用。

将内部端点添加到其他角色后,它的实例已为我加载。但是 - 角色实例的 InstanceEndpoints 集合中仅列出了内部端点。我看不到他们公开的外部端点。

关于azure - 列出 Azure 云中的所有实例终结点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20567435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com