def cleanup(self): """ Called only if PackStack Setup is successful. Returns modified system environment to default. It performs the following activities: 1. Enable Repositories, during installation default repos are disabled {for offline install} (NOTE: EPEL repo is not changed back to default, it still points to /root/cloud/) 2. Remove rabbitmq entry from /etc/hosts file 3. Disable initial-setup-text service """ count = 3 for line in fileinput.input(ROOT_PATH + "/etc/yum.repos.d/CentOS-Base.repo", inplace=True): if line.startswith("enabled"): if count > 0: count -= 1 print(line.replace("enabled=0", "enabled=1").rstrip("\n")) else: print line, else: print line, fileinput.close() for line in fileinput.input(ROOT_PATH + '/etc/hosts', inplace=True): print(line.replace("127.0.0.1 www.rabbitmq.com", "").rstrip("\n")) fileinput.close() ret = iutil._run_systemctl("disable", "initial-setup-text") if ret: print ("Failed to Disable INITIAL-SETUP-UTILITY\n") return False os.remove(os.path.normcase(ROOT_PATH + "/var/www/html/rabbitmq-signing-key-public.asc")) return True
def cleanup(self): """ Called only if PackStack Setup is successful. Returns modified system environment to default. It performs the following activities: 1. Enable Repositories, during installation default repos are disabled {for offline install} (NOTE: EPEL repo is not changed back to default, it still points to /root/cloud/) 2. Remove rabbitmq entry from /etc/hosts file 3. Disable initial-setup-text service """ count = 3 for line in fileinput.input(ROOT_PATH + "/etc/yum.repos.d/CentOS-Base.repo", inplace=True): if line.startswith("enabled"): if count > 0: count -= 1 print(line.replace("enabled=0", "enabled=1").rstrip("\n")) else: print line, else: print line, fileinput.close() for line in fileinput.input(ROOT_PATH + '/etc/hosts', inplace=True): print(line.replace("127.0.0.1 www.rabbitmq.com", "").rstrip("\n")) fileinput.close() ret = iutil._run_systemctl("disable", "initial-setup-text") if ret: print("Failed to Disable INITIAL-SETUP-UTILITY\n") return False os.remove( os.path.normcase(ROOT_PATH + "/var/www/html/rabbitmq-signing-key-public.asc")) return True
def execute(self, storage, ksdata, instclass, users): """ Post install activities, first copy the answer file from location given in kickstart. Second copy cirrios image and rabbitmq public key (both needed for offline packstack run) """ # Create Answers file from given URL TODO:Copy the answer file to host if self.state == "True" and self.env == "anaconda": os.mkdir(ROOT_PATH + ADDON_DIRECTORY) # if (self.lines is not None) and not (self.lines == "") : # answer_file = os.path.normpath(ROOT_PATH + ADDON_DIRECTORY + "answer-file.txt") # with open(answer_file, "w") as fobj: # fobj.write("%s\n" % self.lines) # Copying repodata, cirrios image & rabbitmq public key to Host system from media tmpdirectory = tempfile.mkdtemp() util.mount(device="/dev/disk/by-label/CentOS\\x207\\x20x86_64", mountpoint=tmpdirectory, fstype="auto") copy_tree(tmpdirectory + "/Packages/RDO", os.path.normcase(ROOT_PATH + ADDON_DIRECTORY)) util.umount(tmpdirectory) shutil.rmtree(tmpdirectory) with open(ROOT_PATH + '/etc/hosts', 'a') as file: file.write('127.0.0.1 www.rabbitmq.com\n') file.close() # Copy Addon itself to /usr/share/anaconda/addons #TODO: Once Packaged remove this step if os.path.exists(ROOT_PATH + "/usr/share/anaconda/addons/org_centos_cloud"): os.mkdir(ROOT_PATH + "/usr/share/anaconda/addons/org_centos_cloud") shutil.copytree("/usr/share/anaconda/addons/org_centos_cloud", os.path.normcase(ROOT_PATH + "/usr/share/anaconda/addons/org_centos_cloud")) # Enabling initial-setup-text service, # TODO: Check if Graphical OR Text Service to Enable #initial-setup-text.service: Adding $HOME=/root ENV Variable & Enabling for line in fileinput.input(ROOT_PATH + '/usr/lib/systemd/system/initial-setup-text.service', inplace=1): if line.startswith('Type'): print 'Environment=HOME=/root' print line, rc = iutil.execInSysroot("ln", ["-s", "usr/lib/systemd/system/initial-setup-text.service", "etc/systemd/system/multi-user.target.wants/initial-setup-text.service"]) if rc: msg = "Initializing initial-setup-text service failed" raise KickstartValueError(msg) # NetworkManager: Disable rc = iutil.execInSysroot("rm", ["-rf", "etc/systemd/system/multi-user.target.wants/NetworkManager.service", "etc/systemd/system/dbus-org.freedesktop.NetworkManager.service", "etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service"]) if rc: msg = "Disabling Network Failed" raise KickstartValueError(msg) elif (self.env == "firstboot") and (self.state == "True"): rc = iutil._run_systemctl("enable", "network") if rc: print ("Network start failed") ret = self.run_packstack() if ret: if (self.cleanup()): raw_input("OpenStack Successfully Setup! Press Any Key To Continue...") else: raw_input( "Warning! OpenStack Successfully Setup But System Cleanup failed. Press Any Key To Continue...") else: pass
def execute(self, storage, ksdata, instclass, users): """ Post install activities, first copy the answer file from location given in kickstart. Second copy cirrios image and rabbitmq public key (both needed for offline packstack run) """ # Create Answers file from given URL TODO:Copy the answer file to host if self.state == "True" and self.env == "anaconda": os.mkdir(ROOT_PATH + ADDON_DIRECTORY) # if (self.lines is not None) and not (self.lines == "") : # answer_file = os.path.normpath(ROOT_PATH + ADDON_DIRECTORY + "answer-file.txt") # with open(answer_file, "w") as fobj: # fobj.write("%s\n" % self.lines) # Copying repodata, cirrios image & rabbitmq public key to Host system from media tmpdirectory = tempfile.mkdtemp() util.mount(device="/dev/disk/by-label/CentOS\\x207\\x20x86_64", mountpoint=tmpdirectory, fstype="auto") copy_tree(tmpdirectory + "/Packages/RDO", os.path.normcase(ROOT_PATH + ADDON_DIRECTORY)) util.umount(tmpdirectory) shutil.rmtree(tmpdirectory) with open(ROOT_PATH + '/etc/hosts', 'a') as file: file.write('127.0.0.1 www.rabbitmq.com\n') file.close() # Copy Addon itself to /usr/share/anaconda/addons #TODO: Once Packaged remove this step if os.path.exists(ROOT_PATH + "/usr/share/anaconda/addons/org_centos_cloud"): os.mkdir(ROOT_PATH + "/usr/share/anaconda/addons/org_centos_cloud") shutil.copytree( "/usr/share/anaconda/addons/org_centos_cloud", os.path.normcase( ROOT_PATH + "/usr/share/anaconda/addons/org_centos_cloud")) # Enabling initial-setup-text service, # TODO: Check if Graphical OR Text Service to Enable #initial-setup-text.service: Adding $HOME=/root ENV Variable & Enabling for line in fileinput.input( ROOT_PATH + '/usr/lib/systemd/system/initial-setup-text.service', inplace=1): if line.startswith('Type'): print 'Environment=HOME=/root' print line, rc = iutil.execInSysroot("ln", [ "-s", "usr/lib/systemd/system/initial-setup-text.service", "etc/systemd/system/multi-user.target.wants/initial-setup-text.service" ]) if rc: msg = "Initializing initial-setup-text service failed" raise KickstartValueError(msg) # NetworkManager: Disable rc = iutil.execInSysroot("rm", [ "-rf", "etc/systemd/system/multi-user.target.wants/NetworkManager.service", "etc/systemd/system/dbus-org.freedesktop.NetworkManager.service", "etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service" ]) if rc: msg = "Disabling Network Failed" raise KickstartValueError(msg) elif (self.env == "firstboot") and (self.state == "True"): rc = iutil._run_systemctl("enable", "network") if rc: print("Network start failed") ret = self.run_packstack() if ret: if (self.cleanup()): raw_input( "OpenStack Successfully Setup! Press Any Key To Continue..." ) else: raw_input( "Warning! OpenStack Successfully Setup But System Cleanup failed. Press Any Key To Continue..." ) else: pass