Example #1
0
# Specify parameters of the Edge to be created - as argument
p_or_s = 'None'

while p_or_s != 'p' and p_or_s != 's':
    p_or_s = raw_input(
        "Which edge do you want to configure? \n primary - p, secondary - s    p/s[p]: "
    ) or 'p'

if p_or_s == 'p':
    path = 'inputs/pe_primary_' + seldc(sys.argv[1:]) + '.yml'
else:
    path = 'inputs/pe_secondary_' + seldc(sys.argv[1:]) + '.yml'

# Create an instance of Class vSphere
cred = credentials(inputs)
nsx = NSX(*cred)

with open(path, 'r') as f:
    s = f.read()

# Read the directory of credentials from file
pe = yaml.load(s)

# Find the edge
print('\nSearching for edge-id')
try:
    edgeid = nsx.findedge(pe['name'])
except:
    print("Edge doesn't exist")
    sys.exit(1)
Example #2
0
#! /usr/bin/env python
"""
===================================================================================================
   Author:         Petr Nemec
   Description:    Resolves edge name to edge-id
   Date:           2017-10-04
===================================================================================================
"""

from nsx import NSX
from nsx import credentials
from nsx import seldc
import sys

# Select the instance of NSX manager to be configured - as argument
inputs = 'inputs/nsx_' + seldc(sys.argv[1:]) + '.yml'

# NSX Manager credentials
cred = credentials(inputs)
nsx = NSX(*cred)

# Input the name of edge
edgename = raw_input("Edge name: ")

print(nsx.findedge(edgename))
Example #3
0
# Specify parameters of the Edge to be created - as argument
p_or_s = 'None'

while p_or_s != 'p' and p_or_s != 's':
    p_or_s = raw_input(
        "Which edge do you want to configure? \n primary - p, secondary - s    p/s[p]: "
    ) or 'p'

if p_or_s == 'p':
    path = 'inputs/pe_primary_' + seldc(sys.argv[1:]) + '.yml'
else:
    path = 'inputs/pe_secondary_' + seldc(sys.argv[1:]) + '.yml'

# Create an instance of Class vSphere
cred = credentials(inputs)
nsx = NSX(*cred)

with open(path, 'r') as f:
    s = f.read()

# Read the directory of credentials from file
pe = yaml.load(s)

# Find the edge
print('\nSearching for edge-id')
try:
    edgeid = nsx.findedge(pe['name'])
except:
    print("Edge doesn't exist")
    sys.exit(1)
Example #4
0
#! /usr/bin/env python
"""
===================================================================================================
   Author:         Petr Nemec
   Description:    Get the edges
   Date:           2017-10-04
===================================================================================================
"""

from nsx import NSX
from nsx import credentials
from nsx import seldc
import sys
from pprint import pprint

# Select the vSphere to be modified
inputs = 'inputs/nsx_' + seldc(sys.argv[1:]) + '.yml'

# NSX Manager credentials
cred = credentials(inputs)
nsx = NSX(*cred)

pprint(nsx.getedges())
Example #5
0
===================================================================================================
   Author:         Petr Nemec
   Description:    Remove NSX edge
   Date:           2017-10-04
===================================================================================================
"""

from nsx import NSX
from nsx import credentials
from nsx import seldc
import sys

# Select the instance of NSX manager to be configured - as argument
inputs = 'inputs/nsx_' + seldc(sys.argv[1:]) + '.yml'

# Input the name of edge
edgename = raw_input("Edge name: ")

# NSX Manager credentials
cred = credentials(inputs)
nsx = NSX(*cred)

# Find edge
print('Searching for edge id')
edgeid = nsx.findedge(edgename)

# Delete edge
print('Deleting edge-' + edgeid)
if edgeid:
    nsx.deledge(edgeid)
# Specify parameters of the Edge to be created - as argument
p_or_s = 'None'

while p_or_s != 'p' and p_or_s != 's':
    p_or_s = raw_input(
        "Which edge do you want to configure? \n primary - p, secondary - s    p/s[p]: "
    ) or 'p'

if p_or_s == 'p':
    path = 'inputs/pe_primary_' + seldc(sys.argv[1:]) + '.yml'
else:
    path = 'inputs/pe_secondary_' + seldc(sys.argv[1:]) + '.yml'

# Create an instance of Class vSphere
cred = credentials(inputs)
nsx = NSX(*cred)

with open(path, 'r') as f:
    s = f.read()

# Read the directory of credentials from file
pe = yaml.load(s)

# Find the edge
print('\nSearching for edge-id')
try:
    edgeid = nsx.findedge(pe['name'])
except:
    print("Edge doesn't exist")
    sys.exit(1)
Example #7
0
#! /usr/bin/env python
"""
===================================================================================================
   Description:    template for quick testing of NSX methods
===================================================================================================
"""

from nsx import NSX
from nsx import credentials

cred = credentials('inputs/nsx_mylab.yml')
nsx = NSX(*cred)

# Continue with calling methods of NSX class etc.
nsx.getedges()
nsx.getswitches()
Example #8
0
#! /usr/bin/env python
"""
===================================================================================================
   Author:         Petr Nemec
   Description:    Get the switches
   Date:           2017-10-04
===================================================================================================
"""

from nsx import NSX
from nsx import credentials
from nsx import seldc
import sys
from pprint import pprint

# Select the vSphere to be modified
inputs = 'inputs/nsx_' + seldc(sys.argv[1:]) + '.yml'

# NSX Manager credentials
cred = credentials(inputs)
nsx = NSX(*cred)

pprint(nsx.getswitches())
Example #9
0
print('  Uplink IP:          %s' % pe['uplink']['address'])
print('  Uplink dvportgroup: dvportgroup-%s' % dvportgroup)
print('  CE interconnect IP: %s' % pe['interconnect']['address'])
print('  CE interconnect sw: virtualwire-%s' % vw)
print('\n')

agree = raw_input("Do you want to apply these changes? y/n[N]: " or 'N')

# Proceed with updating configuration
if agree != "Y" and agree != "y":
    print("Script execution canceled")
    sys.exit(1)
else:
    # Create an instance of Class NSX
    cred = credentials(inputs)
    nsx = NSX(*cred)

    # Define XML Body
    xml_edge = createbody("templates/edge.j2", pe)

    # Create edge
    print('Wait for tasks to be completed')
    print('Deploying the edge VM - {0} ---------'.format(pe['name']))
    nsx.createedge(xml_edge)

    # Configure HA

    if pe['ha']:
        print('Searching for edge-id')
        edgeid = nsx.findedge(pe['name'])
        xml_ha = createbody("templates/ha.j2", pe)
Example #10
0
===================================================================================================
"""

from nsx import NSX
from nsx import credentials
from nsx import seldc
from termcolor import cprint
import sys

# Select the vSphere to be modified
inputs = 'inputs/nsx_' + seldc(sys.argv[1:]) + '.yml'

lswitchname = raw_input("Logical switch name: ")

# NSX Manager credentials
cred = credentials(inputs)
nsx = NSX(*cred)


# Find dvswitch-id and VXLAN VNI
print('\nSearching for logical switch id & Segment ID')
swid = (nsx.findswitch(lswitchname))


if swid[0] and swid[1]:
    cprint('\nThe Logical Switch exists as virtualwire-' + swid[0], 'green')
    cprint('Segment-ID: ' + str(swid[1]), 'green')
else:
    cprint("\nThe switch doesn't exist", 'red')