How do I list all the endpoints in the Azure Cloud and not just the endpoints on the current role instance?
I've tried the following code but it only lists the endpoints on the current Azure instance and not on any other Azure instances:
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();
}
Output from running on a multiple role project where each role has multiple instances:
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
If I re-run the above query I randomly get the output from the role instances deployment22(203).CloudService1.Www_IN_0 to deployment22(203).CloudService1.Www_IN_4 as decided by which instance that processes the ASP.NET web form that runs the above code snippet. Example:
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