Cloud Virtual Network Endpoints
436166
@RequestMapping(value = "/cloud/virtualnetwork/create", method = POST, consumes = APPLICATION_JSON_VALUE,
            produces = APPLICATION_JSON_VALUE)
    public ResponseEntity<List<ObjectId>> upsertVirtualNetwork(
            @Valid @RequestBody List<CloudVirtualNetwork> request) {
        return ResponseEntity.ok().body(cloudVirtualNetworkService.upsertVirtualNetwork(request));
    }
1362272
def _configure_endpoint(self, endpoint):
        """"""
        if not endpoint.startswith('http'):
            endpoint = 'https://' + endpoint
        if not endpoint.endswith('/'):
            endpoint += '/'
        return endpoint
1008574
def get_conns(cred, providers):
    """"""
    cld_svc_map = {"aws": conn_aws,
                   "azure": conn_az,
                   "gcp": conn_gcp,
                   "alicloud": conn_ali}
    sys.stdout.write("\rEstablishing Connections:  ")
    sys.stdout.flush()
    busy_obj = busy_disp_on()
    conn_fn = [[cld_svc_map[x.rstrip('1234567890')], cred[x], x]
               for x in providers]
    cgroup = Group()
    conn_res = []
    conn_res = cgroup.map(get_conn, conn_fn)
    cgroup.join()
    conn_objs = {}
    for item in conn_res:
        conn_objs.update(item)
    busy_disp_off(dobj=busy_obj)
    sys.stdout.write("\r                                                 \r")
    sys.stdout.write("\033[?25h")  # cursor back on
    sys.stdout.flush()
    return conn_objs
517752
def get_conn(conn_type):
    '''
    
    '''
    vm_ = get_configured_provider()

    kwargs = vm_.copy()  # pylint: disable=E1103

    kwargs['username'] = vm_['username']
    kwargs['auth_endpoint'] = vm_.get('identity_url', None)
    kwargs['region'] = vm_['compute_region']

    conn = getattr(suop, conn_type)

    return conn(**kwargs)
193253
def __get_network(conn, vm_):
    '''
    
    '''
    network = config.get_cloud_config_value(
        'network', vm_, __opts__,
        default='default', search_global=False)
    return conn.ex_get_network(network)
950673
function createVpcNetwork(mCb) {
			let networksOptions = Object.assign({}, options);
			networksOptions.params = {
				name,
				returnGlobalOperation: true
			};
			networks.add(networksOptions, (error, globalOperationResponse) => {
				if (error) return cb(error);
				
				//assign network name to deployment entry
				oneDeployment.options.network = name;
				
				//check if network is ready then update firewall rules
				checkVpcNetwork(globalOperationResponse, mCb);
			});
			
			function checkVpcNetwork(globalOperationResponse, mCb) {
				
				function globalOperations(miniCB) {
					options.soajs.log.debug("Checking network Create Status");
					//Ref https://cloud.google.com/compute/docs/reference/latest/globalOperations/get
					let request = getConnector(options.infra.api);
					delete request.projectId;
					request.operation = globalOperationResponse.name;
					v1Compute().globalOperations.get(request, (error, response) => {
						if (error) {
							return miniCB(error);
						}
						if (!response || response.status !== "DONE") {
							setTimeout(function () {
								globalOperations(miniCB);
							}, (process.env.SOAJS_CLOOSTRO_TEST) ? 1 : 5000);
						} else {
							return miniCB(null, response);
						}
					});
				}
				
				globalOperations(function (err) {
					if (err) {
						return mCb(err);
					} else {
						//Ref: https://cloud.google.com/compute/docs/reference/latest/firewalls/insert
						let firewallRules = getFirewallRules(oneDeployment.options.network);
						
						let request = getConnector(options.infra.api);
						async.eachSeries(firewallRules, (oneRule, vCb) => {
							options.soajs.log.debug("Registering new firewall rule:", oneRule.name);
							request.resource = oneRule;
							v1Compute().firewalls.insert(request, vCb);
						}, mCb);
					}
				});
				
			}
		}
1061840
private CFEndPoint[] commonGetEndPoints(CFEndPoint[] endPointList, CFEndPointCriteria criteria, boolean getBestOnly) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "commonGetEndPoints");
        }
        if (null == endPointList || 0 == endPointList.length || null == criteria) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                Tr.exit(tc, "commonGetEndPoints", null);
            }
            return null;
        }
        String chainName = criteria.getChainName();
        List<CFEndPoint> chosenEndPoints = new LinkedList<CFEndPoint>();
        if (null != chainName) {
            for (int i = 0; i < endPointList.length; i++) {
                if (null == endPointList[i]) {
                    continue;
                }
                if (chainName.equals(endPointList[i].getName())) {
                    chosenEndPoints.add(endPointList[i]);
                    if (getBestOnly) {
                        break;
                    }
                }
            }
        } else {
            // Chain name was not provided in criteria.
            // Take special steps if the vhost is specified in the criteria.
            String vhost = criteria.getVirtualHost();
            if (null != vhost) {
                // If a match is found with an endpoint, then chosenEndPoints should
                // only include
                // a list of endPoints with matching vhost. If no matches are found,
                // then filter
                // out all endPoints that have the unmatching vhost ... leaving all with
                // null vhosts.
                //
                // Special Note:
                // The case of not finding a match should only happen if no vhost was
                // found to match
                // the inbound chain's host and port that lead to the creation of the
                // CFEndPoint. This
                // could result from a customer changing the port number on the server,
                // but not
                // putting the port into an appropriate virtual host. If precise
                // selection of a
                // CFEndPoint is needed, then that extra step is required by the
                // customer.
                List<CFEndPoint> vhostMatchingEndPoints = new ArrayList<CFEndPoint>();
                List<CFEndPoint> vhostNullEndPoints = new ArrayList<CFEndPoint>();
                for (CFEndPoint tempEndPoint : endPointList) {
                    if (tempEndPoint == null) {
                        continue;
                    }
                    List<String> vhostList = tempEndPoint.getVirtualHosts();
                    if (vhostList.isEmpty()) {
                        vhostNullEndPoints.add(tempEndPoint);
                    } else {
                        for (String value : vhostList) {
                            if (vhost.equalsIgnoreCase(value)) {
                                // Found a match. Add it to the matching array list.
                                vhostMatchingEndPoints.add(tempEndPoint);
                                break;
                            }
                        }
                    }
                }
                // Check to see if any matches were found for the vhost.
                if (0 != vhostMatchingEndPoints.size()) {
                    // A match was found. The endPointList should only include these
                    // endPoints.
                    // Update the array to the correct length. Then fill it with the new
                    // contents.
                    endPointList = new CFEndPoint[vhostMatchingEndPoints.size()];
                    vhostMatchingEndPoints.toArray(endPointList);
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "Found matching vhost in " + vhostMatchingEndPoints.size() + " CFEndPoints.");
                    }
                } else {
                    // No match was found. The endPointList should only include endPoints
                    // with no vhost.
                    // Update the array to the correct length. Then fill it with the new
                    // contents.
                    endPointList = new CFEndPoint[vhostNullEndPoints.size()];
                    vhostNullEndPoints.toArray(endPointList);
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "No matching vhost found.  New CFEndPoint list size " + vhostNullEndPoints.size());
                    }
                }
            }

            // Decision may be based on isSSLRequired and isLocal
            boolean sslRequired = criteria.isSSLRequired();
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Criteria specification if SSL is required: " + sslRequired);
            }

            // Decision may be based on a list of required channel factories.
            Class<?>[] requiredFactories = criteria.getOptionalChannelFactories();

            // Iterate the endPoints and compare them to the criteria.
            for (CFEndPoint tempEndPoint : endPointList) {
                if (tempEndPoint == null) {
                    continue;
                }
                // Double check that the channel accessor is not null.
                if (tempEndPoint.getChannelAccessor() == null) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "Skipping over end point with null channel accessor, " + tempEndPoint.getName());
                    }
                    continue;
                }

                // Check for inclusion of the required factories.
                if (requiredFactories != null) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "Found required factories to match");
                    }
                    boolean foundFactory = true;
                    Class<?> ocdFactory = null;
                    List<OutboundChannelDefinition> ocdList = tempEndPoint.getOutboundChannelDefs();
                    // Iterate the list of required factories to ensure each is in the end
                    // point.
                    for (Class<?> requiredFactory : requiredFactories) {
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "RequiredFactory: " + requiredFactory);
                        }
                        // Note that we haven't found a match yet.
                        foundFactory = false;
                        // Iterate the list of outbound channel definitions in search for
                        // the required factory class.
                        for (OutboundChannelDefinition def : ocdList) {
                            ocdFactory = def.getOutboundFactory();
                            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                Tr.debug(tc, "OCD Factory: " + ocdFactory);
                            }
                            // Try to match the required factory class to this outbound
                            // channel definition.
                            if (requiredFactory.isAssignableFrom(ocdFactory) || ocdFactory.isAssignableFrom(requiredFactory)) {
                                // Found a match. This endpoint is good so far.
                                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                                    Tr.debug(tc, "Found a match");
                                }
                                foundFactory = true;
                                break;
                            }
                        }
                        // Verify that the required factory was in the endpoint.
                        if (!foundFactory) {
                            // Did NOT find a match. This endpoint is no good. Break out of
                            // this loop.
                            break;
                        }
                    }
                    if (!foundFactory) {
                        // Did NOT find a match for a required factory. This endpoint is no
                        // good. Move on to next endpoint.
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "Skipping over endpoint with missing required factory.");
                        }
                        continue;
                    }
                }

                // Check that the channel accessor matches the endPoint.
                if (tempEndPoint.getChannelAccessor().equals(criteria.getChannelAccessor())) {
                    // Found matching channel accessor. Check if SSL is required in the
                    // criteria
                    if (sslRequired) {
                        // The criteria requires an SSL enabled endpoint.
                        if (tempEndPoint.isSSLEnabled()) {
                            // Check to see if an endpoint was already found.
                            if (chosenEndPoints.size() == 0) {
                                // No endpoint found yet. Found a matching endpoint.
                                chosenEndPoints.add(tempEndPoint);
                                // Searching can stop if the endpoint is local
                                if (tempEndPoint.isLocal()) {
                                    // The matching endpoint is local and getBestOnly. Stop
                                    // search.
                                    if (getBestOnly) {
                                        break;
                                    }
                                }
                            } else {
                                if (getBestOnly) {
                                    // Endpoint was already found. We are searching for a better
                                    // local one.
                                    if (tempEndPoint.isLocal()) {
                                        // This endpoint is local and the former endPoint wasn't and
                                        // getBestOnly. Stop search.
                                        chosenEndPoints.add(tempEndPoint);
                                        break;
                                    }
                                } else {
                                    chosenEndPoints.add(tempEndPoint);
                                }
                            }
                        }
                    } else {
                        // The criteria requires a non SSL enabled endpoint.
                        if (!tempEndPoint.isSSLEnabled()) {
                            // Found a matching non SSL enabled endpoint.
                            chosenEndPoints.add(tempEndPoint);
                            // Still need to get a local one if available.
                            if (tempEndPoint.isLocal()) {
                                // Found a matching local endpoint. Stop search.
                                if (getBestOnly) {
                                    break;
                                }
                            }
                        }
                    } // end check sslRequired
                } // end check channelAccessor
            } // end loop through end points
        } // end check chainName

        // convert the list to array or null if no match is found.
        int rtnSize = chosenEndPoints.size();
        CFEndPoint rtnEPs[] = null;
        if (rtnSize > 0) {
            rtnEPs = new CFEndPoint[rtnSize];
            chosenEndPoints.toArray(rtnEPs);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "commonGetEndPoints " + rtnSize);
        }
        return rtnEPs;
    }
237392
def connect_to_services(region=None):
    """"""
    global cloudservers, cloudfiles, cloud_loadbalancers, cloud_databases
    global cloud_blockstorage, cloud_dns, cloud_networks, cloud_monitoring
    global autoscale, images, queues, cloud_cdn
    cloudservers = connect_to_cloudservers(region=region)
    cloudfiles = connect_to_cloudfiles(region=region)
    cloud_cdn = connect_to_cloud_cdn(region=region)
    cloud_loadbalancers = connect_to_cloud_loadbalancers(region=region)
    cloud_databases = connect_to_cloud_databases(region=region)
    cloud_blockstorage = connect_to_cloud_blockstorage(region=region)
    cloud_dns = connect_to_cloud_dns(region=region)
    cloud_networks = connect_to_cloud_networks(region=region)
    cloud_monitoring = connect_to_cloud_monitoring(region=region)
    autoscale = connect_to_autoscale(region=region)
    images = connect_to_images(region=region)
    queues = connect_to_queues(region=region)
68335
def setup_endpoints(provider):
    """"""
    app_routing = {}
    endpoints = [
        AuthorizationEndpoint(
            pyoidcMiddleware(provider.authorization_endpoint)),
        TokenEndpoint(
            pyoidcMiddleware(provider.token_endpoint)),
        UserinfoEndpoint(
            pyoidcMiddleware(provider.userinfo_endpoint)),
        RegistrationEndpoint(
            pyoidcMiddleware(provider.registration_endpoint)),
        EndSessionEndpoint(
            pyoidcMiddleware(provider.endsession_endpoint))
    ]

    for ep in endpoints:
        app_routing["/{}".format(ep.etype)] = ep

    return app_routing
682811
def __get_subnetwork(vm_):
    '''
    
    '''
    ex_subnetwork = config.get_cloud_config_value(
        'subnetwork', vm_, __opts__,
        search_global=False)

    return ex_subnetwork
215673
def _network_event_lifecycle_cb(conn, net, event, detail, opaque):
    '''
    
    '''

    _salt_send_event(opaque, conn, {
        'network': {
            'name': net.name(),
            'uuid': net.UUIDString()
        },
        'event': _get_libvirt_enum_string('VIR_NETWORK_EVENT_', event),
        'detail': 'unknown'  # currently unused
    })
227445
def list_virtual_networks(kwargs=None, conn=None, call=None):
    '''
    
    '''
    if call != 'function':
        raise SaltCloudSystemExit(
            'The list_virtual_networks function must be called with -f or --function.'
        )

    path = 'services/networking/virtualnetwork'
    data = query(path)
    return data
515426
def _find_usage_network_interfaces(self):
        """"""
        enis = paginate_dict(
            self.conn.describe_network_interfaces,
            alc_marker_path=['NextToken'],
            alc_data_path=['NetworkInterfaces'],
            alc_marker_param='NextToken'
        )

        self.limits['Network interfaces per Region']._add_current_usage(
            len(enis['NetworkInterfaces']),
            aws_type='AWS::EC2::NetworkInterface'
        )
554878
def list_networks(kwargs=None, call=None):
    '''
    
    '''
    if call != 'function':
        raise SaltCloudSystemExit(
            'The list_networks function must be called with '
            '-f or --function.'
        )

    return {'Networks': salt.utils.vmware.list_networks(_get_si())}
464616
def list_nodes(call=None):
    '''
    

    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The list_nodes function must be called '
            'with -f or --function.'
        )

    providers = __opts__.get('providers', {})

    ret = {}
    providers_to_check = [_f for _f in [cfg.get('libvirt') for cfg in six.itervalues(providers)] if _f]
    for provider in providers_to_check:
        conn = __get_conn(provider['url'])
        domains = conn.listAllDomains()
        for domain in domains:
            data = {
                'id': domain.UUIDString(),
                'image': '',
                'size': '',
                'state': VIRT_STATE_NAME_MAP[domain.state()[0]],
                'private_ips': [],
                'public_ips': get_domain_ips(domain, libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE)}
            # TODO: Annoyingly name is not guaranteed to be unique, but the id will not work in other places
            ret[domain.name()] = data

    return ret
1344325
def cli(env, sortby):
    """"""

    mgr = SoftLayer.NetworkManager(env.client)
    datacenters = mgr.summary_by_datacenter()

    table = formatting.Table(COLUMNS)
    table.sortby = sortby

    for name, datacenter in datacenters.items():
        table.add_row([
            name,
            datacenter['hardware_count'],
            datacenter['virtual_guest_count'],
            datacenter['vlan_count'],
            datacenter['subnet_count'],
            datacenter['public_ip_count'],
        ])

    env.fout(table)
183444
def detect_cloud() -> str:
    '''
    
    '''
    # NOTE: Contributions are welcome!
    # Please add other cloud providers such as Rackspace, IBM BlueMix, etc.
    if sys.platform.startswith('linux'):
        # Google Cloud Platform or Amazon AWS (hvm)
        try:
            # AWS Nitro-based instances
            mb = Path('/sys/devices/virtual/dmi/id/board_vendor').read_text().lower()
            if 'amazon' in mb:
                return 'amazon'
        except IOError:
            pass
        try:
            bios = Path('/sys/devices/virtual/dmi/id/bios_version').read_text().lower()
            if 'google' in bios:
                return 'google'
            if 'amazon' in bios:
                return 'amazon'
        except IOError:
            pass
        # Microsoft Azure
        # https://gallery.technet.microsoft.com/scriptcenter/Detect-Windows-Azure-aed06d51
        # TODO: this only works with Debian/Ubuntu instances.
        # TODO: this does not work inside containers.
        try:
            dhcp = Path('/var/lib/dhcp/dhclient.eth0.leases').read_text()
            if 'unknown-245' in dhcp:
                return 'azure'
            # alternative method is to read /var/lib/waagent/GoalState.1.xml
            # but it requires sudo privilege.
        except IOError:
            pass
    else:
        log.warning('Cloud detection is implemented for Linux only yet.')
    return None