commit before remaking caching system
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Mathieu Broillet 2023-06-20 08:48:38 +02:00
parent 957df53cd5
commit 5c67775f34
No known key found for this signature in database
GPG Key ID: 7D4F25BC50A0AA32
2 changed files with 12 additions and 11 deletions

View File

@ -176,18 +176,16 @@ class LXC(LinuxMachine):
Get IPv4 Get IPv4
:return: ipv4 :return: ipv4
""" """
if self.is_running():
if netmask:
return self.get_in_cache('network', 'ipv4_netmask',
default_value=self.retrieve_ipv4(netmask=netmask, use_ssh=use_ssh))
if netmask: else:
ipv4 = self.get_in_cache('network', 'ipv4_netmask') return self.get_in_cache('network', 'ipv4',
if ipv4 is None: default_value=self.retrieve_ipv4(netmask=netmask, use_ssh=use_ssh))
self.set_in_cache('network', 'ipv4_netmask', self.retrieve_ipv4(netmask=netmask, use_ssh=use_ssh))
return self.get_in_cache('network', 'ipv4_netmask')
else: return self.ipv4
ipv4 = self.get_in_cache('network', 'ipv4')
if ipv4 is None:
self.set_in_cache('network', 'ipv4', self.retrieve_ipv4(netmask=netmask, use_ssh=use_ssh))
return self.get_in_cache('network', 'ipv4')
def retrieve_ipv4(self, netmask: bool = False, use_ssh: bool = False): def retrieve_ipv4(self, netmask: bool = False, use_ssh: bool = False):
if self.ipv4 == "dhcp": if self.ipv4 == "dhcp":

View File

@ -327,7 +327,10 @@ class LinuxMachine():
self.run_command(f"sed {'-i' if case_sensitive else ''} 's/{search}/{replace}/g' {path}", self.run_command(f"sed {'-i' if case_sensitive else ''} 's/{search}/{replace}/g' {path}",
return_status_code=True) return_status_code=True)
def get_in_cache(self, category: str, property: str): def get_in_cache(self, category: str, property: str, default_value: any = None):
if default_value is not None and property not in self.cache[category]:
self.set_in_cache(category, property, default_value)
if category in self.cache: if category in self.cache:
if property in self.cache[category]: if property in self.cache[category]:
return self.cache[category][property] return self.cache[category][property]