Giter Club home page Giter Club logo

az.cli's Introduction

Az.Cli

PyPi Build Status master Build Status dev

Python azure.cli.core interface to execute az Azure CLI commands in python.

The method returns a named tuple AzResult = namedtuple('AzResult', ['exit_code', 'result_dict', 'log']). The error_code where 0 == success. A result_dict containing successfull return as a python dictionary. On failure (error_code > 0) a log message inside log as a string.

Usage

Install the package

pip install az.cli

Login using az login or sign in using a service principal.

Under the hood the package uses the ~/.azure folder to persist and retrieve config.

Example

from az.cli import az

# AzResult = namedtuple('AzResult', ['exit_code', 'result_dict', 'log'])
exit_code, result_dict, logs = az("group show -n test")

# On 0 (SUCCESS) print result_dict, otherwise get info from `logs`
if exit_code == 0:
    print (result_dict)
else:
    print(logs)

Interactive

You can run the command interactively to traverse the dictionary. Navigate to src and run python3. Import the library from az.cli import az and run any command by executing the method az("<my command>") to invoke Azure CLI.

# cd src
# python3
from az.cli import az
# on Success, the `error_code` is 0 and the result_dict contains the output
az("group list") # list return tuple (exit_code, result_dict, log)
az("group list")[0] # 0
az("group list")[1] # print result_dict
az("group list")[1][0]['id'] # enumerate the id of the first element in dictionary

# On Error, the `error_code` will be != 1 and the log is present
az("group show -n does-not-exsist") # list return tuple (exit_code, result_dict, log)
az("group show -n does-not-exsist")[0] # 3
az("group show -n does-not-exsist")[2] # print the log

Build

Local Development

  • install python3
  • install REQUIREMENTS.txt using make init

I recommend to use Python3 virtual environments.

# sets up environment
make env
# installs requirements
make init

Docker

To build the image run the following in order.

# Runs docker build & create
make create

Run

After the container is build & created you can run the az.cli interactivly.

# Run docker run
make run

az.cli's People

Contributors

markwarneke 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.