List Azure Virtual Machines via REST API - rest

I am currently attempting to get a list of all of the Virtual Machines that I have running under a Windows Azure subscription programmatically. For this, I am attempting to use the Azure REST API (https://management.core.windows.net), and not use the power-shell cmdlets.
Using the cmdlets I can run 'Get-AzureVM' and get a listing of all of the VM's with ServiceName, Name, and Status without any modifications. The problem is that I cannot find anywhere in the documentation of how to list out the VMs via the API.
I have looked through the various Azure REST API's but have not been able to find anything. The documentation for VM REST API does not show or provide a list function.
Am I missing the fundamentals somewhere?
// Create the request.
// https://management.core.windows.net/<subscription-id>/services/hostedservices
requestUri = new Uri("https://management.core.windows.net/"
+ subscriptionId
+ "/services/"
+ operation);
This is what I am using for the base of the request. I can get a list of hosted services but not the Virtual Machines.

You would need to get a list all the Cloud Services (Hosted Services), and then the deployment properties for each. Look for the deployment in the Production environment/slot. Then check for a role type of "PersistentVMRole".
VMs are really just a type of Cloud Service, along with Web and Worker roles. The Windows Azure management portal and PowerShell cmdlets abstracts this away to make things a little easier to understand and view.

Follow these steps for listing VMs:
List HostedServices using the following ListHostedServices
For each service in from the above,
a)GetDeployment by Environment(production or staging).
OR
b) Get Deployment By Name.
In either case, get the value for Deployment.getRoleInstanceList().getRoleInstance().getInstanceName().

You can use Azure node SDK to list out all VMs in your subscription
computeClient.virtualMachines.listAll(function (err, result))
More details on Azure Node SDK here: https://github.com/Azure-Samples/compute-node-manage-vm

Related

Require Azure Function to be updated through Azure Pipeline

Is there a way to require that Azure Functions be updated through an Azure pipeline, and not someone using the VSCode integration or azure functions core tools CLI?
I don't believe that there is a direct way to restrict deployment by method (AZ CLI, Az Powershell, Azure DevOps, Azure Portal, etc.), as ultimately most everything in Azure goes through REST APIs, ARM templates, etc.
What you can do is to organize your functions into a resource group or groups, to which you limit Contributor/Administrator/Owner access to the service principal associated with your Azure DevOps service connections. Allow other users the ability to read/inspect resources in that group, but only allow the service principal the right to create objects there. You may also need to allow the managed identities greater privileges to operate within that space, but the concept remains the same - limit the autonomy of interactive users in the space where your Azure Functions live.

how to register aws ec2 instance launch API in TFS service endpoint?

My requirement is, need to launch an AWS EC2 Instance through REST API while TFS running.
For that I need to register the API in TFS as Generic Service Endpoint.
I am not aware how to add the API endpoint because the endpoint contains many header values and signatures.
I hope we can pass the Signature in token.
But what need to pass for UserName?
Could anyone know how to register the AWS REST API in TFS service Endpoint.?
You should do this task via powershell script and just add a powershell step in the TFS build/release workflow. You have flexibility to run it via powershell command line without the TFS web UI. Also the script is portable. It can be invoked in TFS,Jenkins, etc.
It's not able to register aws ec2 instance API in TFS Generic Service Endpoint.
You could use a powershell script to authenticate with AWS API to launch a EC2 instance and invoke the REST API from your Build Pipeline.
Besides, you could use AWS Tools for Microsoft Visual Studio Team Services.
This tool include a new service endpoint type, AWS, to supply AWS credentials to the tasks at runtime.
It will create an AWS Credentials Connection. Select the AWS endpoint type and provide the following parameters:
A name used to refer to the credentials when configuring tasks that
require AWS credentials
AWS Access Key ID
AWS Secret Access Key
After an AWS subscription has be linked to Team Foundation Server, you could use the task deploy to Amazon EC2 with AWS CodeDeploy.
Note: Minimum supported environments
Visual Studio Team Services
Team Foundation Server 2015 Update 3 (or higher)

Get relation between Hosts and Datastores using vSphere Automation REST API

I'm trying to create VM using vSphere Automation SDK REST API and vRealize Orchestrator but the workflow in Orchestrator I'm using needs the host and datastore on which to create the VM (I'm cloning a VM using a template).
My problem is that my datastores are not shared by all clusters (and hosts) so I need to be careful to create a VM with a matching host and datastore.
With the vSphere Automation SDK REST API I can easily get the list of hosts and datastores (here's the doc I found : https://code.vmware.com/doc/preview?id=4645), but none of the "list" or "get" requests give me links between hosts and datastores.
How can I get the relations between my datastores and my hosts so that I can call Orchestrator with the correct parameters ?
Thank you.
Check out https://github.com/doublecloudinc/vim-rest-api
The REST APIs supports FULL features of vSphere APIs, and scales across many vCenter/ESXi servers. You can list all the host and pick one to get its datastore property easily with a couple of REST calls.
Also, vBrownBag tech talk: https://youtu.be/EpMlP27gEEM
Disclaimer: I am the creator of the REST APIs.

Programmatically download RDP file of Azure Resource Manager VM

I am able to create VM from a custom image using Azure resource management sdk for .net. Now, I want to download the RDP file for virtual machine programmatically. I have searched and able to find Rest API for azure 'Classic' deployments which contains an api call to download RDP file but i can't find the same in Rest API for 'ARM' deployment. Also, I can't find any such Method in .net sdk for azure.
Does there any way exist to achieve that? Please guide..
I don't know of a way to get the RDP file, but you can get all the information you need from the deployment itself. On the deployment, you can set outputs for the values you need like the publicIp dns. See this:
https://github.com/bmoore-msft/AzureRM-Samples/blob/master/VMCSEInstallFilePS/azuredeploy.json#L213-215
If your environment is more complex (load balancers, network security groups) you need to account for port numbers, etc.

Azure REST API - getting identity data

In Amazon cloud API there is the possibility to get identity data, meaning data from the running instance - on which region it is, dns ....
is there the same option in Azure? as I am creating management system in which the server is installed on a virtual machine and I need to know to which region it is related, all this using REST API
In Azure you can use Azure API Management REST API to get all sort of information for Azure:
ex:
Lists all of the resources in a subscription:
https://management.azure.com/subscriptions/{subscription-id}/resources?$top={top}$skiptoken={skiptoken}&$filter={filter}&api-version={api-version}
For the complete documentation look at this page here:
https://msdn.microsoft.com/en-us/library/azure/dn776326.aspx
You can do similar things using Powershell scripts as well.