def __init__(self): optional_args.add_argument('--rule-name', default='Sample Firewall Rule', help='Name of the new firewall rule') optional_args.add_argument( '--use-compute-gateway', action='store_true', default=False, help='Use compute gateway. Default is using ' 'management gateway') optional_args.add_argument('--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.edge_id = None self.rule_id = None self.nfwr = None self.org_id = args.org_id self.sddc_id = args.sddc_id self.rule_name = args.rule_name self.compute_gw = args.use_compute_gateway self.cleanup = args.cleardata self.vmc_client = create_vmc_client(args.refresh_token)
def __init__(self): optional_args.add_argument( '--network-name', default='Sample Logical Network', help='Name of the new logical network') optional_args.add_argument( '--subnet', default='192.168.100.1/24', help='Logical network subnet') optional_args.add_argument( '--dhcp-range', default='192.168.100.2-192.168.100.254', help='DHCP IP range for the logical network') optional_args.add_argument( '--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.network_id = None self.org_id = args.org_id self.sddc_id = args.sddc_id self.network_name = args.network_name self.primary_address, self.prefix_length = args.subnet.split('/') self.dhcp_range = args.dhcp_range self.cleanup = args.cleardata self.vmc_client = create_vmc_client(args.refresh_token)
def __init__(self): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-r', '--refresh-token', required=True, help='VMware Cloud API refresh token') parser.add_argument('-o', '--org-id', required=True, help='Organization identifier.') parser.add_argument('-s', '--sddc-id', required=True, help='Sddc Identifier.') parser.add_argument('--notes', default='Sample public IP', help='Notes of the new public IP') parser.add_argument('-c', '--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.ip_id = None self.org_id = args.org_id self.sddc_id = args.sddc_id self.notes = args.notes self.cleanup = args.cleardata self.vmc_client = create_vmc_client(args.refresh_token)
def __init__(self): optional_args.add_argument('--public-ip', help='Public IP range for the NAT rule') optional_args.add_argument('--rule-description', default='Sample NAT rule', help='Description for the rule') optional_args.add_argument('--internal-ip', default='192.168.200.1/24', help='NAT rule subnet') optional_args.add_argument('--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.network_id = None self.edge_id = None self.rule_id = None self.org_id = args.org_id self.sddc_id = args.sddc_id self.public_ip = args.public_ip self.internal_ip = args.internal_ip self.rule_description = args.rule_description self.internal_ip = args.internal_ip self.cleanup = args.cleardata self.vmc_client = create_vmc_client(args.refresh_token)
def __init__(self, refreshToken=None, verbose=False): self.refreshToken = refreshToken if not self.refreshToken: raise ValueError('You must supply your OAuth Refresh Token') session = requests.Session() self.vmc_client = create_vmc_client(self.refreshToken, session) atexit.register(session.close) self.orgs = [] self.refreshOrgs() if not self.orgs: raise ValueError('You must have at least one Organization' ' associated with the calling user') if verbose: self.listOrgs() self.config = None self.pod_filter = None self.create_pods = None self.delete_existing = None self.firewall_rules = None self.answer_yes = None self.pod_tasks = None self.connected_account = None
def __init__(self): parser = argparse.ArgumentParser() required_args = parser.add_argument_group('required arguments') optional_args = parser.add_argument_group('optional arguments') required_args.add_argument('--refresh_token', required=True, help='Refresh token obtained from CSP') required_args.add_argument('--org_id', required=True, help='Organization identifier.') optional_args.add_argument('--sddc-name', help="Name of the SDDC to be created. " "Default is 'Sample SDDC xx'") optional_args.add_argument('--region', default='US_WEST_2', help='AWS Region') optional_args.add_argument('--interval-sec', default=60, help='Task pulling interval in sec') optional_args.add_argument('--listsddc', action='store_true', help='List SDDCs in the specified Org') optional_args.add_argument('--createsddc', action='store_true', help='Create an SDDC in the specified Org') optional_args.add_argument( '--deletesddc', action='store_true', help='Deletes the SDDC in the specified Org ') optional_args.add_argument('--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.refresh_token = args.refresh_token self.org_id = args.org_id self.region = args.region self.listsddc = args.listsddc self.createsddc = args.createsddc self.deletesddc = args.deletesddc self.cleanup = args.cleardata self.sddc_id = None self.sddc_name = args.sddc_name or 'Sample SDDC {}'.format( randrange(100)) self.interval_sec = int(args.interval_sec) # Login to VMware Cloud on AWS self.vmc_client = create_vmc_client(self.refresh_token)
def __init__(self): optional_args.add_argument( '--use-compute-gateway', action='store_true', default=False, help='Use compute gateway. Default is using ' 'management gateway') optional_args.add_argument( '--vpn-name', default='Sample IPsec VPN', help='Name of the new VPN') optional_args.add_argument( '--public-ip', default='10.10.10.10', help='IP (IPv4) address or FQDN of the Peer') optional_args.add_argument( '--private-ip', default='192.168.10.10', help='Local IP of the IPsec Site') optional_args.add_argument( '--remote-networks', default='192.168.20.10/24', help='Peer subnets for which VPN is configured') optional_args.add_argument( '--local-networks', default='192.168.30.10/24', help='Local subnets for which VPN is configured') optional_args.add_argument( '--key', default='00000000', help='Pre Shared Key for the IPsec Site') optional_args.add_argument( '--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.edge_id = None self.site_id = None self.org_id = args.org_id self.sddc_id = args.sddc_id self.vpn_name = args.vpn_name self.public_ip = args.public_ip self.private_ip = args.private_ip self.remote_networks = args.remote_networks self.local_networks = args.local_networks self.compute_gw = args.use_compute_gateway self.key = args.key self.cleanup = args.cleardata self.vmc_client = create_vmc_client(args.refresh_token)
def __init__(self): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-r', '--refresh-token', required=True, help='VMware Cloud API refresh token') parser.add_argument('-o', '--org-id', required=True, help='Organization identifier.') parser.add_argument('-s', '--sddc-id', required=True, help='Sddc Identifier.') parser.add_argument('--notes', default='Sample public IP ' + str(random.randint(0, 100)), help='Notes of the new public IP') parser.add_argument('--fw-rule-name', default='Sample firewall rule ' + str(random.randint(0, 100)), help='Name of the compute gae') parser.add_argument('--nat-rule-description', default='Sample NAT rule ' + str(random.randint(0, 100)), help='Description for the NAT rule') parser.add_argument('--internal-ip', required=True, help='Private IP of the VM') parser.add_argument('-c', '--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.network_id = None self.edge_id = None self.nat_rule_id = None self.public_ip = None self.nfwr = None self.org_id = args.org_id self.sddc_id = args.sddc_id self.notes = args.notes self.fw_rule_name = args.fw_rule_name self.nat_rule_description = args.nat_rule_description self.internal_ip = args.internal_ip self.cleardata = args.cleardata self.vmc_client = create_vmc_client(args.refresh_token)
def setup(self): # Login to VMware Cloud on AWS session = requests.Session() self.vmc_client = create_vmc_client(self.refresh_token, session) atexit.register(session.close) # Check if the organization exists orgs = self.vmc_client.Orgs.list() if self.org_id not in [org.id for org in orgs]: raise ValueError("Org with ID {} doesn't exist".format(self.org_id))
def __init__(self): optional_args.add_argument('-c', '--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.org_id = args.org_id self.sddc_id = args.sddc_id self.query_wait_time = 100 self.max_wait_time = 900 self.cleanup = args.cleardata self.vmc_client = create_vmc_client(refresh_token=args.refresh_token)
def __init__(self): optional_args.add_argument('--notes', default='Sample public IP', help='Notes of the new public IP') optional_args.add_argument('--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.ip_id = None self.org_id = args.org_id self.sddc_id = args.sddc_id self.notes = args.notes self.cleanup = args.cleardata self.vmc_client = create_vmc_client(args.refresh_token)
def __init__(self): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-r', '--refresh-token', required=True, help='VMware Cloud API refresh token') parser.add_argument('-o', '--org-id', required=True, help='Organization identifier.') parser.add_argument('-s', '--sddc-id', required=True, help='Sddc Identifier.') parser.add_argument('--public-ip', help='Public IP range for the NAT rule') parser.add_argument('--rule-description', default='Sample NAT rule', help='Description for the rule') parser.add_argument('--internal-ip', default='192.168.200.1/24', help='NAT rule subnet') parser.add_argument('-c', '--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.network_id = None self.edge_id = None self.rule_id = None self.org_id = args.org_id self.sddc_id = args.sddc_id self.public_ip = args.public_ip self.internal_ip = args.internal_ip self.rule_description = args.rule_description self.internal_ip = args.internal_ip self.cleanup = args.cleardata self.vmc_client = create_vmc_client(args.refresh_token)
def __init__(self): optional_args.add_argument('-c', '--cleardata', action='store_true', help='Clean up after sample run') optional_args.add_argument('--interval_sec', default=60, help='Task pulling interval in sec') args = parser.parse_args() self.org_id = args.org_id self.sddc_id = args.sddc_id self.interval_sec = int(args.interval_sec) self.cleanup = args.cleardata self.vmc_client = create_vmc_client(refresh_token=args.refresh_token)
def __init__(self): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-r', '--refresh-token', required=True, help='VMware Cloud API refresh token') parser.add_argument('-o', '--org-id', required=True, help='Organization identifier.') parser.add_argument('-s', '--sddc-id', required=True, help='Sddc Identifier.') parser.add_argument('--network-name', default='Sample Logical Network', help='Name of the new logical network') parser.add_argument('--subnet', default='192.168.100.1/24', help='Logical network subnet') parser.add_argument('--dhcp-range', default='192.168.100.2-192.168.100.254', help='DHCP IP range for the logical network') parser.add_argument('-c', '--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.network_id = None self.org_id = args.org_id self.sddc_id = args.sddc_id self.network_name = args.network_name self.primary_address, self.prefix_length = args.subnet.split('/') self.dhcp_range = args.dhcp_range self.cleanup = args.cleardata self.vmc_client = create_vmc_client(args.refresh_token)
def __init__(self): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-r', '--refresh-token', required=True, help='VMware Cloud API refresh token') parser.add_argument('-o', '--org-id', required=True, help='Organization identifier.') parser.add_argument('-s', '--sddc-id', required=True, help='Sddc Identifier.') parser.add_argument('--rule-name', default='Sample Firewall Rule', help='Name of the new firewall rule') parser.add_argument('--use-compute-gateway', action='store_true', default=False, help='Use compute gateway. Default is using ' 'management gateway') parser.add_argument('-c', '--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.edge_id = None self.rule_id = None self.nfwr = None self.org_id = args.org_id self.sddc_id = args.sddc_id self.rule_name = args.rule_name self.compute_gw = args.use_compute_gateway self.cleanup = args.cleardata self.vmc_client = create_vmc_client(args.refresh_token)
def run(self): # Connect to VMware Cloud on AWS vmc_client = create_vmc_client(self.refresh_token) print( '\n# Example: Successfully login to VMware Cloud on AWS instance') # Check if the organization exists orgs = vmc_client.Orgs.list() if self.org_id not in [org.id for org in orgs]: raise ValueError("Org with ID {} doesn't exist".format( self.org_id)) # Check if the SDDC exists try: sddc = vmc_client.orgs.Sddcs.get(self.org_id, self.sddc_id) except NotFound as e: error_response = e.data.convert_to(ErrorResponse) raise ValueError(error_response.error_messages) # Get VC hostname server = parse.urlparse(sddc.resource_config.vc_url).hostname # Connect to vSphere client using the initial cloud admin credentials. # Please use the new credentials to login after you reset the default one. vsphere_client = create_vsphere_client( server, username=sddc.resource_config.cloud_username, password=sddc.resource_config.cloud_password) print("\n# Example: Successfully connect to vCenter at '{}'".format( server)) # List VMs in the vSphere instance vms = vsphere_client.vcenter.VM.list() print('\n# Example: List VMs in the vSphere') for vm_summary in vms: print('VM ID: {}, VM Name: {}'.format(vm_summary.vm, vm_summary.name))
def __init__(self): optional_args.add_argument('-c', '--cleardata', action='store_true', help='Clean up after sample run') optional_args.add_argument('--interval_sec', default=60, help='Task pulling interval in sec') args = parser.parse_args() self.org_id = args.org_id self.sddc_id = args.sddc_id self.interval_sec = int(args.interval_sec) ''' SRM extension key suffix.This must be fewer than 13 characters and can include alphanumeric characters, hyphen, or period, but cannot start or end with a sequence of hyphen, or period characters ''' self.extension_key = 'TestNode' self.cleanup = args.cleardata self.vmc_client = create_vmc_client(refresh_token=args.refresh_token)
def setup(self): # Login to VMware Cloud on AWS session = requests.Session() self.vmc_client = create_vmc_client(self.refresh_token, session) atexit.register(session.close) # Check if the organization exists orgs = self.vmc_client.Orgs.list() if self.org_id not in [org.id for org in orgs]: raise ValueError("Org with ID {} doesn't exist".format(self.org_id)) # Check if the SDDC exists sddcs = self.vmc_client.orgs.Sddcs.list(self.org_id) if self.sddc_id not in [sddc.id for sddc in sddcs]: raise ValueError("SDDC with ID {} doesn't exist in org {}". format(self.sddc_id, self.org_id)) self.sddc = self.vmc_client.orgs.Sddcs.get(self.org_id,self.sddc_id) # Check if the cluster exists if self.cluster_name not in [cluster.cluster_name for cluster in self.sddc.resource_config.clusters]: raise ValueError("Specified Cluster {} doesn't exist in SDDC {}". format(self.cluster_name, self.sddc.name))
def __init__(self): optional_args.add_argument('--notes', default='Sample public IP ' + str(random.randint(0, 100)), help='Notes of the new public IP') optional_args.add_argument('--fw-rule-name', default='Sample firewall rule ' + str(random.randint(0, 100)), help='Name of the compute gae') optional_args.add_argument('--nat-rule-description', default='Sample NAT rule ' + str(random.randint(0, 100)), help='Description for the NAT rule') required_args.add_argument('--internal-ip', required=True, help='Private IP of the VM') optional_args.add_argument('--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.network_id = None self.edge_id = None self.nat_rule_id = None self.public_ip = None self.nfwr = None self.org_id = args.org_id self.sddc_id = args.sddc_id self.notes = args.notes self.fw_rule_name = args.fw_rule_name self.nat_rule_description = args.nat_rule_description self.internal_ip = args.internal_ip self.cleardata = args.cleardata self.vmc_client = create_vmc_client(args.refresh_token)
def setup(self): # Login to VMware Cloud on AWS session = requests.Session() self.vmc_client = create_vmc_client(self.refresh_token, session) atexit.register(session.close)
def __init__(self): args = parser.parse_args() self.org_id = args.org_id self.sddc_id = args.sddc_id self.client = create_vmc_client(refresh_token=args.refresh_token)
def login(refreshtoken): vmc_client = create_vmc_client(refreshtoken, session) return vmc_client
def login(self): """Login to VMware Cloud on AWS.""" self.vmc_client = create_vmc_client(self.refresh_token)
import argparse import requests from vmware.vapi.vmc.client import create_vmc_client parser = argparse.ArgumentParser() parser.add_argument('--refresh_token', required=True, help='VMware Cloud API refresh token') parser.add_argument('--org_id', required=True, help='Organization identifier.') parser.add_argument('--sddc_id', required=True, help='Sddc Identifier.') args = parser.parse_args() refresh_token = args.refresh_token org_id = args.org_id sddc_id = args.sddc_id client = create_vmc_client(refresh_token) site_recovery_activation_task = client.draas.SiteRecovery.get(org_id, sddc_id) print(site_recovery_activation_task)
def __init__(self): parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('-r', '--refresh-token', required=True, help='VMware Cloud API refresh token') parser.add_argument('-o', '--org-id', required=True, help='Organization identifier.') parser.add_argument('-s', '--sddc-id', required=True, help='Sddc Identifier.') parser.add_argument('--use-compute-gateway', action='store_true', default=False, help='Use compute gateway. Default is using ' 'management gateway') parser.add_argument('--vpn-name', default='Sample IPsec VPN', help='Name of the new VPN') parser.add_argument('--public-ip', default='10.10.10.10', help='IP (IPv4) address or FQDN of the Peer') parser.add_argument('--private-ip', default='192.168.10.10', help='Local IP of the IPsec Site') parser.add_argument('--remote-networks', default='192.168.20.10/24', help='Peer subnets for which VPN is configured') parser.add_argument('--local-networks', default='192.168.30.10/24', help='Local subnets for which VPN is configured') parser.add_argument('--key', default='00000000', help='Pre Shared Key for the IPsec Site') parser.add_argument('-c', '--cleardata', action='store_true', help='Clean up after sample run') args = parser.parse_args() self.edge_id = None self.site_id = None self.org_id = args.org_id self.sddc_id = args.sddc_id self.vpn_name = args.vpn_name self.public_ip = args.public_ip self.private_ip = args.private_ip self.remote_networks = args.remote_networks self.local_networks = args.local_networks self.compute_gw = args.use_compute_gateway self.key = args.key self.cleanup = args.cleardata self.vmc_client = create_vmc_client(args.refresh_token)
def get_vmc_client(token): session = requests.Session() vmc_client = create_vmc_client(token, session=session) atexit.register(session.close) return vmc_client
required=True, help='Refresh token obtained from CSP') required_args.add_argument( '--org-id', required=True, help='Organization identifier.') optional_args.add_argument( '--task-status', help='Task status to filter. Possible values are: {} \ Show all tasks if no value is passed'.format(accepted)) args = parser.parse_args() vmc_client = create_vmc_client(args.refresh_token) tasks = [] if args.task_status: status = args.task_status.upper() if status not in accepted: raise ValueError('Status "{}" is invalid, accept values are {}'. format(args.task_status, accepted)) tasks = vmc_client.orgs.Tasks.list( org=args.org_id, filter="(status eq '{}')".format(status)) print('# List all "{}" tasks:\n'.format(status)) else:
def get_vmc_client(token): return create_vmc_client(token)
* SPDX-License-Identifier: MIT * ******************************************************* * * DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN, * EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED * WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, * NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. """ __author__ = 'VMware, Inc.' from vmware.vapi.vmc.client import create_vmc_client from vmware.vapi.bindings.stub import ApiClient, StubFactoryBase client = create_vmc_client('1234') def test_orgs_client(): assert hasattr(client, 'Orgs') def test_locale_client(): assert hasattr(client, 'Locale') def test_account_link_client(): assert hasattr(client.orgs, 'AccountLink') assert hasattr(client.orgs, 'account_link') assert isinstance(client.orgs.account_link, StubFactoryBase)