import json
from collections import OrderedDict
from cloudshell.api.cloudshell_api import CloudShellAPISession

user = "******"
password = "******"
server = "localhost"
domain = "Global"

api = CloudShellAPISession(host=server, username=user, password=password, domain=domain)

# Get all active sandboxes
active_sandboxes = api.GetCurrentReservations().Reservations

if not active_sandboxes:
    print("No currently active sandboxes")
    exit(0)

print("Active sandboxes")
for sandbox in active_sandboxes:
    target_keys = [
        ("id", sandbox.Id),
        ("name", sandbox.Name),
        ("owner", sandbox.Owner),
        ("status", sandbox.Status),
        ("start_time", sandbox.StartTime),
        ("end_time", sandbox.EndTime),
        ("source_blueprint", sandbox.Topologies[0]),
    ]
    curr_dict = OrderedDict(target_keys)
    print(json.dumps(curr_dict, indent=4))
コード例 #2
0
from cloudshell.api.cloudshell_api import CloudShellAPISession
api = CloudShellAPISession('localhost', 'admin', 'admin', 'Global')

for r in api.GetCurrentReservations('admin').Reservations:
    try:
        print r.Id
        api.EndReservation(r.Id)
    except:
        print 'Failed'
コード例 #3
0
def end_named_reservations(session: CloudShellAPISession, reservation_name: str) -> None:
    """ End and delete reservation. """
    reservations = session.GetCurrentReservations(reservationOwner=session.username)
    for reservation in [r for r in reservations.Reservations if r.Name == reservation_name]:
        end_reservation(session, reservation.Id)
コード例 #4
0
from random import random, randint

api = CloudShellAPISession('localhost',
                           domain="Global",
                           username='******',
                           password='******')

ports = [
    'dut9/port1', 'dut10/port1', 'dut1/port1', 'dut2/port1', 'dut7/port1',
    'dut8/port1', 'dut3/port1', 'dut4/port1', 'dut5/port1', 'dut6/port1',
    'dut19/port1', 'dut20/port1', 'dut11/port1', 'dut12/port1', 'dut17/port1',
    'dut18/port1', 'dut13/port1', 'dut14/port1', 'dut15/port1', 'dut16/port1'
]

resid = [
    x.Id for x in api.GetCurrentReservations().Reservations
    if '20 dut' in x.Name
][0]


def connect(a, b):
    print 'Connecting ' + a + ' ' + b
    # time.sleep(randint(1, 3))
    print '\n'.join([
        x.Source + ' ' + x.Target
        for x in api.ConnectRoutesInReservation(resid, [a, b], 'bi').Routes
    ])


def disconnect(a, b):
    print 'Disconnecting ' + a + ' ' + b
from cloudshell.api.cloudshell_api import CloudShellAPISession

# set list of service "Alias"
TARGET_SERVICES = ["IxNetwork Controller"]

# api session details
user = "******"
password = "******"
server = "localhost"
domain = "Global"

api = CloudShellAPISession(host=server,
                           username=user,
                           password=password,
                           domain=domain)
sandboxes = api.GetCurrentReservations()
x = "lol.txt"


def is_resource_list_in_blueprint(api, blueprint_name, target_service_names):
    """
    search current blueprint resources for presence of the Target Resource
    :param CloudShellAPISession api:
    :param str blueprint_name:
    :param [str] target_service_names:
    :return:
    """
    details = api.GetTopologyDetails(blueprint_name)
    bp_services = details.Services
    bp_service_names = [service.Alias for service in bp_services]
    for service_name in target_service_names: