Created
April 16, 2014 21:27
-
-
Save jcourtois/10934872 to your computer and use it in GitHub Desktop.
This file contains 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
class OS: | |
def __init__(self, os_name): | |
if os_name == 'ubuntu': | |
self.__class__ = DebianOS | |
elif os_name in ['rhel', 'centos']: | |
self.__class__ = RHEL | |
else: | |
util.logger.exception( | |
"Operating system not supported at this time") | |
def check_packages(self, package): | |
raise NotImplementedError() | |
def install_package(self, package): | |
raise NotImplementedError() | |
def update_dist(self, dist_upgrade=False): | |
raise NotImplementedError() | |
class DebianOS(OS): | |
def check_packages(self, package): | |
return "dpkg -l | grep {0}".format(package) | |
def update_dist(self, dist_upgrade=False): | |
if dist_upgrade: | |
return 'apt-get update; apt-get dist-upgrade -y' | |
else: | |
return 'apt-get update; apt-get upgrade -y' | |
def install_package(self, package): | |
return 'apt-get install -y {0}'.format(package) | |
class RHEL(OS): | |
def check_packages(self, package): | |
return "rpm -a | grep {0}".format(package) | |
def update_dist(self, dist_upgrade=False): | |
return 'yum update -y' | |
def install_package(self, package): | |
return 'yum install -y {0}'.format(package) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment