Example #1
0
 def setup(self):
     library = parse_library_files(self.file_layout)
     if self.pw_database:
         pw_database = self.pw_database
     elif not self.has_pw_file:
         import engage.utils.pw_repository as pw_repository
         pw_database = pw_repository.PasswordRepository("")
     else:
         pw_database = None # setup_context() will read the db
     import install_context
     install_context.setup_context(self.file_layout,
                                   False, library, pw_database)
     with open(self.install_script_file, "rb") as f:
         resource_list_json = json.load(f)
     rlist = [r for r in ifilter(lambda res: res["id"]==self.resource_id,
                                 resource_list_json)]
     if len(rlist)==0:
         raise Exception("Resource %s not found" % self.resource_id)
     if len(rlist)>1:
         raise Exception("Multiple instances of resource %s!" %
                         self.resource_id)
     resource = parse_resource_from_json(rlist[0])
     entry = library.get_entry(resource)
     if entry==None:
         raise Exception("Unable to find library entry for %s, of resource type %s %s" % (resource.id, resource.key["name"], resource.key["version"]))
     resource_manager_class = entry.get_manager_class()
     if self.options.dry_run:
         mgr = resource_manager_class(resource, dry_run=True)
     else:
         mgr = resource_manager_class(resource)
     mgr.install_context = install_context
     return (mgr, entry.get_package())
Example #2
0
    def _run_worker(self, multi_node=False):
        import install_plan
        import install_sequencer
        import install_context as ctx
        efl = self.engage_file_layout
        install_script_file = efl.get_install_script_file()
        if not os.path.exists(install_script_file):
            raise CmdLineError(errors[ERR_BAD_SOLN_FILE],
                               msg_args={"filename":install_script_file})
        library_file = efl.get_preprocessed_library_file()
        resource_list = parse_install_soln(install_script_file)
        self.logger.info("Using software library %s." % library_file)
        library = parse_library_files(efl)
        gp = password.generate_pw_file_if_necessary
        self.pw_database = \
            gp(efl, self.deployment_home, resource_list, library,
               installer_supplied_pw_key_list=self.installer_supplied_pw_key_list,
               master_password_file=self.options.master_password_file,
               read_master_pw_from_stdin=self.options.subproc,
               suppress_master_password_file=self.options.suppress_master_password_file,
               generate_random_passwords=self.options.generate_random_passwords,
               dry_run=self.options.dry_run)
        if not self.pw_database:
            # if no password file is being used, created a dummy password
            # object
            self.pw_database = pw_repository.PasswordRepository("")
        ctx.setup_context(efl, self.options.subproc, library, self.pw_database)
        if self.options.dry_run:
            self.logger.info("Dry run complete.")
            return
        ## if self.options.generate_password_file:
        ##     self.logger.info("Password file at %s, password salt file at %s." %
        ##                      (efl.get_password_database_file(),
        ##                       efl.get_password_salt_file()))
        ##     return

        if multi_node:
            install_sequencer.run_multi_node_install(install_plan.create_multi_node_install_plan(resource_list),
                                                     library,
                                                     self.options.force_stop_on_error)
            # TODO: need to consider whether we need to make any calls to the management API
            # for the master node in multi-node. Is there a way to register cross-node dependencies?
        else: # single node or slave
            mgr_pkg_list = [install_sequencer.get_manager_and_package(instance_md, library)
                            for instance_md in install_plan.create_install_plan(resource_list)]
            install_sequencer.run_install(mgr_pkg_list, library, self.options.force_stop_on_error)
            if self.options.mgt_backends:
                import mgt_registration
                mgt_registration.register_with_mgt_backends(self.options.mgt_backends,
                                                            [mgr for (mgr, pkg) in mgr_pkg_list],
                                                            self.deployment_home,
                                                            sudo_password=ctx.get_sudo_password(),
                                                            upgrade=False)