Skip to content

Commit

Permalink
Allow hostname to be configured
Browse files Browse the repository at this point in the history
Fixes #79
  • Loading branch information
tomdee committed Mar 30, 2016
1 parent 6f50912 commit 90f8512
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
15 changes: 10 additions & 5 deletions calico.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def __init__(self, network_config, env):
Type of IPAM to use, e.g calico-ipam.
"""

self.hostname = network_config.get("hostname", socket.gethostname())
"""
The hostname to register endpoints under.
"""

self.policy_driver = get_policy_driver(self.k8s_pod_name,
self.k8s_namespace,
self.network_config)
Expand Down Expand Up @@ -480,7 +485,7 @@ def _create_endpoint(self, ip_list):
_log.debug("Creating Calico endpoint with workload_id=%s",
self.workload_id)
try:
endpoint = self._client.create_endpoint(HOSTNAME,
endpoint = self._client.create_endpoint(self.hostname,
self.orchestrator_id,
self.workload_id,
ip_list)
Expand Down Expand Up @@ -518,7 +523,7 @@ def _remove_workload(self):
"""
try:
_log.info("Removing Calico workload '%s'", self.workload_id)
self._client.remove_workload(hostname=HOSTNAME,
self._client.remove_workload(hostname=self.hostname,
orchestrator_id=self.orchestrator_id,
workload_id=self.workload_id)
except KeyError:
Expand All @@ -529,7 +534,7 @@ def _remove_workload(self):
_log.debug("Could not find workload with workload ID %s.",
self.workload_id)
try:
self._client.remove_workload(hostname=HOSTNAME,
self._client.remove_workload(hostname=self.hostname,
orchestrator_id="cni",
workload_id=self.container_id)
except KeyError:
Expand Down Expand Up @@ -597,7 +602,7 @@ def _get_endpoint(self):
_log.debug("Looking for endpoint that matches workload ID %s",
self.workload_id)
endpoint = self._client.get_endpoint(
hostname=HOSTNAME,
hostname=self.hostname,
orchestrator_id=self.orchestrator_id,
workload_id=self.workload_id
)
Expand All @@ -608,7 +613,7 @@ def _get_endpoint(self):
self.workload_id)
try:
endpoint = self._client.get_endpoint(
hostname=HOSTNAME,
hostname=self.hostname,
orchestrator_id="cni",
workload_id=self.container_id
)
Expand Down
4 changes: 0 additions & 4 deletions calico_cni/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
import re
import socket


# System Specific Constants
HOSTNAME = socket.gethostname()

# Regex to parse CNI_ARGS. Looks for key value pairs separated by an equals
# sign and followed either the end of the string, or a colon (indicating
# that there is another CNI_ARG key/value pair.
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_cni_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def setUp(self):
"etcd_authority": "dummy_value:1234",
"etcd_endpoints": "http://dummy_value:1234",
"type": "calico",
"hostname": "test-host",
"ipam": {
"type": "calico-ipam",
"subnet": "10.22.0.0/16",
Expand Down

0 comments on commit 90f8512

Please sign in to comment.