0
votes

Is it possible to connect to Azure cloud from a Linux script, to get information about all resources available (virtual machines, networks, cloud services etc.)?

I'm not the administrator of the Azure cloud in question, but I have VPN access to the network, have access to the management portal and have SSH access to all Linux servers in that cloud.

I would like to be able to: 1) connect to the cloud (with the same credentials as when I log into Azure management portal) 2) retrieve a list of resources and from that list retrieve detailed information about each resource 3) log into each Linux instance and retrieve some files (this point I know how to)

PS. If someone knows how to do the first two points above in Java I would really appreciate it too. Any other language is not relevant.

2
The easiest way to achieve this is to leverage the Management Portal (assuming the Administrator hasn't restricted your access to resources). There isn't an 'uber script' that will give you all deployed resources in a subscription.Simon W

2 Answers

0
votes

I would comment and ask these questions, but I don't have enough point yet. I'm assuming you know about the azure java sdk:

http://dl.windowsazure.com/javadoc/

We would need to know exactly what services you are querying.

Azure services are seperated into categories and would need separate queries done. Things like "compute" which could get a list of vm's, web roles, and worker roles could be done with this:

DeploymentOperations getDeploymentsOperations()

http://dl.windowsazure.com/javadoc/com/microsoft/windowsazure/management/compute/DeploymentOperations.html

Same goes for: network http://dl.windowsazure.com/javadoc/com/microsoft/windowsazure/management/network/NetworkManagementClient.html

mediaservices http://dl.windowsazure.com/javadoc/com/microsoft/windowsazure/management/mediaservices/package-summary.html

... and storage, and much more. Each has different object types that need to be handled different ways. If you're just looking for a list, the management portal then all items is definitely the easiest.

Hope this helps,

=Devon

0
votes

Azure makes available azure-cli (a Node.js module) which you can call from your shell or other scripts. If you pass --json to the operations, you can parse the output with jq or similar JSON-parsing tools.

Once you have Node.js and npm, install with:

npm install azure-cli -g

Then you need to login (azure login if you login with anything that can't be used to login to, say, Xbox - or azure account download then azure account import for the rest)

Here's an example:

azure site list --json | jq '.[] | [.name, .state]'
[
  "alpha",
  "Stopped"
]
[
  "beta",
  "Running"
]
[
...

The Python scripts MS Open Tech has open sourced on GitHub could also save some time. They work with Zabbix and Nagios. HTH.