Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple host ips #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

letsmakesense
Copy link

No description provided.

@letsmakesense
Copy link
Author

Ops, just wanted to update my own repo. But check if you like it

Copy link
Owner

@aszlig aszlig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request. However, since most of the code is lxc-specific, I can't accept this as is, see the corresponding comments.

@@ -1,3 +1,4 @@
*.pyc
/build/
/result
.idea
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep out all editor-specific ignores, so can you please drop this hunk?

@@ -45,16 +48,60 @@ def set(self, ip, new_destination):
"Invalid IP address '%s'. Failover IP addresses are %s"
% (ip, failovers.keys()))
failover = failovers.get(ip)
if new_destination == failover.active_server_ip:
dest_list = new_destination.split(' ')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't stringly-type things, I'd rather prefer the function signature to be something like:

def set(self, ip: str, *destinations: str) -> None:
    ...

@@ -233,35 +233,36 @@ class Failover(SubCommand):
make_option('-s', '--set', dest='setfailover', action='store_true',
default=False,
help="Assign failover IP address to server"),
make_option('-m', '--monitor', dest='monitorfailover',
action='store_true', default=False,
help="Assign failover IP address to server"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate help comment.

Comment on lines +65 to +107

def monitor(self):
"""Check if container with failover IP is running on host
and if IP is not mapped to host change settings
"""
msgs = []
failovers = self.list()
if len(failovers) > 0:
ips = self._get_active_ips()
host_ip = self._get_host_ip()
for failover_ip, failover in failovers.items():
if failover_ip in ips and failover.active_server_ip != host_ip:
new_failover = self.set(failover_ip, host_ip)
if new_failover:
msgs.append("Failover IP successfully assigned to new"
" destination")
msgs.append(str(failover))
return msgs

def _get_active_ips(self):
ips = []
try:
out = subprocess.check_output(["lxc-ls", "--active", "-fF", "IPV4"])
except subprocess.CalledProcessError as e:
raise RobotError(str(e))
except Exception as e:
raise RobotError(str(e))
else:
[ips.extend([ip.strip() for ip in line.strip().split(',')])
for line in out.split('\n')
if re.search(r'\d+\.\d+\.\d+\.\d', line)]
return ips

def _get_host_ip(self):
try:
host_ip = subprocess.check_output(["hostname", "--ip-address"])
except subprocess.CalledProcessError as e:
raise RobotError(str(e))
except Exception as e:
raise RobotError(str(e))
else:
return host_ip.strip()

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, these are lxc-specific methods which clearly have nothing to do with the library. If we really want people to extend the hetznerctl tool, we should instead introduce a plugin system, where people can introduce such changes without becoming a maintenance burden upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants