Git Product home page Git Product logo

virtual-machines-python-vm-data-list's Introduction

services platforms author date
virtual-machines
python
abhisekb
June, 2017

Azure Management API IaaS VM Inventory Sample Scripts

This project contains several scripts that demonstrate how to use a simple technique to extract, transform, and generate an inventory of virtual machines (VMs) associated with a subscription. This will include VMs using both the Azure Resource Manager (ARM) and Classic (ASM) deployment models.

Read the accompanying How-To Guide:

There are three main parts to the example code:

  1. An extraction process to pull the information on VMs directly from the Azure Management APIs using either PowerShell on Windows or the Azure CLI tool on Linux. This process produces several detailed JSON files.

  2. A transform process using Python scripts to combine and regularize the information extracted from the APIs, and output that data to a combined JSON file.

  3. An Inventory process to convert the transformed JSON file into easily readable CSV files.

Prerequisites

Instructions

Save the samplecode folder to a location on your local machine. This folder contains a sample pyproj file and Visual Studio solution file for the project. It also contains the following sub-folders:

  • extract - contains the PowerShell and Bash scripts used to extract information from the Azure Management APIs

  • transform - contains the transform Python script

  • inventory - contains the inventory Python script that will generate human readable CSV files

  • data - location where extracted JSON data and output CSVs will be stored

  • sampledata - contains pre-generated sample files

  • JMESPath.py library for JSON processing in Python

  • Admin or Co-admin rights to the subscription you want to extract information from.

Extraction on Windows

To run the PowerShell scripts on Windows, simply open PowerShell and navigate to the samplecode\extract\windows folder and run:

.\extract.ps1 <Subscripton ID>

The script will ask you to login two times: once for ARM mode and again for ASM mode. On completion, several files will be generated with the VM and storage account information for the subscription you specified. These files will be stored in the samplecode\data\<Subscription ID> folder.

Extraction on Linux

Before running the extraction script, you need to login to the Azure CLI apps. In CLI 2.0 you can log on to a subscription using:

az login

In CLI 1.0, you can log on to a subscription using:

azure login

Once both are logged in navigate to the samplecode/extract/linux folder and run:

bash extract.sh <Subscripton ID>

On completion, several files will be generated with the VM and storage account information for the subscription you specified. These files will be stored in the samplecode/data/<Subscription ID> folder.

Transform

Navigate to the folder samplecode/transform and run:

python transform.py <Subscripton ID>

This will load the data from the specified subscription and generate a combined transformeddata.json file in the samplecode/data/<Subscription ID> folder.

Inventory

Navigate to the folder samplecode/inventory and run:

python inventory.py <Subscripton ID>

This will load the transformeddata.json file and generate two CSV files in the samplecode/data/<Subscription ID> folder:

  • vmInventory.csv - a list of VMs and information about them

  • storageAccountInventory.csv - a list of all storage drives used by the VMs

MSFT OSS Code Of Conduct Notice

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

virtual-machines-python-vm-data-list's People

Contributors

microsoftopensource avatar msftgits avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.