Package com.cloud.utils.script

Examples of com.cloud.utils.script.Script


            return new CopyCmdAnswer("failed to upload" + srcData.getPath() + e.toString());
        }
    }

    String swiftDownload(SwiftTO swift, String container, String rfilename, String lFullPath) {
        Script command = new Script("/bin/bash", s_logger);
        command.add("-c");
        command.add("/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl()
                + " -U " + swift.getAccount() + ":" + swift.getUserName() + " -K " + swift.getKey() + " download "
                + container + " " + rfilename + " -o " + lFullPath);
        OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
        String result = command.execute(parser);
        if (result != null) {
            String errMsg = "swiftDownload failed  err=" + result;
            s_logger.warn(errMsg);
            return errMsg;
        }
View Full Code Here


        return null;

    }

    String swiftDownloadContainer(SwiftTO swift, String container, String ldir) {
        Script command = new Script("/bin/bash", s_logger);
        command.add("-c");
        command.add("cd " + ldir + ";/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A "
                + swift.getUrl() + " -U " + swift.getAccount() + ":" + swift.getUserName() + " -K " + swift.getKey()
                + " download " + container);
        OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
        String result = command.execute(parser);
        if (result != null) {
            String errMsg = "swiftDownloadContainer failed  err=" + result;
            s_logger.warn(errMsg);
            return errMsg;
        }
View Full Code Here

        }

        for (String file : files) {
            File f = new File(lDir + "/" + file);
            long size = f.length();
            Script command = new Script("/bin/bash", s_logger);
            command.add("-c");
            if (size <= SWIFT_MAX_SIZE) {
                command.add("cd " + lDir
                        + ";/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A "
                        + swift.getUrl() + " -U " + swift.getAccount() + ":" + swift.getUserName() + " -K "
                        + swift.getKey() + " upload " + container + " " + file);
            } else {
                command.add("cd " + lDir
                        + ";/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A "
                        + swift.getUrl() + " -U " + swift.getAccount() + ":" + swift.getUserName() + " -K "
                        + swift.getKey() + " upload -S " + SWIFT_MAX_SIZE + " " + container + " " + file);
            }
            OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
            String result = command.execute(parser);
            if (result != null) {
                String errMsg = "swiftUpload failed , err=" + result;
                s_logger.warn(errMsg);
                return errMsg;
            }
View Full Code Here

        return null;
    }

    String[] swiftList(SwiftTO swift, String container, String rFilename) {
        Script command = new Script("/bin/bash", s_logger);
        command.add("-c");
        command.add("/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl()
                + " -U " + swift.getAccount() + ":" + swift.getUserName() + " -K " + swift.getKey() + " list "
                + container + " " + rFilename);
        OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
        String result = command.execute(parser);
        if (result == null && parser.getLines() != null) {
            String[] lines = parser.getLines().split("\\n");
            return lines;
        } else {
            if (result != null) {
View Full Code Here

        }
        return null;
    }

    String swiftDelete(SwiftTO swift, String container, String object) {
        Script command = new Script("/bin/bash", s_logger);
        command.add("-c");
        command.add("/usr/bin/python /usr/local/cloud/systemvm/scripts/storage/secondary/swift -A " + swift.getUrl()
                + " -U " + swift.getAccount() + ":" + swift.getUserName() + " -K " + swift.getKey() + " delete "
                + container + " " + object);
        OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
        String result = command.execute(parser);
        if (result != null) {
            String errMsg = "swiftDelete failed , err=" + result;
            s_logger.warn(errMsg);
            return errMsg;
        }
View Full Code Here

        return new Answer(cmd, success, result.toString());

    }

    private String setVhdParent(String lFullPath, String pFullPath) {
        Script command = new Script("/bin/bash", s_logger);
        command.add("-c");
        command.add("/bin/vhd-util modify -n " + lFullPath + " -p " + pFullPath);
        String result = command.execute();
        if (result != null) {
            String errMsg = "failed to set vhd parent, child " + lFullPath + " parent " + pFullPath + ", err=" + result;
            s_logger.warn(errMsg);
            return errMsg;
        }
View Full Code Here

     *            Options for the create. Takes a Map<String, String> with key value
     *            pairs which are passed on to qemu-img without validation.
     * @return void
     */
    public void create(QemuImgFile file, QemuImgFile backingFile, Map<String, String> options) throws QemuImgException {
        Script s = new Script(_qemuImgPath);
        s.add("create");

        if (options != null && !options.isEmpty()) {
            s.add("-o");
            String optionsStr = "";
            for (Map.Entry<String, String> option : options.entrySet()) {
                optionsStr += option.getKey() + "=" + option.getValue() + ",";
            }
            s.add(optionsStr);
        }

        /*
            -b for a backing file does not show up in the docs, but it works.
            Shouldn't this be -o backing_file=filename instead?
        */
        s.add("-f");
        if (backingFile != null) {
            s.add(backingFile.getFormat().toString());
            s.add("-b");
            s.add(backingFile.getFileName());
        } else {
            s.add(file.getFormat().toString());
        }

        s.add(file.getFileName());

        if (backingFile == null) {
            s.add(Long.toString(file.getSize()));
        }
        String result = s.execute();
        if (result != null) {
            throw new QemuImgException(result);
        }
    }
View Full Code Here

     *            Options for the convert. Takes a Map<String, String> with key value
     *            pairs which are passed on to qemu-img without validation.
     * @return void
     */
    public void convert(QemuImgFile srcFile, QemuImgFile destFile, Map<String, String> options) throws QemuImgException {
        Script s = new Script(_qemuImgPath);
        s.add("convert");
        s.add("-f");
        s.add(srcFile.getFormat().toString());
        s.add("-O");
        s.add(destFile.getFormat().toString());

        if (options != null && !options.isEmpty()) {
            s.add("-o");
            String optionsStr = "";
            for (Map.Entry<String, String> option : options.entrySet()) {
                optionsStr += option.getKey() + "=" + option.getValue() + ",";
            }
            s.add(optionsStr);
        }

        s.add(srcFile.getFileName());
        s.add(destFile.getFileName());

        String result = s.execute();
        if (result != null) {
            throw new QemuImgException(result);
        }
    }
View Full Code Here

     * @param file
     *            A QemuImgFile object containing the file to get the information from
     * @return A HashMap with String key-value information as returned by 'qemu-img info'
     */
    public Map<String, String> info(QemuImgFile file) throws QemuImgException {
        Script s = new Script(_qemuImgPath);
        s.add("info");
        s.add(file.getFileName());
        OutputInterpreter.AllLinesParser parser = new OutputInterpreter.AllLinesParser();
        String result = s.execute(parser);
        if (result != null) {
            throw new QemuImgException(result);
        }

        HashMap<String,String> info = new HashMap<String,String>();
View Full Code Here

                throw new QemuImgException("size should not be negative if 'delta' is false!");
            }
            newSize = Long.toString(size);
        }

        Script s = new Script(_qemuImgPath);
        s.add("resize");
        s.add(file.getFileName());
        s.add(newSize);
        s.execute();
    }
View Full Code Here

TOP

Related Classes of com.cloud.utils.script.Script

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.