Package com.cloud.utils.script

Examples of com.cloud.utils.script.Script


                        }
                    }

                    String result = null;
                    for (int i = 0; i < 5; i++) {
                        Script cmd = new Script(_heartBeatPath,
                                _heartBeatUpdateTimeout, s_logger);
                        cmd.add("-i", primaryStoragePool._poolIp);
                        cmd.add("-p", primaryStoragePool._poolMountSourcePath);
                        cmd.add("-m", primaryStoragePool._mountDestPath);
                        cmd.add("-h", _hostIP);
                        result = cmd.execute();
                        if (result != null) {
                            s_logger.warn("write heartbeat failed: " + result
                                    + ", retry: " + i);
                        } else {
                            break;
                        }
                    }

                    if (result != null) {
                        s_logger.warn("write heartbeat failed: " + result
                                + "; reboot the host");
                        Script cmd = new Script(_heartBeatPath,
                                _heartBeatUpdateTimeout, s_logger);
                        cmd.add("-i", primaryStoragePool._poolIp);
                        cmd.add("-p", primaryStoragePool._poolMountSourcePath);
                        cmd.add("-m", primaryStoragePool._mountDestPath);
                        cmd.add("-c");
                        result = cmd.execute();
                    }
                }
            }

        }
View Full Code Here


        s_logger.debug("Checking if network " + networkName + " exists as openvswitch bridge");
        if (networkName == null) {
            return true;
        }

        Script command = new Script("/bin/sh", _timeout);
        command.add("-c");
        command.add("ovs-vsctl br-exists " + networkName);
        String result = command.execute(null);
        if ("Ok".equals(result)) {
            return true;
        } else {
            return false;
        }
View Full Code Here

        }
    }

    private boolean passCmdLine(String vmName, String cmdLine)
            throws InternalErrorException {
        final Script command = new Script(_patchViaSocketPath, 5*1000, s_logger);
        String result;
        command.add("-n",vmName);
        command.add("-p", cmdLine.replaceAll(" ", "%"));
        result = command.execute();
        if (result != null) {
            s_logger.debug("passcmd failed:" + result);
            return false;
        }
        return true;
View Full Code Here

                    return new ResizeVolumeAnswer(cmd, false, "Unable to shrink volumes of type " + type);
                }

                s_logger.debug("got to the stage where we execute the volume resize, params:"
                            + path + "," + currentSize + "," + newSize + "," + type + "," + vmInstanceName + "," + shrinkOk);
                final Script resizecmd = new Script(_resizeVolumePath,
                            _cmdsTimeout, s_logger);
                resizecmd.add("-s",String.valueOf(newSize));
                resizecmd.add("-c",String.valueOf(currentSize));
                resizecmd.add("-p",path);
                resizecmd.add("-t",type);
                resizecmd.add("-r",String.valueOf(shrinkOk));
                resizecmd.add("-v",vmInstanceName);
                String result = resizecmd.execute();

                if (result != null) {
                    return new ResizeVolumeAnswer(cmd, false, result);
                }
            }
View Full Code Here

      String result = null;
        Connect conn;
    try {
      if (cmd.getType() == PvlanSetupCommand.Type.DHCP) {
        Script script = new Script(_ovsPvlanDhcpHostPath, _timeout, s_logger);
        if (add) {
          conn = LibvirtConnection.getConnectionByVmName(dhcpName);
          List<InterfaceDef> ifaces = getInterfaces(conn, dhcpName);
          InterfaceDef guestNic = ifaces.get(0);
          script.add(opr, "-b", _guestBridgeName,
            "-p", primaryPvlan, "-i", isolatedPvlan, "-n", dhcpName,
            "-d", dhcpIp, "-m", dhcpMac, "-I", guestNic.getDevName());
        } else {
          script.add(opr, "-b", _guestBridgeName,
            "-p", primaryPvlan, "-i", isolatedPvlan, "-n", dhcpName,
            "-d", dhcpIp, "-m", dhcpMac);
        }
        result = script.execute();
        if (result != null) {
          s_logger.warn("Failed to program pvlan for dhcp server with mac " + dhcpMac);
          return new Answer(cmd, false, result);
        } else {
          s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac);
        }
      } else if (cmd.getType() == PvlanSetupCommand.Type.VM) {
        Script script = new Script(_ovsPvlanVmPath, _timeout, s_logger);
        script.add(opr, "-b", _guestBridgeName,
            "-p", primaryPvlan, "-i", isolatedPvlan, "-v", vmMac);
        result = script.execute();
        if (result != null) {
          s_logger.warn("Failed to program pvlan for vm with mac " + vmMac);
          return new Answer(cmd, false, result);
        } else {
          s_logger.info("Programmed pvlan for vm with mac " + vmMac);
View Full Code Here

                    } catch (Exception e) {
                        s_logger.error("A RBD snapshot operation on " + disk.getName() + " failed. The error was: " + e.getMessage());
                    }
                } else {
                    /* VM is not running, create a snapshot by ourself */
                    final Script command = new Script(_manageSnapshotPath,
                            _cmdsTimeout, s_logger);
                    if (cmd.getCommandSwitch().equalsIgnoreCase(
                            ManageSnapshotCommand.CREATE_SNAPSHOT)) {
                        command.add("-c", disk.getPath());
                    } else {
                        command.add("-d", snapshotPath);
                    }

                    command.add("-n", snapshotName);
                    String result = command.execute();
                    if (result != null) {
                        s_logger.debug("Failed to manage snapshot: " + result);
                        return new ManageSnapshotAnswer(cmd, false,
                                "Failed to manage snapshot: " + result);
                    }
View Full Code Here

                } catch (IOException e) {
                    s_logger.debug("An I/O error occured during a snapshot operation on " + snapshotDestPath);
                    return new BackupSnapshotAnswer(cmd, false, e.toString(), null, true);
                }
            } else {
                Script command = new Script(_manageSnapshotPath, _cmdsTimeout,
                        s_logger);
                command.add("-b", snapshotDisk.getPath());
                command.add("-n", snapshotName);
                command.add("-p", snapshotDestPath);
                command.add("-t", snapshotName);
                String result = command.execute();
                if (result != null) {
                    s_logger.debug("Failed to backup snaptshot: " + result);
                    return new BackupSnapshotAnswer(cmd, false, result, null, true);
                }
            }
            /* Delete the snapshot on primary */

            DomainInfo.DomainState state = null;
            Domain vm = null;
            if (vmName != null) {
                try {
                    vm = getDomain(conn, cmd.getVmName());
                    state = vm.getInfo().state;
                } catch (LibvirtException e) {
                    s_logger.trace("Ignoring libvirt error.", e);
                }
            }

            KVMStoragePool primaryStorage = _storagePoolMgr.getStoragePool(
                    cmd.getPool().getType(),
                    cmd.getPool().getUuid());
            if (state == DomainInfo.DomainState.VIR_DOMAIN_RUNNING
                    && !primaryStorage.isExternalSnapshot()) {
                String vmUuid = vm.getUUIDString();
                Object[] args = new Object[] { snapshotName, vmUuid };
                String snapshot = SnapshotXML.format(args);
                s_logger.debug(snapshot);
                DomainSnapshot snap = vm.snapshotLookupByName(snapshotName);
                snap.delete(0);

                /*
                 * libvirt on RHEL6 doesn't handle resume event emitted from
                 * qemu
                 */
                vm = getDomain(conn, cmd.getVmName());
                state = vm.getInfo().state;
                if (state == DomainInfo.DomainState.VIR_DOMAIN_PAUSED) {
                    vm.resume();
                }
            } else {
                Script command = new Script(_manageSnapshotPath, _cmdsTimeout,
                        s_logger);
                command.add("-d", snapshotDisk.getPath());
                command.add("-n", snapshotName);
                String result = command.execute();
                if (result != null) {
                    s_logger.debug("Failed to backup snapshot: " + result);
                    return new BackupSnapshotAnswer(cmd, false,
                            "Failed to backup snapshot: " + result, null, true);
                }
View Full Code Here

            _storage.mkdirs(templatePath);

            String tmplPath = templateInstallFolder + File.separator
                    + tmplFileName;
            Script command = new Script(_createTmplPath, _cmdsTimeout, s_logger);
            command.add("-t", templatePath);
            command.add("-n", tmplFileName);
            command.add("-f", snapshot.getPath());
            command.execute();

            Map<String, Object> params = new HashMap<String, Object>();
            params.put(StorageLayer.InstanceConfigKey, _storage);
            Processor qcow2Processor = new QCOW2Processor();
            qcow2Processor.configure("QCOW2 Processor", params);
View Full Code Here

            String tmpltPath = secondaryStorage.getLocalPath() + File.separator
                    + templateInstallFolder;
            _storage.mkdirs(tmpltPath);

            if (primary.getType() != StoragePoolType.RBD) {
                Script command = new Script(_createTmplPath, _cmdsTimeout, s_logger);
                command.add("-f", disk.getPath());
                command.add("-t", tmpltPath);
                command.add("-n", cmd.getUniqueName() + ".qcow2");

                String result = command.execute();

                if (result != null) {
                    s_logger.debug("failed to create template: " + result);
                    return new CreatePrivateTemplateAnswer(cmd, false, result);
                }
View Full Code Here

        }
        return new Answer(cmd);
    }

    private String doPingTest(final String computingHostIp) {
        final Script command = new Script(_pingTestPath, 10000, s_logger);
        command.add("-h", computingHostIp);
        return command.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.