def configure_cluster(client, cluster_name): param = {'display_name': cluster_name} request = client.__getattr__('Fabric').ListComputeCollections(**param) response, responseAdapter = request.result() if len(response['results']) == 0: logger.error("No such a Compute collection with %s" % cluster_name) return [] elif len(response['results']) > 1: logger.error("More than one Compute collections with %s" % cluster_name) return [] cc = response['results'][0] ComputeCollectionFabricTemplate = client.get_model( 'ComputeCollectionFabricTemplate') ccft = ComputeCollectionFabricTemplate(auto_install_nsx=True, compute_collection_id=cc['external_id']) param = {'ComputeCollectionFabricTemplate': convert_to_dict(ccft)} request = client.__getattr__( 'Fabric').CreateComputeCollectionFabricTemplate(**param) try: request.result() except: logger.error("Could not create compute collection fabric template for %s" % cluster_name) return [] return [cc]
def add_cm(client, cm): """ This function returns added compute manager in NSX :param client: bravado client for NSX :return: returns a tuple, the first item is a list of tuples with item 0 containing the IPset Name as string and item 1 containing the IPset id as string. The second item contains a list of dictionaries containing all ipset details """ param = {'ComputeManager': convert_to_dict(cm)} request = client.__getattr__('Fabric').AddComputeManager(**param) try: response, responseAdpter = request.result() except: logger.error("Could not add compute manager with %s" % cm.display_name) return [] return [response]
def add_t0_logicalrouter(client, logicalrouter): """ This function returns added logical router in NSX :param client: bravado client for NSX :return: returns a list includes added logical router """ param = {'Logicalrouter': convert_to_dict(logicalrouter)} request = client.__getattr__( 'Logical Routing And Services').CreateLogicalRouter(**param) try: response, responseAdpter = request.result() except: logger.error("Could not add create logicalrouter with %s" % logicalrouter['display_name']) return [] return [response]
def add_ippool(client, ippool): """ This function returns deleted ip pool found in NSX :param client: bravado client for NSX :return: returns a tuple, the first item is a list of tuples with IP pool summary. The second item contains a list of dictionaries containing all pool details """ ippool param = {'IpPool': convert_to_dict(ippool)} request = client.__getattr__('Pool Management').CreateIpPool(**param) try: response, responseAdpter = request.result() except: logger.error("Could not create ip pool with id: %s" % ippool.display_name) return ([], []) return [response]
def add_tz(client, tz): """ This function returns alled TZ in NSX :param client: bravado client for NSX :return: returns a tuple, the first item is a list of tuples with item 0 containing the IPset Name as string and item 1 containing the IPset id as string. The second item contains a list of dictionaries containing all ipset details """ param = {'TransportZone': convert_to_dict(tz)} request = client.__getattr__('Network Transport').CreateTransportZone( **param) try: response, responseAdpter = request.result() except: logger.error("Could not add compute manager with %s" % tz.display_name) return [] return [response]
def add_logicalswitch(client, logicalswitch): """ This function returns alled LOGICALSWITCH in NSX :param client: bravado client for NSX :return: returns a tuple, the first item is a list of tuples with item 0 containing the IPset Name as string and item 1 containing the IPset id as string. The second item contains a list of dictionaries containing all ipset details """ param = {'LogicalSwitch': convert_to_dict(logicalswitch)} request = client.__getattr__('Logical Switching').CreateLogicalSwitch( **param) try: response, responseAdpter = request.result() except: logger.error("Could not add create logicalswitch with %s" % logicalswitch.display_name) return [] return [response]
def configure_cluster(client, cluster_name, tz_name, uplink_profile_name, ippool_name, pnic_name): param = {'display_name': cluster_name} request = client.__getattr__('Fabric').ListComputeCollections(**param) response, responseAdapter = request.result() if len(response['results']) == 0: logger.error("No such a Compute collection with %s" % cluster_name) return [] elif len(response['results']) > 1: logger.error("More than one Compute collections with %s" % cluster_name) return [] cc = response['results'][0] tzs = list_tz(client) TransportZoneEndPoint = client.get_model('TransportZoneEndPoint') specificied_tz = None for tz in tzs: if tz['display_name'] == tz_name: specificied_tz = tz break if specificied_tz is None: logger.error("No such a transport zone with %s" % tz_name) return [] tzep = TransportZoneEndPoint(transport_zone_id=specificied_tz['id']) # TODO should get uplink profile here HostSwitchProfileTypeIdEntry = client.get_model( 'HostSwitchProfileTypeIdEntry') uplink_profiles = list_uplink_profile(client) specified_uplink_profile = None for uplink_profile in uplink_profiles: if uplink_profile['display_name'] == uplink_profile_name: specified_uplink_profile = uplink_profile break if specified_uplink_profile is None: logger.error("No such a uplink profile with %s" % uplink_profile_name) return [] host_switch_profile_id = HostSwitchProfileTypeIdEntry( key='UplinkHostSwitchProfile', value=specified_uplink_profile['id']) ippools = list_ippool(client) StaticIpPoolSpec = client.get_model('StaticIpPoolSpec') ip_pool_spec = None for ippool in ippools: if ippool['display_name'] == ippool_name: ip_pool_spec = StaticIpPoolSpec(ip_pool_id=ippool['id'], resource_type=u'StaticIpPoolSpec') break if ip_pool_spec is None: logger.error("No such Ip pool with %s" % ippool_name) return [] pnic_list = [] Pnic = client.get_model('Pnic') for i, pnic in enumerate(pnic_name): pnic_list.append( Pnic(device_name=pnic, uplink_name=specified_uplink_profile['teaming']['active_list'] [i]['uplink_name'])) StandardHostSwitch = client.get_model('StandardHostSwitch') host_switch = StandardHostSwitch( host_switch_name=specificied_tz['host_switch_name'], cpu_config=[], host_switch_profile_ids=[host_switch_profile_id], ip_assignment_spec=ip_pool_spec, pnics=pnic_list) StandardHostSwitchSpec = client.get_model('StandardHostSwitchSpec') shss = StandardHostSwitchSpec(host_switches=[host_switch], resource_type='StandardHostSwitchSpec') ComputeCollectionTransportNodeTemplate = client.get_model( 'ComputeCollectionTransportNodeTemplate') cctnt = ComputeCollectionTransportNodeTemplate( compute_collection_ids=[cc['external_id']], host_switch_spec=shss, resource_type='ComputeCollectionTransportNodeTemplate', transport_zone_endpoints=[tzep]) param = {'ComputeCollectionTransportNodeTemplate': convert_to_dict(cctnt)} request = client.__getattr__( 'Network Transport').CreateComputeCollectionTransportNodeTemplate( **param) try: request.result() except: logger.error( "Could not create compute collection transport template for %s" % cluster_name) return [] return [cc] pass