Python client for the HNV (Hyper-V Network Virtualization) REST API
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OpenDev Sysadmins 9efa079c80 OpenDev Migration Patch 1 month ago
doc Rename the project from "hnv" to "hnvclient" 2 years ago
hnvclient Add missing resource reference in FrontendIPConfigurations 2 years ago
releasenotes Rename the project from "hnv" to "hnvclient" 2 years ago
.coveragerc Rename the project from "hnv" to "hnvclient" 2 years ago
.gitignore Applies OpenStack project cookiecutter 2 years ago
.gitreview OpenDev Migration Patch 1 month ago
.mailmap Applies OpenStack project cookiecutter 2 years ago
.testr.conf Applies OpenStack project cookiecutter 2 years ago
.travis.yml Remove pylint Travis-CI job 2 years ago
CONTRIBUTING.rst Applies OpenStack project cookiecutter 2 years ago
HACKING.rst Applies OpenStack project cookiecutter 2 years ago
LICENSE Applies OpenStack project cookiecutter 2 years ago
MANIFEST.in Applies OpenStack project cookiecutter 2 years ago
README.rst Rename the project from "hnv" to "hnvclient" 2 years ago
babel.cfg Applies OpenStack project cookiecutter 2 years ago
requirements.txt Change oslo.config with a global dictionary 2 years ago
setup.cfg Rename the project from "hnv" to "hnvclient" 2 years ago
setup.py Applies OpenStack project cookiecutter 2 years ago
test-requirements.txt Applies OpenStack project cookiecutter 2 years ago
tox.ini Applies OpenStack project cookiecutter 2 years ago

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 __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()