Ejemplo n.º 1
0
#! /usr/bin/env python

from vsphere import Vsphere
from vsphere import credentials
from vsphere import seldc
import sys

# Select the vSphere to be modified
inputs = seldc(sys.argv[1:])

# Specify manually the distributed port group to be created
dportgroup = raw_input("Distributed port group: ")

# Create an instance of Class vSphere
cred = credentials(inputs)
vmw = Vsphere(*cred)

# Check if the port group already exist
vmw.find_dvportgroup(dportgroup)

Ejemplo n.º 2
0
from vsphere import credentials
from vsphere import seldc
from vsphere import dvswitch
import sys
from termcolor import cprint

# Read the credentials for vSphere from YAML file and input dialog
inputs = seldc(sys.argv[1:])

# It returns the name of distributed switch, banner and active uplink in teaming policy
dswitch = dvswitch(inputs)

dportgroup = raw_input("Distributed port group to be deleted: ")

cred = credentials(inputs)
vmw = Vsphere(*cred)

# Check if the port group exist
if not vmw.find_dvportgroup(dportgroup):
    sys.exit()
else:
    print('\n')
    cprint(dswitch['banner'], 'yellow')
    cprint('\nReview the portgroup to be deleted:', 'red')
    print('  ' + dportgroup)
    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":
Ejemplo n.º 3
0
#! /usr/bin/env python

from vsphere import Vsphere
from vsphere import credentials
from vsphere import seldc
import sys

from pprint import pprint

# Select the vSphere to be modified
inputs = seldc(sys.argv[1:])

# Create an instance of Class vSphere
cred = credentials(inputs)
vmw = Vsphere(*cred)

# Retrieve all distributed switches
dsw = vmw.list_dvswitch()

# Retrieve all portgroups
pgdir = vmw.list_portgroups()

# Resolve dvs_id to dvs_name and add it to dictionary
for pg in pgdir:
    pgdir[pg]['dvsname'] = dsw[pgdir[pg]['dvs_id']]['name']

pprint(pgdir)
Ejemplo n.º 4
0
#! /usr/bin/env python

from vsphere import Vsphere
from vsphere import credentials
from vsphere import seldc
import sys
from pprint import pprint

# Select the vSphere instance
inputs = seldc(sys.argv[1:])

# Create an instance of Class vSphere
cred = credentials(inputs)
vmw = Vsphere(*cred)

# List all VMs and display id, uuid, IP, hostname etc..
VMs = vmw.list_vm()
pprint(VMs)
Ejemplo n.º 5
0
inputs = seldc(sys.argv[1:])

# Specify the telnet port
telnetport = raw_input("Telnet port: ")
while not telnetport.isdigit():
    telnetport = raw_input("Telnet port must be a number: ")

vm_name = raw_input("VM name: ")

# Review and accept or decline the proposed changes
cprint('\nReview the serial port to be created:', 'red')
print('  Telnet port: %s ' % telnetport)
print('  VM:          %s ' % vm_name)

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

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

    # Create serial port
    if vmw.find_vm(vm_name):
        vmw.add_telnet(vm_name, telnetport)
    else:
        print('VM {} not found'.format(vm_name))
Ejemplo n.º 6
0
                    The clusters are identified by static 'NSX' string as a part of the name
                    It provides summary of all datastore appliances from all esx hosts
   Date:            2018-05-07
===================================================================================================
"""

from vsphere import Vsphere
from vsphere import credentials
from vsphere import seldc
import sys

# Select the vSphere instance
inputs = seldc(sys.argv[1:])

# Create an instance of Class vSphere
cred = credentials(inputs)
# Or bypass with custom credentials
# cred = ('10.20.30.40', 'administrator', 'mysecretpassword123')
vmw = Vsphere(*cred)

# Get a list of NSX-dedicated cluster; it searches for 'NSX' in the name of a cluster
clusters = vmw.list_clusters()

for cluster in clusters:
    print('\n')
    print(cluster)
    # Get a list of NSX-dedicated cluster; it searches for 'NSX' in the name
    datastores = vmw.find_cluster(cluster)['datastores']
    for i in range(len(datastores)):
        print(vmw.get_datastore_byid(datastores[i]), datastores[i])
Ejemplo n.º 7
0
#! /usr/bin/env python

from vsphere import Vsphere
from vsphere import credentials
from vsphere import seldc
import sys
from pprint import pprint

# Select the vSphere to be modified
inputs = seldc(sys.argv[1:])


# Specify manually the VM to be found
vm = raw_input("Virtual machine: ")


# Create an instance of Class vSphere
cred = credentials(inputs)
vmw = Vsphere(*cred)


# Check if the VM exists
vminfo = vmw.find_vm(vm)
pprint(vminfo)
Ejemplo n.º 8
0
#! /usr/bin/env python

from vsphere import Vsphere
from pyVmomi import vim, vmodl
from vsphere import credentials
from vsphere import seldc
import sys

# Select the vSphere to be modified
inputs = seldc(sys.argv[1:])

# Create an instance of Class vSphere
cred = credentials(inputs)
# Or bypass with custom credentials
# cred = ('10.20.30.40', 'administrator', 'mysecretpassword123')
vmw = Vsphere(*cred)

# Specify the VM Group, the name of the VM to be added to the group and the cluster where the group exists
vm_group = ''
while not vm_group:
    vm_group = raw_input("VM Group name: ")
vm_name = ''
while not vm_name:
    vm_name = raw_input("VM name: ")
cluster_name = ''
while not vm_name:
    cluster_name = raw_input("Cluster name: ")

# Find the VM
vm = vmw.get_vm_object(vm_name)
vmid = str(vm)
Ejemplo n.º 9
0
===================================================================================================
"""

from vsphere import Vsphere
from vsphere import credentials
from vsphere import seldc
import sys

# Select the vSphere instance
inputs = seldc(sys.argv[1:])

# Create an instance of Class vSphere
cred = credentials(inputs)
# Or bypass with custom credentials
# cred = ('10.20.30.40', 'administrator', 'mysecretpassword123')
vmw = Vsphere(*cred)

# Get a list of NSX-dedicated cluster; it searches for 'NSX' in the name
clusters = vmw.list_clusters()

# Retrieve all ESX hosts
hosts = vmw.list_hosts()

# Retrieve all datadstores
datastores = vmw.list_datastores()

# Identify subset of datastores attached to all hosts present in a cluster
for cluster in clusters:
    cluster_shared_storages = {}
    cluster_shared_storages['cluster_name'] = cluster
    cluster_shared_storages['cluster_id'] = clusters[cluster]['domain']