def __enter__(self): """ Set up the route reflector clusters when entering context. :return: self. """ # Construct the common environment variables passed in when starting # the route reflector. etcd_auth = "-e ETCD_AUTHORITY=%s:2379" % get_ip() # Create the route reflector hosts, grouped by redundancy. for ii in range(self.num_redundancy_groups): cluster_id = str(IPAddress(0xFF000001 + ii)) redundancy_group = [] for jj in range(self.num_in_redundancy_group): rr = DockerHost('RR.%d.%d' % (ii, jj), start_calico=False) ip = "-e IP=%s" % rr.ip rr.execute("docker load --input /code/routereflector.tar") # Check which type of etcd is being run, then invoke the # suggested curl command to add the RR entry to etcd. # # See https://github.com/projectcalico/calico-bird/tree/feature-ipinip/build_routereflector # for details. if os.getenv("ETCD_SCHEME", None) == "https": # Etcd is running with SSL/TLS, pass the key values rr.execute("docker run --privileged --net=host -d " "--name rr %s " "-e ETCD_AUTHORITY=%s:2379 " "-e ETCD_CA_CERT_FILE=%s " "-e ETCD_CERT_FILE=%s " "-e ETCD_KEY_FILE=%s " "-e ETCD_SCHEME=https " "-v %s/certs:%s/certs " "calico/routereflector" % (ip, ETCD_HOSTNAME_SSL, ETCD_CA, ETCD_CERT, ETCD_KEY, CHECKOUT_DIR, CHECKOUT_DIR)) rr.execute( r'curl --cacert %s --cert %s --key %s ' r'-L https://%s:2379/v2/keys/calico/bgp/v1/rr_v4/%s ' r'-XPUT -d value="{' r'\"ip\":\"%s\",' r'\"cluster_id\":\"%s\"' r'}"' % (ETCD_CA, ETCD_CERT, ETCD_KEY, ETCD_HOSTNAME_SSL, rr.ip, rr.ip, cluster_id)) else: rr.execute("docker run --privileged --net=host -d " "--name rr %s %s " "calico/routereflector" % (etcd_auth, ip)) rr.execute( r'curl -L http://%s:2379/v2/keys/calico/bgp/v1/rr_v4/%s ' r'-XPUT -d value="{' r'\"ip\":\"%s\",' r'\"cluster_id\":\"%s\"' r'}"' % (get_ip(), rr.ip, rr.ip, cluster_id)) # Store the redundancy group. redundancy_group.append(rr) self.redundancy_groups.append(redundancy_group) return self
def __enter__(self): """ Set up the route reflector clusters when entering context. :return: self. """ # Create the route reflector hosts, grouped by redundancy. for ii in range(self.num_redundancy_groups): cluster_id = str(IPAddress(0xFF000001 + ii)) redundancy_group = [] for jj in range(self.num_in_redundancy_group): rr = DockerHost('RR.%d.%d' % (ii, jj), start_calico=False) rr.add_resource({ 'apiVersion': 'projectcalico.org/v3', 'kind': 'Node', 'metadata': { 'name': rr.get_hostname(), 'labels': { 'routeReflectorClusterID': cluster_id, }, }, 'spec': { 'bgp': { 'routeReflectorClusterID': cluster_id, }, }, }) rr.start_calico_node() # Store the redundancy group. redundancy_group.append(rr) self.redundancy_groups.append(redundancy_group) # If there is more than one of them, configure full mesh # peering between the route reflectors. if self.num_redundancy_groups * self.num_in_redundancy_group > 1: rr.add_resource({ 'apiVersion': 'projectcalico.org/v3', 'kind': 'BGPPeer', 'metadata': { 'name': 'rr-mesh', }, 'spec': { 'nodeSelector': 'has(routeReflectorClusterID)', 'peerSelector': 'has(routeReflectorClusterID)', }, }) return self
def __enter__(self): """ Set up the route reflector clusters when entering context. :return: self. """ # Construct the common environment variables passed in when starting # the route reflector. etcd_auth = "-e ETCD_AUTHORITY=%s:2379" % get_ip() # Create the route reflector hosts, grouped by redundancy. for ii in range(self.num_redundancy_groups): cluster_id = str(IPAddress(0xFF000001 + ii)) redundancy_group = [] for jj in range(self.num_in_redundancy_group): rr = DockerHost('RR.%d.%d' % (ii, jj), start_calico=False) ip = "-e IP=%s" % rr.ip rr.execute( "docker load --input /code/calico_containers/routereflector.tar" ) rr.execute("docker run --privileged --net=host -d " "--name rr %s %s " "calico/routereflector" % (etcd_auth, ip)) # Invoke the suggested curl command to add the RR entry to # etcd. # # See https://github.com/projectcalico/calico-bird/tree/feature-ipinip/build_routereflector # for details. rr.execute( r'curl -L http://%s:2379/v2/keys/calico/bgp/v1/rr_v4/%s ' r'-XPUT -d value="{' r'\"ip\":\"%s\",' r'\"cluster_id\":\"%s\"' r'}"' % (get_ip(), rr.ip, rr.ip, cluster_id)) # Store the redundancy group. redundancy_group.append(rr) self.redundancy_groups.append(redundancy_group) return self