Пример #1
0
def login():
    error = None
    if request.method == 'POST':
        global nuage_user
        session['userx'] = request.form.get('user')
        session['passwd'] = request.form.get('passwd')
        session['org'] = request.form.get('org')
        ip = 'https://' + request.form.get('ipaddress') + ':8443'
        session['ipaddress'] = ip
        # Configuring a connection to the VSD API
        nc = vsdk.NUVSDSession(username=session['userx'],
                               password=session['passwd'],
                               enterprise=session['org'],
                               api_url=session['ipaddress'])

        # Actively connecting ot the VSD API
        try:
            nc.start()
        except:
            flash('Login Session Failed...Check Credentials')
            return render_template('main.html')
        # Root User
        nuage_user = nc.user
        #return nuage_user
        return render_template('menu.html', error=error)
    return render_template('main.html')
Пример #2
0
def createVsdkSession(vsdUrl, vsdEnterprise, vsdUsername, vsdPassword):
    # Connect to VSD
    session = None
    if 'version' in vsdk.NUVSDSession.__init__.__code__.co_varnames:
        # If older SDK
        session = vsdk.NUVSDSession(username=vsdUsername,
                                    password=vsdPassword,
                                    enterprise=vsdEnterprise,
                                    api_url=vsdUrl,
                                    version=LOGIN_API_VERSION)
    else:
        session = vsdk.NUVSDSession(username=vsdUsername,
                                    password=vsdPassword,
                                    enterprise=vsdEnterprise,
                                    api_url=vsdUrl)
    session.start()
    return session
Пример #3
0
def createVsdkSession():
    #Connect to VSD
    session = None
    if 'version' in vsdk.NUVSDSession.__init__.__code__.co_varnames:
        #If older SDK
        session = vsdk.NUVSDSession(username=LOGIN_USER,
                                    password=LOGIN_PASS,
                                    enterprise=LOGIN_ENTERPRISE,
                                    api_url=LOGIN_API_URL,
                                    version=LOGIN_API_VERSION)
    else:
        session = vsdk.NUVSDSession(username=LOGIN_USER,
                                    password=LOGIN_PASS,
                                    enterprise=LOGIN_ENTERPRISE,
                                    api_url=LOGIN_API_URL)
    session.start()
    return session
Пример #4
0
    def __init__(self, config):
        for k, v in config.items():
            setattr(self, k, v)

        self.session = vsdk.NUVSDSession(username=self.username,
                                         password=self.password,
                                         enterprise=self.enterprise,
                                         api_url=self.api_url)

        logging.info(
            "starting session username: %s, password: %s, enterprise: %s, api_url: %s"
            % (self.username, self.password, self.enterprise, self.api_url))
        self.session.start()
Пример #5
0
def logx():
    # Configuring a connection to the VSD API
    nc = vsdk.NUVSDSession(username=userx,
                           password=passwd,
                           enterprise=org,
                           api_url=ipaddress)
    # Actively connecting ot the VSD API
    try:
        nc.start()
    except:
        flash('Login Session Failed...Check Credentials')
        return render_template('main.html')
    # Root User
    nuage_user = nc.user
    #return nuage_user
    return (nuage_user)
Пример #6
0
    def __init__(self, config):
        for k, v in config.items():
            LOG.info("%s = %s" % (k, v))
            setattr(self, k, v)
        try:
            self.session = vsdk.NUVSDSession(username=self.username,
                                             password=self.password,
                                             enterprise=self.enterprise,
                                             api_url=self.api_url)

            LOG.info(
                "starting session username: %s, password: %s, enterprise: %s, api_url: %s"
                %
                (self.username, self.password, self.enterprise, self.api_url))
            self.session.start()

        except Exception, e:
            LOG.error("creating VSD session failed with error %s" % str(e))
Пример #7
0
__credits__ = ["Rick Kauffman"]
__license__ = "Apache2"
__version__ = "1.0.0"
__maintainer__ = "Rick Kauffman"
__email__ = "*****@*****.**"
__status__ = "Prototype"

test connectivity to the VSD API

'''
from vspk import v3_2 as vsdk
import json
import time
# Configuring a connection to the VSD API
nc = vsdk.NUVSDSession(username='******',
                       password='******',
                       enterprise='csp',
                       api_url="https://10.132.0.126:8443")

# Actively connecting ot the VSD API
try:
    nc.start()
except:
    print(nc)
    print type(nc.start)
    print(dir(nc))

# Root User
nuage_user = nc.user

dom = 'Tower'
fromzone = 'TrumpZone 0'
def main():
    """
    Manage the vCenter Integration Node configuration
    """

    # Handling arguments
    args = get_args()
    debug = args.debug
    folder_name = None
    if args.folder:
        folder_name = args.folder[0]
    log_file = None
    if args.logfile:
        log_file = args.logfile[0]
    name = args.name[0]
    nuage_enterprise = args.nuage_enterprise[0]
    nuage_host = args.nuage_host[0]
    nuage_port = args.nuage_port[0]
    nuage_password = None
    if args.nuage_password:
        nuage_password = args.nuage_password[0]
    nuage_username = args.nuage_username[0]
    nuage_vm_enterprise = None
    if args.nuage_vm_enterprise:
        nuage_vm_enterprise = args.nuage_vm_enterprise[0]
    nuage_vm_domain = None
    if args.nuage_vm_domain:
        nuage_vm_domain = args.nuage_vm_domain[0]
    nuage_vm_zone = None
    if args.nuage_vm_zone:
        nuage_vm_zone = args.nuage_vm_zone[0]
    nuage_vm_subnet = None
    if args.nuage_vm_subnet:
        nuage_vm_subnet = args.nuage_vm_subnet[0]
    nuage_vm_ip = None
    if args.nuage_vm_ip:
        nuage_vm_ip = args.nuage_vm_ip[0]
    nuage_vm_user = None
    if args.nuage_vm_user:
        nuage_vm_user = args.nuage_vm_user[0]
    power_on = not args.nopoweron
    resource_pool_name = None
    if args.resource_pool:
        resource_pool_name = args.resource_pool[0]
    nosslcheck = args.nosslcheck
    template = args.template[0]
    vcenter_host = args.vcenter_host[0]
    vcenter_port = args.vcenter_port[0]
    vcenter_password = None
    if args.vcenter_password:
        vcenter_password = args.vcenter_password[0]
    vcenter_username = args.vcenter_username[0]
    verbose = args.verbose

    # Logging settings
    if debug:
        log_level = logging.DEBUG
    elif verbose:
        log_level = logging.INFO
    else:
        log_level = logging.WARNING

    logging.basicConfig(filename=log_file,
                        format='%(asctime)s %(levelname)s %(message)s',
                        level=log_level)
    logger = logging.getLogger(__name__)

    # Disabling SSL verification if set
    if nosslcheck:
        logger.debug('Disabling SSL certificate verification.')
        requests.packages.urllib3.disable_warnings()
        import ssl
    if hasattr(ssl, '_create_unverified_context'):
        ssl._create_default_https_context = ssl._create_unverified_context

    # Getting user password for Nuage connection
    if nuage_password is None:
        logger.debug(
            'No command line Nuage password received, requesting Nuage password from user'
        )
        nuage_password = getpass.getpass(
            prompt='Enter password for Nuage host %s for user %s: ' %
            (nuage_host, nuage_username))

    # Getting user password for vCenter connection
    if vcenter_password is None:
        logger.debug(
            'No command line vCenter password received, requesting vCenter password from user'
        )
        vcenter_password = getpass.getpass(
            prompt='Enter password for vCenter host %s for user %s: ' %
            (vcenter_host, vcenter_username))

    try:
        vc = None
        nc = None

        # Connecting to Nuage
        try:
            logger.info('Connecting to Nuage server %s:%s with username %s' %
                        (nuage_host, nuage_port, nuage_username))
            nc = vsdk.NUVSDSession(username=nuage_username,
                                   password=nuage_password,
                                   enterprise=nuage_enterprise,
                                   api_url="https://%s:%s" %
                                   (nuage_host, nuage_port))
            nc.start()
        except IOError, e:
            pass

        if not nc or not nc.is_current_session():
            logger.error(
                'Could not connect to Nuage host %s with user %s, enterprise %s and specified password'
                % (nuage_host, nuage_username, nuage_enterprise))
            return 1

        # Connecting to vCenter
        try:
            logger.info('Connecting to vCenter server %s:%s with username %s' %
                        (vcenter_host, vcenter_port, vcenter_username))
            vc = SmartConnect(host=vcenter_host,
                              user=vcenter_username,
                              pwd=vcenter_password,
                              port=int(vcenter_port))
        except IOError, e:
            pass
def main():
    """
    Manage the vCenter Integration Node configuration
    """

    # Handling arguments
    args                = get_args()
    all_clusters        = args.all_clusters
    all_datacenters     = args.all_datacenters
    all_hosts           = args.all_hosts
    clusters            = []
    if args.clusters:
        clusters        = args.clusters
    debug               = args.debug
    datacenters         = []
    if args.datacenters:
        datacenters     = args.datacenters
    hosts               = []
    if args.hosts:
        hosts           = args.hosts
    host_configure_agent= args.host_configure_agent
    hosts_file             = None
    if args.hosts_file:
        hosts_file         = args.hosts_file[0]
    hv_username             = None
    if args.hv_username:
        hv_username         = args.hv_username[0]
    hv_password         = None
    if args.hv_password:
        hv_password     = args.hv_password[0]
    hv_management_network = None
    if args.hv_management_network:
        hv_management_network = args.hv_management_network[0]
    hv_data_network     = None
    if args.hv_data_network:
        hv_data_network = args.hv_data_network[0]
    hv_vm_network       = None
    if args.hv_vm_network:
        hv_vm_network   = args.hv_vm_network[0]
    hv_mc_network       = None
    if args.hv_mc_network:
        hv_mc_network   = args.hv_mc_network[0]
    log_file            = None
    if args.logfile:
        log_file        = args.logfile[0]
    nuage_enterprise    = args.nuage_enterprise[0]
    nuage_host          = args.nuage_host[0]
    nuage_port          = args.nuage_port[0]
    nuage_password      = None
    if args.nuage_password:
        nuage_password  = args.nuage_password[0]
    nuage_username      = args.nuage_username[0]
    nuage_vrs_ovf       = None
    if args.nuage_vrs_ovf:
        nuage_vrs_ovf   = args.nuage_vrs_ovf[0]
    nosslcheck          = args.nosslcheck
    verbose             = args.verbose
    vcenter_host        = args.vcenter_host[0]
    vcenter_name        = vcenter_host
    if args.vcenter_name:
        vcenter_name    = args.vcenter_name[0]
    vcenter_https_port  = args.vcenter_https_port[0]
    vcenter_http_port   = args.vcenter_http_port[0]
    vcenter_password    = None
    if args.vcenter_password:
        vcenter_password = args.vcenter_password[0]
    vcenter_username    = args.vcenter_username[0]

    # Logging settings
    if debug:
        log_level = logging.DEBUG
    elif verbose:
        log_level = logging.INFO
    else:
        log_level = logging.WARNING

    logging.basicConfig(filename=log_file, format='%(asctime)s %(levelname)s %(message)s', level=log_level)
    logger = logging.getLogger(__name__)

    # Input checking
    if not all_datacenters and len(datacenters) < 1:
        logger.critical('Not all datacenters have to be present in the Nuage Deployment tool (--all-datacenters option NOT enabled), but also no datacenters specified (at least one --datacenter)')
        return 1
    if not all_clusters and len(clusters) < 1:
        logger.critical('Not all clusters have to be present in the Nuage Deployment tool (--all-clusters option NOT enabled), but also no clusters specified (at least one --cluster)')
        return 1
    if not all_hosts and len(hosts) < 1 and not hosts_file:
        logger.critical('Not all hosts have to be present in the Nuage Deployment tool (--all-hosts option NOT enabled), but also no hosts specified (at least one --host or specify a file with the host information via --hosts-file)')
        return 1
    if all_datacenters and len(datacenters) > 0:
        logger.warning('You enabled all datacenters and added individual datacenter options, --all-datacenters takes precendence and overwrites the specified datacenters.')
        datacenters = []
    if all_clusters and len(clusters) > 0:
        logger.warning('You enabled all clusters and added individual cluster options, --all-clusters takes precendence and overwrites the specified clusters.')
        clusters = []
    if all_hosts and len(hosts) > 0 and not hosts_file:
        logger.warning('You enabled all hosts and added individual hosts options, --all-hosts takes precendence and overwrites the specified hosts.')
        hosts = []
    elif all_hosts and len(hosts) < 1 and hosts_file:
        logger.warning('You enabled all hosts and provided a hosts file, the hosts file takes precendence over the --all-hosts flag and this flag will be ignored.')
        all_hosts = False
    elif not all_hosts and len(hosts) > 0 and hosts_file:
        logger.warning('You specified host with the --host argument and provided a hosts file, the hosts file takes precendence over the --host paramerters and these will be ignored.')
        hosts = []

    # CSV Handling
    hosts_list = None
    if hosts_file:
        hosts_list = {}
        # CSV fields:
        # VM Name, Resource Pool, Folder, MAC Address, Post Script
        logger.debug('Parsing csv %s' % hosts_file)

        if not os.path.isfile(hosts_file):
            logger.critical('CSV file %s does not exist, exiting' % hosts_file)
            return 1

        with open(hosts_file, 'rb') as hostlist:
            hosts_list_raw = csv.reader(hostlist, delimiter=',', quotechar='"')
            for row in hosts_list_raw:
                logger.debug('Found CSV row: %s' % ','.join(row))
                # Adding IP to the hosts variable so it can also be used in further handling if it's a valid IP
                if ip_address_is_valid(row[0]):
                    hosts_list[row[0]] = row
                    hosts.append(row[0])
                else: 
                    logger.warning('Found an invalid IP %s in the hosts file, skipping line' % row[0])

    # Disabling SSL verification if set
    if nosslcheck:
        logger.debug('Disabling SSL certificate verification.')
        requests.packages.urllib3.disable_warnings()
        import ssl
        if hasattr(ssl, '_create_unverified_context'): 
            ssl._create_default_https_context = ssl._create_unverified_context

    # Getting user password for Nuage connection
    if nuage_password is None:
        logger.debug('No command line Nuage password received, requesting Nuage password from user')
        nuage_password = getpass.getpass(prompt='Enter password for Nuage host %s for user %s: ' % (nuage_host, nuage_username))

    # Getting user password for vCenter connection
    if vcenter_password is None:
        logger.debug('No command line vCenter password received, requesting vCenter password from user')
        vcenter_password = getpass.getpass(prompt='Enter password for vCenter host %s for user %s: ' % (vcenter_host, vcenter_username))

    # Getting user password for hosts
    if hv_password is None:
        logger.debug('No command line Host password received, requesting Host password from user')
        hv_password = getpass.getpass(prompt='Enter password for the hosts inside vCenter %s for user %s: ' % (vcenter_host, hv_username))

    try:
        vc = None
        nc = None

        # Connecting to Nuage 
        try:
            logger.info('Connecting to Nuage server %s:%s with username %s' % (nuage_host, nuage_port, nuage_username))
            nc = vsdk.NUVSDSession(username=nuage_username, password=nuage_password, enterprise=nuage_enterprise, api_url="https://%s:%s" % (nuage_host, nuage_port))
            nc.start()
        except IOError, e:
            pass

        if not nc or not nc.is_current_session():
            logger.error('Could not connect to Nuage host %s with user %s and specified password' % (nuage_host, nuage_username))
            return 1

        # Connecting to vCenter
        try:
            logger.info('Connecting to vCenter server %s:%s with username %s' % (vcenter_host, vcenter_https_port, vcenter_username))
            vc = SmartConnect(host=vcenter_host, user=vcenter_username, pwd=vcenter_password, port=int(vcenter_https_port))
        except IOError, e:
            pass
Пример #10
0
# -*- coding: utf-8 -*-
"""
A simple script that will print out a tree structure for each enterprise the user has access to.

--- Usage ---
python list_enterprises_domains_vms_structure_acls.py

--- Author ---
Philippe Dellaert <*****@*****.**>
"""
from vspk import v3_2 as vsdk

session = vsdk.NUVSDSession(
        username='******',
        password='******',
        enterprise='csp',
        api_url='https://VSD-IP:8443'
)

session.start()

user = session.user

for cur_ent in user.enterprises.get():
    print('VMs inside Enterprise %s' % cur_ent.name)
    for cur_vm in cur_ent.vms.get():
        print('|- %s' % cur_vm.name)

    print('\nDomains inside Enterprise %s' % cur_ent.name)
    for cur_domain in cur_ent.domains.get():
        print('|- Domain: %s' % cur_domain.name)