Tricks for Deleting Windows Azure Virtual Machines via the REST API

While I call this post “tricks” for deleting a Windows Azure Virtual Machine it really is not a trick.  It does require a little deeper understanding of how Windows Azure creates and hosts Virtual Machines in order to use the REST API to delete them.

Let us start with some background.  When you use the Windows Azure Portal to create a new Virtual Machine, a hidden service is created for you that will host the virtual machine role.  This will allow more than one Role (i.e. Virtual Machine) to be connected to this service to allow for the automatic round-robin of calls made to the exposed ports.

Below is a list of the Services in one of my Azure Account.

Using the REST API to list all Services, I see that not all of the services returned are shown on the screen in the portal.  The service named Test0206D is not listed inside the portal.

  <HostedService>
    <Url>https://management.core.windows.net/<subscription-id>/services/hostedservices/Test0206D</Url>
    <ServiceName>Test0206D</ServiceName>
    <HostedServiceProperties>
      <Description>Implicitly created hosted service2013-02-07 01:20</Description>
      <Location>West US</Location>
      <Label>VGVzdDAyMqZE</Label>
      <Status>Created</Status>
      <DateCreated>2013-02-07T01:20:58Z</DateCreated>
      <DateLastModified>2013-02-07T01:21:32Z</DateLastModified>
      <ExtendedProperties />
    </HostedServiceProperties>
  </HostedService>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

In this case the Description clearly tells us this was created for us and when.  When we delete a Virtual Machine, the service will start to show up inside the portal.  If you never want to deploy a new Virtual Machine to that service again, it can be deleted.  Otherwise, keeping the service allows the DNS Name to be reserved and allows a new Virtual Machine Role to be added to this service at a later point. 

In order to Add a new Role (i.e. Virtual Machine) to an existing service, use the From Gallery option to create the Virtual Machine. Then, on step 4, Virtual Machine mode, select the Connect To An Existing Virtual Machine option. You will get a drop down of available options.

This background leads to the reason it might be tricky to delete a Virtual Machine using the REST API.

To Delete a stand-alone Virtual Machine

In an earlier blog post I listed the way to delete a Virtual Machine was to do an HTTP DELETE to the following URL.

https://management.core.windows.net/<Subscription-ID>/services/hostedservices/<Service-Name>/deploymentslots/Production

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

While this work, it only works in the case of a strand-alone Virtual Machine.  If you do not know if the Virtual Machine is stand-along or attached, do an HTTP GET to the URL above.  If you only have one <Role> element than it is a stand-alone Virtual Machine.

To Delete a Virtual Machine that is attached to another Virtual Machine

In order to Delete a Virtual Machine that is part of another service, you need to Remove the PersistentVMRole.  This is done by an HTTP DELETE to the following URL.

https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/<deployment-name>/roles/<vm-name>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

The service name and virtual machine name are straight forward but the deployment name is tricky.  The deployment name is usually the Service Name but it can also be the name of the first virtual machine you put into the service.  To find out for sure, do an HTTP GET to the following URL to get the details of the service deployment.

https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deploymentslots/Production

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

This will return an XML response that looks like the following.

<Deployment xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
  <Name>Test0202A</Name>
  <DeploymentSlot>Production</DeploymentSlot>
  ...removed...
</Deployment>

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

The Name element is the name of the Deployment. 

In summary, a single call can be made to delete a stand-alone Virtual Machine.  For scenarios that join several Virtual Machines together inside a single service it takes a deeper understanding of that service’s properties in order to remove a Virtual Machine from that service.

Looking for a simple tool to work with the Windows Azure REST APIs?  I have a free tool here that greatly simplifies making REST calls.

SP2013: Adding an Embedded Yammer Feed to SharePoint

While setting up a new SharePoint solution one of the requirements was to embed a
Yammer Feed.

So I followed the help document only to have an unusual situation:

1) the feed wouldnt render in browse mode.

2) the feed WOULD render in Edit Mode.

The key to the situation was to declare a little more on the sample script Yammer
gave – adding ’text/javascript’

Here’s the working script – (one for the bat -utility belt)

*tested from Win8, Firefox *

<script data-app-id=’hyB2pTvrL36Y50py8EWj6A’ type=’text/javascript’ src=’https://assets.yammer.com/platform/yam.js’></script>
<script type=’text/javascript’>
yam.connect.embedFeed(
{ container: ‘#embedded-feed’
, network: ‘yournetworkhere’

});
</script>
<div id=’embedded-feed’></div>

Blog Post by: Mick Badran

MVC4 Makes it Easier to Create Desktop and Mobile Web Applications

Last year I wrote an article that expressed the importance of developing not only desktop solutions but mobile ones as well.  Since then it has become increasingly important to present not only to a desktop market, but to a mobile one as well.
That said, this article isn’t about convincing you to move to a desktop-mobile […]
Blog Post by: Karl Schwirz

WPC HIPAA Database Toolkit for BizTalk

Originally posted on: http://geekswithblogs.net/wmichel/archive/2013/02/06/wpc-db-toolkit.aspx

I created a post on the WPC HIPAA DB Toolkit for Microsoft BizTalk. The post provides an introduction to the basic capabilities of the toolkit; a description of how to install the toolkit and I go through a simple example of how to use it.

Introducing the WPC HIPAA Database Toolkit

BizTalk Community Series: Introducing Colin Meade

A few weeks ago I presented at the London BizTalk Summit 2013. During this event I met a few BizTalk professionals face to face, which I interviewed in the past for these community series. I for instance met Naushad Alam and Stuart Brierly. I also ran into Colin Meade.

Colin is a Senior Integration Consultant working for Spanish Point Technologies in Ireland. He is originally from Dublin, but he

Regular vs Threshold Monitoring alarms in BizTalk360

In BizTalk360 you can setup monitoring in two different modes, either to receive regular periodic updates about the health of the system or updates based on threshold violations. Example: A receive location is disabled, that’s supposed to be enabled. Regular Alarms Regular alarms are like your daily early morning wake up calls. You are fast […]

The post Regular vs Threshold Monitoring alarms in BizTalk360 appeared first on BizTalk360 Blog.

Blog Post by: Saravana Kumar

Invoking a web service returning ISO-8859-1 encoded data with BizTalk Server 2010

TheTextMessageEncodingBindingElementof
WCF supports only the UTF-8, UTF-16 and Big Endean Unicode encodings. If the
web service returns response in some other encoding e.g. ISO-8859-1 need to be
consumed in BizTalk Server 2010 then the following error get logged in the
event viewer:

System.ServiceModel.ProtocolException:
The content type text/xml of the response message does not match