Open
Conversation
Author
|
Ops, just wanted to update my own repo. But check if you like it |
aszlig
requested changes
Jun 20, 2020
| *.pyc | ||
| /build/ | ||
| /result | ||
| .idea |
Owner
There was a problem hiding this comment.
I'd like to keep out all editor-specific ignores, so can you please drop this hunk?
| % (ip, failovers.keys())) | ||
| failover = failovers.get(ip) | ||
| if new_destination == failover.active_server_ip: | ||
| dest_list = new_destination.split(' ') |
Owner
There was a problem hiding this comment.
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:
...| 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"), |
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() | ||
|
|
Owner
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.