mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Refactor some code in timezone module
This commit is contained in:
parent
be19af02f7
commit
4bbfe36a6e
1 changed files with 8 additions and 8 deletions
|
@ -218,6 +218,12 @@ class Timezone(object):
|
|||
"""
|
||||
self.abort('set(key, value) is not implemented on target platform')
|
||||
|
||||
def _verify_timezone(self):
|
||||
tz = self.value['name']['planned']
|
||||
tzfile = '/usr/share/zoneinfo/%s' % tz
|
||||
if not os.path.isfile(tzfile):
|
||||
self.abort('given timezone "%s" is not available' % tz)
|
||||
|
||||
|
||||
class SystemdTimezone(Timezone):
|
||||
"""This is a Timezone manipulation class systemd-powered Linux.
|
||||
|
@ -241,10 +247,7 @@ class SystemdTimezone(Timezone):
|
|||
self.status = dict()
|
||||
# Validate given timezone
|
||||
if 'name' in self.value:
|
||||
tz = self.value['name']['planned']
|
||||
tzfile = '/usr/share/zoneinfo/%s' % tz
|
||||
if not os.path.isfile(tzfile):
|
||||
self.abort('given timezone "%s" is not available' % tz)
|
||||
self._verify_timezone()
|
||||
|
||||
def _get_status(self, phase):
|
||||
if phase not in self.status:
|
||||
|
@ -298,10 +301,7 @@ class NosystemdTimezone(Timezone):
|
|||
super(NosystemdTimezone, self).__init__(module)
|
||||
# Validate given timezone
|
||||
if 'name' in self.value:
|
||||
tz = self.value['name']['planned']
|
||||
tzfile = '/usr/share/zoneinfo/%s' % tz
|
||||
if not os.path.isfile(tzfile):
|
||||
self.abort('given timezone "%s" is not available' % tz)
|
||||
self._verify_timezone()
|
||||
self.update_timezone = self.module.get_bin_path('cp', required=True)
|
||||
self.update_timezone += ' %s /etc/localtime' % tzfile
|
||||
self.update_hwclock = self.module.get_bin_path('hwclock', required=True)
|
||||
|
|
Loading…
Reference in a new issue