Beispiel #1
0
def _unmount(conf, mount_point):
    command = [conf.get_script_location("unmount"), mount_point]
    (stdout, stderr, rc) = plugin_utils.run_command(conf, command)
    if rc != 0:
        _g_logger.info("The unmount of %s did not succeed: %s" % (mount_point, stderr))
        raise exceptions.AgentExecutableException(command, rc, stdout, stderr)
    return rc
Beispiel #2
0
    def configure_raid(self, device_id):
        _g_logger.info("Configuring RAID on " + str(device_id))
        if self.args.formatVolume:
            exe = self.conf.get_script_location("configureRaid")
        else:
            exe = self.conf.get_script_location("assembleRaid")

        if self.args.raidLevel.upper() == "NONE":
            raise plugin_exceptions.AgentPluginParameterBadValueException(
                "mount_volume", "raidLevel",
                "When using multiple volumes you must specify a RAID level")

        try:
            raid_level = str(int(self.args.raidLevel[4:]))
        except:
            raise plugin_exceptions.AgentPluginParameterBadValueException(
                "mount_volume", "raidLevel", "Invalid RAID level")

        cmd = [exe, raid_level, device_id]

        for d in self.args.devices:
            cmd.append(d)

        _g_logger.debug("Running the raid configuration command %s" % str(cmd))
        (stdout, stderr, rc) = plugin_utils.run_command(self.conf, cmd)
        _g_logger.debug("configure raid results: %d stdout=%s stderr=%s" %
                        (rc, str(stdout), str(stderr)))

        if rc != 0:
            _g_logger.error(
                "Failed to run raid configuration: stdout=%s\nstderr=%s" %
                (str(stdout), str(stderr)))
            raise exceptions.AgentExecutableException(cmd, rc, stdout, stderr)
Beispiel #3
0
    def configure_raid(self, device_id):
        _g_logger.info("Configuring RAID on " + str(device_id))
        if self.args.formatVolume:
            exe = self.conf.get_script_location("configureRaid")
        else:
            exe = self.conf.get_script_location("assembleRaid")

        if self.args.raidLevel.upper() == "NONE":
            raise plugin_exceptions.AgentPluginParameterBadValueException(
                "mount_volume", "raidLevel", "When using multiple volumes you must specify a RAID level"
            )

        try:
            raid_level = str(int(self.args.raidLevel[4:]))
        except:
            raise plugin_exceptions.AgentPluginParameterBadValueException(
                "mount_volume", "raidLevel", "Invalid RAID level"
            )

        cmd = [exe, raid_level, device_id]

        for d in self.args.devices:
            cmd.append(d)

        _g_logger.debug("Running the raid configuration command %s" % str(cmd))
        (stdout, stderr, rc) = plugin_utils.run_command(self.conf, cmd)
        _g_logger.debug("configure raid results: %d stdout=%s stderr=%s" % (rc, str(stdout), str(stderr)))

        if rc != 0:
            _g_logger.error("Failed to run raid configuration: stdout=%s\nstderr=%s" % (str(stdout), str(stderr)))
            raise exceptions.AgentExecutableException(cmd, rc, stdout, stderr)
Beispiel #4
0
def _close_encrypted_device(conf, encrypted_device_id):
    command = [conf.get_script_location("closeEncryption"),
               encrypted_device_id]
    (stdout, stderr, rc) = plugin_utils.run_command(conf, command)
    if rc != 0:
        _g_logger.info("The close of encrypted %s did not succeed: %s" % (encrypted_device_id, stderr))
        raise exceptions.AgentExecutableException(command, rc, stdout, stderr)
    return rc
Beispiel #5
0
 def run(self):
     command = [self.conf.get_script_location("removeUser"),
                self.args.userId]
     (stdout, stderr, rc) = plugin_utils.run_command(self.conf, command, with_sudo=True)
     if rc != 0:
         raise exceptions.AgentExecutableException(
                 command, rc, stdout, stderr)
     return plugin_base.PluginReply(rc, message="job removeUser succeeded.")
Beispiel #6
0
def _unmount(conf, mount_point):
    command = [conf.get_script_location("unmount"), mount_point]
    (stdout, stderr, rc) = plugin_utils.run_command(conf, command)
    if rc != 0:
        _g_logger.info("The unmount of %s did not succeed: %s" %
                       (mount_point, stderr))
        raise exceptions.AgentExecutableException(command, rc, stdout, stderr)
    return rc
Beispiel #7
0
 def _install_deps(self, dep_dict):
     if self.conf.platform_name in dep_dict:
         _g_logger.debug("Installing packaging deps")
         pkg_installer_cmd = dep_dict[self.conf.platform_name]
         if pkg_installer_cmd:
             cmd_path = self.conf.get_script_location(pkg_installer_cmd[0])
             pkg_installer_cmd[0] = cmd_path
             (stdout, stderr, rc) = plugin_utils.run_command(self.conf, pkg_installer_cmd)
             _g_logger.debug("Results of install: stdout: %s, stderr: " "%s, rc %d" % (str(stdout), str(stderr), rc))
Beispiel #8
0
def _close_encrypted_device(conf, encrypted_device_id):
    command = [
        conf.get_script_location("closeEncryption"), encrypted_device_id
    ]
    (stdout, stderr, rc) = plugin_utils.run_command(conf, command)
    if rc != 0:
        _g_logger.info("The close of encrypted %s did not succeed: %s" %
                       (encrypted_device_id, stderr))
        raise exceptions.AgentExecutableException(command, rc, stdout, stderr)
    return rc
Beispiel #9
0
 def setup_encryption(self, device_id, encrypted_device_id, key_file_path):
     command = [
         self.conf.get_script_location("setupEncryption"), device_id,
         encrypted_device_id, key_file_path
     ]
     (stdout, stderr, rc) = plugin_utils.run_command(self.conf, command)
     if rc != 0:
         raise exceptions.AgentExecutableException(command, rc, stdout,
                                                   stderr)
     return rc
Beispiel #10
0
    def configure_server_with_puppet(self):

        if self.args.endpoint is None:
            raise exceptions.AgentOptionValueNotSetException("endpoint")

        # XXX it will only work with the default port.  There is no way for
        # the user to configure anything else in the console
        endpoint = urllib.parse.urlparse(self.args.endpoint).hostname

        puppet_extras_base_path = os.path.join(self.conf.extra_base_path,
                                               "puppetconf")
        puppet_extras_bin = os.path.join(self.conf.extra_base_path,
                                         "bin/puppet")

        try:
            utils.install_extras(self.conf,
                                 package=self.conf.extra_package_name)
        except exceptions.AgentExtrasNotInstalledException as ex:
            _g_logger.exception("An error occurred trying to install puppet.  "
                                "Exception message is %s" % str(ex))
            raise

        template_puppet_conf_path = os.path.join(puppet_extras_base_path,
                                                 "puppet.conf.template")
        if not os.path.exists(template_puppet_conf_path):
            raise exceptions.AgentExtrasNotInstalledException(
                "The puppet.conf template did not install properly.")
        if not os.path.exists(puppet_extras_bin):
            raise exceptions.AgentExtrasNotInstalledException(
                "The puppet binary did not install properly.")

        puppet_conf_path = self.conf.get_temp_file("puppet.conf")
        self._edit_puppet_conf(template_puppet_conf_path, puppet_conf_path,
                               endpoint)
        cert_file_path = self.conf.get_temp_file("cert.pem")
        key_file_path = self.conf.get_temp_file("key.pem")

        try:
            with open(cert_file_path, "w") as fptr:
                fptr.write(self.args.configCert)
            with open(key_file_path, "w") as fptr:
                fptr.write(self.args.configKey)

            exe = self.conf.get_script_location(
                "runConfigurationManagement-PUPPET")
            cmd = [
                exe, endpoint, cert_file_path, key_file_path,
                self.args.configClientName, self.conf.extra_base_path,
                puppet_conf_path
            ]
            return plugin_utils.run_command(self.conf, cmd)
        finally:
            plugin_utils.safe_delete(cert_file_path)
            plugin_utils.safe_delete(key_file_path)
            plugin_utils.safe_delete(puppet_conf_path)
Beispiel #11
0
    def run(self):
        command_list = [self.exe_path]
        command_list.extend(self.ordered_param_list)
        _g_logger.debug("Plugin running the command %s" % str(command_list))

        _g_logger.debug("Running the remote %s" % self.exe_path)
        (stdout, stderr, rc) = plugin_api.run_command(
            self.conf, command_list, cwd=self.cwd)
        _g_logger.debug("Command %s: stdout %s.  stderr: %s" %
                        (str(command_list), stdout, stderr))
        return PluginReply(rc, message=stdout, error_message=stderr)
Beispiel #12
0
 def _install_deps(self, dep_dict):
     if self.conf.platform_name in dep_dict:
         _g_logger.debug("Installing packaging deps")
         pkg_installer_cmd = \
             dep_dict[self.conf.platform_name]
         if pkg_installer_cmd:
             cmd_path = self.conf.get_script_location(pkg_installer_cmd[0])
             pkg_installer_cmd[0] = cmd_path
             (stdout, stderr,
              rc) = plugin_utils.run_command(self.conf, pkg_installer_cmd)
             _g_logger.debug("Results of install: stdout: %s, stderr: "
                             "%s, rc %d" % (str(stdout), str(stderr), rc))
Beispiel #13
0
    def run(self):
        command_list = [self.exe_path]
        command_list.extend(self.ordered_param_list)
        _g_logger.debug("Plugin running the command %s" % str(command_list))

        _g_logger.debug("Running the remote %s" % self.exe_path)
        (stdout, stderr, rc) = plugin_api.run_command(self.conf,
                                                      command_list,
                                                      cwd=self.cwd)
        _g_logger.debug("Command %s: stdout %s.  stderr: %s" %
                        (str(command_list), stdout, stderr))
        return PluginReply(rc, message=stdout, error_message=stderr)
Beispiel #14
0
    def run(self):
        response = urllib.request.urlopen(self.args.url)
        data = response.read()

        script_file = self.conf.get_temp_file("upgradescript")
        opts_file = self.conf.get_temp_file("upgradeopts")
        try:
            with open(script_file, "wb") as f:
                f.write(data)
            os.chmod(script_file, 0o755)

            # write the configuration to a file.  We may not be safe assuming
            # that the default configuration location is correct
            opts_list = config.build_options_list()
            opts_dict = {}
            for opt in opts_list:
                if opt.section not in opts_dict:
                    opts_dict[opt.section] = {}
                opts_dict[opt.section][opt.name] = getattr(
                    self.conf, opt.get_option_name())

            with open(opts_file, "w") as f:
                for section_name in opts_dict:
                    f.write("[" + section_name + "]" + os.linesep)
                    section = opts_dict[section_name]
                    for key in section:
                        f.write("%s=%s" % (key, section[key]))
                        f.write(os.linesep)

            command_list = [
                script_file, self.args.newVersion, dcm.agent.g_version,
                opts_file
            ]
            command_list.extend(self.args.args)
            _g_logger.debug("Plugin running the command %s" %
                            str(command_list))
            (stdout, stderr,
             rc) = plugin_utils.run_command(self.conf, command_list)
            _g_logger.debug("Command %s: stdout %s.  stderr: %s" %
                            (str(command_list), stdout, stderr))
            return plugin_base.PluginReply(rc,
                                           message=stdout,
                                           error_message=stderr,
                                           reply_type="void")
        finally:
            if os.path.exists(script_file):
                plugin_utils.secure_delete(self.conf, script_file)
            if os.path.exists(opts_file):
                plugin_utils.secure_delete(self.conf, opts_file)
Beispiel #15
0
    def run(self):
        _scheme_map = {'http': self._do_http_download,
                       'https': self._do_http_download,
                       'file': self._do_file}

        url_parts = urllib.parse.urlparse(self.args.url)

        if url_parts.scheme not in list(_scheme_map.keys()):
            # for now we are only accepting http.  in the future we will
            # switch on scheme to decide what cloud storage protocol module
            # to use
            raise plugin_exceptions.AgentPluginParameterBadValueException(
                "url", url_parts.scheme,
                expected_values=str(list(_scheme_map.keys())))

        func = _scheme_map[url_parts.scheme]
        try:
            exe_file, cleanup = func()
        except BaseException as ex:
            if type(ex) == plugin_exceptions.AgentPluginOperationException:
                raise
            return plugin_base.PluginReply(
                1, error_message="Failed to download the URL %s: %s"
                                 % (self.args.url, str(ex)))

        try:
            os.chmod(exe_file, 0o755)

            command_list = []
            if self.args.runUnderSudo:
                command_list.append(self.conf.system_sudo)
            if self.args.inpython:
                command_list.append(sys.executable)
            command_list.append(exe_file)

            if self.args.arguments:
                command_list.extend(self.args.arguments)
            _g_logger.debug("FetchRunScript is running the command %s"
                            % str(command_list))
            (stdout, stderr, rc) = plugin_utils.run_command(
                self.conf, command_list)
            _g_logger.debug("Command %s: stdout %s.  stderr: %s" %
                            (str(command_list), stdout, stderr))
            return plugin_base.PluginReply(
                rc, message=stdout, error_message=stderr, reply_type="void")
        finally:
            if exe_file and cleanup and os.path.exists(exe_file):
                os.remove(exe_file)
Beispiel #16
0
    def run(self):
        response = urllib.request.urlopen(self.args.url)
        data = response.read()

        script_file = self.conf.get_temp_file("upgradescript")
        opts_file = self.conf.get_temp_file("upgradeopts")
        try:
            with open(script_file, "wb") as f:
                f.write(data)
            os.chmod(script_file, 0o755)

            # write the configuration to a file.  We may not be safe assuming
            # that the default configuration location is correct
            opts_list = config.build_options_list()
            opts_dict = {}
            for opt in opts_list:
                if opt.section not in opts_dict:
                    opts_dict[opt.section] = {}
                opts_dict[opt.section][opt.name] = getattr(
                    self.conf, opt.get_option_name())

            with open(opts_file, "w") as f:
                for section_name in opts_dict:
                    f.write("[" + section_name + "]" + os.linesep)
                    section = opts_dict[section_name]
                    for key in section:
                        f.write("%s=%s" % (key, section[key]))
                        f.write(os.linesep)

            command_list = [script_file,
                            self.args.newVersion,
                            dcm.agent.g_version,
                            opts_file]
            command_list.extend(self.args.args)
            _g_logger.debug("Plugin running the command %s"
                            % str(command_list))
            (stdout, stderr, rc) = plugin_utils.run_command(
                self.conf, command_list)
            _g_logger.debug("Command %s: stdout %s.  stderr: %s" %
                            (str(command_list), stdout, stderr))
            return plugin_base.PluginReply(
                rc, message=stdout, error_message=stderr, reply_type="void")
        finally:
            if os.path.exists(script_file):
                plugin_utils.secure_delete(self.conf, script_file)
            if os.path.exists(opts_file):
                plugin_utils.secure_delete(self.conf, opts_file)
Beispiel #17
0
    def configure_server_with_chef(self):
        chef_dir = self.conf.get_temp_file("chefconf", isdir=True)
        run_list_file_name = os.path.join(chef_dir, "runList.cfg")
        token_file_path = self.conf.get_temp_file("token.pem")

        try:
            if self.args.encryptedAuthSecret:
                token = self.args.encryptedAuthSecret
            else:
                token = "NULL"

            authId = self.args.authId
            if authId is None:
                authId = "NULL"

            endpoint = self.args.endpoint
            if endpoint is None:
                endpoint = "NULL"
            environmentId = self.args.environmentId
            if environmentId is None:
                environmentId = "NULL"
            chef_json = {"run_list": self.args.runListIds}
            with open(run_list_file_name, "w") as fptr:
                fptr.write(json.dumps(chef_json))

            with open(token_file_path, "w") as fptr:
                fptr.write(token)
                fptr.write(os.linesep)

            exe = self.conf.get_script_location(
                "runConfigurationManagement-CHEF")
            cmd_list = [
                exe, self.args.runAsUser, self.args.configClientName,
                token_file_path, run_list_file_name, authId, endpoint,
                environmentId,
                self.conf.configuration_management_chef_client_version
            ]
            return plugin_utils.run_command(self.conf, cmd_list)
        finally:
            plugin_utils.safe_delete(run_list_file_name)
            plugin_utils.safe_delete(token_file_path)
Beispiel #18
0
    def run(self):
        script_file = self.conf.get_temp_file("exe_script")
        data = self.args.b64script
        if self.args.compression:
            if self.args.compression not in _g_compression_map:
                raise plugin_exceptions.AgentPluginBadParameterException(
                    'compression',
                    "The value % is not a supported compression module")
            data = _g_compression_map[self.args.compression](data)
        sha256 = hashlib.sha256()
        sha256.update(data)
        actual_checksum = sha256.hexdigest()
        if actual_checksum != self.args.checksum:
            raise plugin_exceptions.AgentPluginOperationException(
                "The checksum did not match")
        try:
            with open(script_file, "wb") as f:
                f.write(data)
            os.chmod(script_file, 0o755)

            command_list = []
            if self.args.runUnderSudo:
                command_list.append(self.conf.system_sudo)
            if self.args.inpython:
                command_list.append(sys.executable)
            command_list.append(script_file)
            if self.args.arguments:
                command_list.extend(self.args.arguments)
            _g_logger.debug("Plugin running the command %s"
                            % str(command_list))
            (stdout, stderr, rc) = plugin_utils.run_command(
                self.conf, command_list)
            _g_logger.debug("Command %s: stdout %s.  stderr: %s" %
                            (str(command_list), stdout, stderr))
            return plugin_base.PluginReply(
                rc, message=stdout, error_message=stderr, reply_type="void")
        finally:
            if os.path.exists(script_file):
                os.remove(script_file)
Beispiel #19
0
 def setup_encryption(self, device_id, encrypted_device_id, key_file_path):
     command = [self.conf.get_script_location("setupEncryption"), device_id, encrypted_device_id, key_file_path]
     (stdout, stderr, rc) = plugin_utils.run_command(self.conf, command)
     if rc != 0:
         raise exceptions.AgentExecutableException(command, rc, stdout, stderr)
     return rc