Python client for the HNV (Hyper-V Network Virtualization) REST API
Go to file
Alexandru Coman 2d85269cd3
Add missing resource reference in FrontendIPConfigurations
Change the value of the "public_ip_address" field  from a
dictionary to an instance of hnv.client.Resource.

Change-Id: I2e85a7cdd42199c845526e063b7a8dbb803ee219
2017-03-27 16:41:19 +03:00
doc Rename the project from "hnv" to "hnvclient" 2017-03-27 16:21:30 +03:00
hnvclient Add missing resource reference in FrontendIPConfigurations 2017-03-27 16:41:19 +03:00
releasenotes Rename the project from "hnv" to "hnvclient" 2017-03-27 16:21:30 +03:00
.coveragerc Rename the project from "hnv" to "hnvclient" 2017-03-27 16:21:30 +03:00
.gitignore Applies OpenStack project cookiecutter 2017-03-07 15:42:40 +02:00
.gitreview Applies OpenStack project cookiecutter 2017-03-07 15:42:40 +02:00
.mailmap Applies OpenStack project cookiecutter 2017-03-07 15:42:40 +02:00
.testr.conf Applies OpenStack project cookiecutter 2017-03-07 15:42:40 +02:00
.travis.yml Remove pylint Travis-CI job 2017-03-07 15:58:22 +02:00
CONTRIBUTING.rst Applies OpenStack project cookiecutter 2017-03-07 15:42:40 +02:00
HACKING.rst Applies OpenStack project cookiecutter 2017-03-07 15:42:40 +02:00
LICENSE Applies OpenStack project cookiecutter 2017-03-07 15:42:40 +02:00
MANIFEST.in Applies OpenStack project cookiecutter 2017-03-07 15:42:40 +02:00
README.rst Rename the project from "hnv" to "hnvclient" 2017-03-27 16:21:30 +03:00
babel.cfg Applies OpenStack project cookiecutter 2017-03-07 15:42:40 +02:00
requirements.txt Change oslo.config with a global dictionary 2017-03-23 16:13:12 +02:00
setup.cfg Rename the project from "hnv" to "hnvclient" 2017-03-27 16:21:30 +03:00
setup.py Applies OpenStack project cookiecutter 2017-03-07 15:42:40 +02:00
test-requirements.txt Applies OpenStack project cookiecutter 2017-03-07 15:42:40 +02:00
tox.ini Applies OpenStack project cookiecutter 2017-03-07 15:42:40 +02:00

README.rst

python-hnvclient

image

Python client for the HNV (Hyper-V Network Virtualization) REST API.

Features

The Python interface matches the underlying REST API and can be employed in 3rd party projects.

>>> from hnvclient import client
>>> logical_networks = client.LogicalNetworks.get()
>>> for logical_network in logical_networks:
...     print(logical_network.resource_id)
...
"63606911-e053-42cf-842e-29f67c90d5c6"
"c4cd42ff-5efb-4006-ac56-479730557926"
"cd804db3-df59-4f57-8a7d-11cc3f3c4d98"

>>> logical_network = client.LogicalNetworks.get(resource_id="cd804db3-df59-4f57-8a7d-11cc3f3c4d98")
>>> logical_network
<hnvclient.client.LogicalNetworks object at 0x7fcd79419910>
>>> logical_network.provisioning_state
u'Succeeded'
>>> logical_network.subnetworks
[<hnvclient.client.LogicalSubnetworks object at 0x7fcd79419150>]
>>> logical_network.subnetworks[0].resource_id
u'4390e3d8-c527-4534-882f-906c47ffd0bb'
from __future__ import print_function

import json
import sys

from hnvclient import client


def view_logical_networks():
    """List all the available logical networks."""
    logical_networks = client.LogicalNetworks.get()
    print("Logical networks:")
    for logical_network in logical_networks:
        print("\t - ", logical_network.resource_ref)
        print("\t\t", "Logical subnetworks:")
        for logical_subnetwork in logical_network.subnetworks:
            print("\t\t - %s (%s)" % (logical_subnetwork.resource_id,
                                      logical_subnetwork.address_prefix))

        print("\t\t", "Virtual networks:")
        for virtual_network in logical_network.virtual_networks:
            print("\t\t - %s" % virtual_network.resource_ref)


def create_virtual_network():
    """Create a new virtual network on the first logical network."""
    print("Creating a new virtual network.")
    address_space = client.AddressSpace(
        address_prefixes=["192.168.133.0/24"])

    logical_network = client.Resource(
        resource_ref=client.LogicalNetworks.get()[0].resource_ref)

    virtual_network = client.VirtualNetworks(
        resource_id="hvn-test",
        address_space=address_space,
        logical_network=logical_network,
    )
    virtual_network.commit()

    print("The raw content of the new Virtual Network")
    print(json.dumps(virtual_network.dump(), indent=4))


def remove_virtual_network():
    """Remove the new virtual network."""
    print("Remove the new virtual network")
    client.VirtualNetworks.remove(resource_id="hvn-test")


def main():
    """Logical networks sample entry point."""
    client.setup()
    view_logical_networks()
    create_virtual_network()
    view_logical_networks()
    remove_virtual_network()
    view_logical_networks()