|
43 | 43 | CONFIG_IF_PREF_PATH = CONFIG_PATH + "InterfacePrefix" |
44 | 44 | HOSTS_PATH = CALICO_V_PATH + "/host/" |
45 | 45 | HOST_PATH = HOSTS_PATH + "%(hostname)s/" |
| 46 | +HOST_CONFIG_PATH = HOST_PATH + "config/" |
| 47 | +HOST_CONFIG_KEY_PATH = HOST_CONFIG_PATH + "%(config_param)s" |
46 | 48 | ORCHESTRATOR_PATH = HOST_PATH + "workload/%(orchestrator_id)s/" |
47 | 49 | WORKLOAD_PATH = ORCHESTRATOR_PATH + "%(workload_id)s/" |
48 | 50 | LOCAL_ENDPOINTS_PATH = WORKLOAD_PATH + "endpoint/" |
@@ -280,14 +282,63 @@ def create_host(self, hostname, ipv4, ipv6, as_num): |
280 | 282 | # This is important for Mesos, where the containerized executor process |
281 | 283 | # needs to exchange messages with the Mesos Slave process running on |
282 | 284 | # the host. |
283 | | - self.etcd_client.write(host_path + |
284 | | - "config/DefaultEndpointToHostAction", "RETURN") |
| 285 | + self.set_per_host_config(hostname, "DefaultEndpointToHostAction", |
| 286 | + "RETURN") |
285 | 287 |
|
286 | | - # Flag to Felix that the host is created. |
287 | | - self.etcd_client.write(host_path + "config/marker", "created") |
| 288 | + # Flag that the host is created. |
| 289 | + self.set_per_host_config(hostname, "marker", "created") |
288 | 290 |
|
289 | 291 | return |
290 | 292 |
|
| 293 | + @handle_errors |
| 294 | + def get_per_host_config(self, hostname, config_param): |
| 295 | + """ |
| 296 | + Get a raw (string) per-host config parameter from etcd. |
| 297 | + :param hostname: The name of the host. |
| 298 | + :param config_param: The name of the config parameter (e.g. |
| 299 | + "LogSeverityFile"). |
| 300 | + :return: string value or None if config wasn't present. |
| 301 | + """ |
| 302 | + config_key = HOST_CONFIG_KEY_PATH % { |
| 303 | + "hostname": hostname, |
| 304 | + "config_param": config_param, |
| 305 | + } |
| 306 | + try: |
| 307 | + return self.etcd_client.read(config_key).value |
| 308 | + except EtcdKeyNotFound: |
| 309 | + return None |
| 310 | + |
| 311 | + @handle_errors |
| 312 | + def set_per_host_config(self, hostname, config_param, value): |
| 313 | + """ |
| 314 | + Write a raw (string) per-host config parameter to etcd. |
| 315 | + :param hostname: The name of the host who's config should be updated. |
| 316 | + :param config_param: The name of the parameter (e.g. |
| 317 | + "LogSeverityFile"). |
| 318 | + :param value: The raw string value to set, or None to delete the key. |
| 319 | + """ |
| 320 | + config_key = HOST_CONFIG_KEY_PATH % { |
| 321 | + "hostname": hostname, |
| 322 | + "config_param": config_param, |
| 323 | + } |
| 324 | + if value is not None: |
| 325 | + self.etcd_client.write(config_key, value) |
| 326 | + else: |
| 327 | + try: |
| 328 | + self.etcd_client.delete(config_key) |
| 329 | + except EtcdKeyNotFound: |
| 330 | + pass |
| 331 | + |
| 332 | + @handle_errors |
| 333 | + def remove_per_host_config(self, hostname, config_param): |
| 334 | + """ |
| 335 | + Remove a per-host config parameter. |
| 336 | + :param hostname: The name of the host who's config should be updated. |
| 337 | + :param config_param: The name of the parameter (e.g. |
| 338 | + "LogSeverityFile"). |
| 339 | + """ |
| 340 | + self.set_per_host_config(hostname, config_param, None) |
| 341 | + |
291 | 342 | @handle_errors |
292 | 343 | def remove_host(self, hostname): |
293 | 344 | """ |
|
0 commit comments