Search in sources :

Example 1 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class LibvirtPvlanSetupCommandWrapper method execute.

@Override
public Answer execute(final PvlanSetupCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final String primaryPvlan = command.getPrimary();
    final String isolatedPvlan = command.getIsolated();
    final String op = command.getOp();
    final String dhcpName = command.getDhcpName();
    final String dhcpMac = command.getDhcpMac();
    final String dhcpIp = command.getDhcpIp();
    final String vmMac = command.getVmMac();
    boolean add = true;
    String opr = "-A";
    if (op.equals("delete")) {
        opr = "-D";
        add = false;
    }
    String result = null;
    try {
        final String guestBridgeName = libvirtComputingResource.getGuestBridgeName();
        final int timeout = libvirtComputingResource.getScriptsTimeout();
        if (command.getType() == PvlanSetupCommand.Type.DHCP) {
            final String ovsPvlanDhcpHostPath = libvirtComputingResource.getOvsPvlanDhcpHostPath();
            final Script script = new Script(ovsPvlanDhcpHostPath, timeout, s_logger);
            if (add) {
                final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper();
                final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(dhcpName);
                final List<LibvirtVmDef.InterfaceDef> ifaces = libvirtComputingResource.getInterfaces(conn, dhcpName);
                final LibvirtVmDef.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(command, false, result);
            } else {
                s_logger.info("Programmed pvlan for dhcp server with mac " + dhcpMac);
            }
        } else if (command.getType() == PvlanSetupCommand.Type.VM) {
            final String ovsPvlanVmPath = libvirtComputingResource.getOvsPvlanVmPath();
            final 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(command, false, result);
            } else {
                s_logger.info("Programmed pvlan for vm with mac " + vmMac);
            }
        }
    } catch (final LibvirtException e) {
        s_logger.error("Error whislt executing OVS Setup command! ==> " + e.getMessage());
        return new Answer(command, false, e.getMessage());
    }
    return new Answer(command, true, result);
}
Also used : Script(com.cloud.utils.script.Script) LibvirtVmDef(com.cloud.agent.resource.kvm.xml.LibvirtVmDef) Answer(com.cloud.legacymodel.communication.answer.Answer) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect)

Example 2 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class LibvirtDestroyCommandWrapper method execute.

@Override
public Answer execute(final DestroyCommand command, final LibvirtComputingResource libvirtComputingResource) {
    final VolumeTO vol = command.getVolume();
    try {
        final KvmStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
        final KvmStoragePool pool = storagePoolMgr.getStoragePool(vol.getPoolType(), vol.getPoolUuid());
        pool.deletePhysicalDisk(vol.getPath(), null);
        return new Answer(command, true, "Success");
    } catch (final CloudRuntimeException e) {
        s_logger.debug("Failed to delete volume: " + e.toString());
        return new Answer(command, false, e.toString());
    }
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) VolumeTO(com.cloud.legacymodel.to.VolumeTO) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)

Example 3 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method deleteSnapshot.

protected Answer deleteSnapshot(final DeleteCommand cmd) {
    final DataTO obj = cmd.getData();
    final DataStoreTO dstore = obj.getDataStore();
    if (dstore instanceof NfsTO) {
        final NfsTO nfs = (NfsTO) dstore;
        String parent = getRootDir(nfs.getUrl());
        if (!parent.endsWith(File.separator)) {
            parent += File.separator;
        }
        String snapshotPath = obj.getPath();
        if (snapshotPath.startsWith(File.separator)) {
            snapshotPath = snapshotPath.substring(1);
        }
        // check if the passed snapshot path is a directory or not. For ImageCache, path is stored as a directory instead of
        // snapshot file name. If so, since backupSnapshot process has already deleted snapshot in cache, so we just do nothing
        // and return true.
        final String fullSnapPath = parent + snapshotPath;
        final File snapDir = new File(fullSnapPath);
        if (snapDir.exists() && snapDir.isDirectory()) {
            s_logger.debug("snapshot path " + snapshotPath + " is a directory, already deleted during backup snapshot, so no need to delete");
            return new Answer(cmd, true, null);
        }
        // passed snapshot path is a snapshot file path, then get snapshot directory first
        final int index = snapshotPath.lastIndexOf("/");
        final String snapshotName = snapshotPath.substring(index + 1);
        snapshotPath = snapshotPath.substring(0, index);
        final String absoluteSnapshotPath = parent + snapshotPath;
        // check if snapshot directory exists
        final File snapshotDir = new File(absoluteSnapshotPath);
        String details = null;
        if (!snapshotDir.exists()) {
            details = "snapshot directory " + snapshotDir.getName() + " doesn't exist";
            s_logger.debug(details);
            return new Answer(cmd, true, details);
        }
        // delete snapshot in the directory if exists
        final String lPath = absoluteSnapshotPath + "/*" + snapshotName + "*";
        final String result = deleteLocalFile(lPath);
        if (result != null) {
            details = "failed to delete snapshot " + lPath + " , err=" + result;
            s_logger.warn(details);
            return new Answer(cmd, false, details);
        }
        return new Answer(cmd, true, null);
    } else {
        return new Answer(cmd, false, "Unsupported image data store: " + dstore);
    }
}
Also used : ListTemplateAnswer(com.cloud.legacymodel.communication.answer.ListTemplateAnswer) GetStorageStatsAnswer(com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer) ReadyAnswer(com.cloud.legacymodel.communication.answer.ReadyAnswer) ListVolumeAnswer(com.cloud.legacymodel.communication.answer.ListVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) CheckHealthAnswer(com.cloud.legacymodel.communication.answer.CheckHealthAnswer) UploadStatusAnswer(com.cloud.legacymodel.communication.answer.UploadStatusAnswer) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) DataTO(com.cloud.legacymodel.to.DataTO) NfsTO(com.cloud.legacymodel.to.NfsTO) File(java.io.File)

Example 4 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method execute.

protected Answer execute(final DeleteCommand cmd) {
    final DataTO obj = cmd.getData();
    final DataObjectType objType = obj.getObjectType();
    if (obj.getPath() == null) {
        // account for those fake entries for NFS migration to object store
        return new Answer(cmd, true, "Object with null install path does not exist on image store , no need to delete");
    }
    switch(objType) {
        case TEMPLATE:
            return deleteTemplate(cmd);
        case VOLUME:
            return deleteVolume(cmd);
        case SNAPSHOT:
            return deleteSnapshot(cmd);
    }
    return Answer.createUnsupportedCommandAnswer(cmd);
}
Also used : ListTemplateAnswer(com.cloud.legacymodel.communication.answer.ListTemplateAnswer) GetStorageStatsAnswer(com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer) ReadyAnswer(com.cloud.legacymodel.communication.answer.ReadyAnswer) ListVolumeAnswer(com.cloud.legacymodel.communication.answer.ListVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) CheckHealthAnswer(com.cloud.legacymodel.communication.answer.CheckHealthAnswer) UploadStatusAnswer(com.cloud.legacymodel.communication.answer.UploadStatusAnswer) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) DataTO(com.cloud.legacymodel.to.DataTO) DataObjectType(com.cloud.model.enumeration.DataObjectType)

Example 5 with Answer

use of com.cloud.legacymodel.communication.answer.Answer in project cosmic by MissionCriticalCloud.

the class NfsSecondaryStorageResource method execute.

private Answer execute(final ListVolumeCommand cmd) {
    if (!this._inSystemVM) {
        return new ListVolumeAnswer(cmd.getSecUrl(), null);
    }
    final DataStoreTO store = cmd.getDataStore();
    if (store instanceof NfsTO) {
        final String root = getRootDir(cmd.getSecUrl());
        final Map<Long, TemplateProp> templateInfos = this._dlMgr.gatherVolumeInfo(root);
        return new ListVolumeAnswer(cmd.getSecUrl(), templateInfos);
    } else {
        return new Answer(cmd, false, "Unsupported image data store: " + store);
    }
}
Also used : TemplateProp(com.cloud.legacymodel.storage.TemplateProp) ListTemplateAnswer(com.cloud.legacymodel.communication.answer.ListTemplateAnswer) GetStorageStatsAnswer(com.cloud.legacymodel.communication.answer.GetStorageStatsAnswer) ReadyAnswer(com.cloud.legacymodel.communication.answer.ReadyAnswer) ListVolumeAnswer(com.cloud.legacymodel.communication.answer.ListVolumeAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CopyCmdAnswer(com.cloud.legacymodel.communication.answer.CopyCmdAnswer) CheckHealthAnswer(com.cloud.legacymodel.communication.answer.CheckHealthAnswer) UploadStatusAnswer(com.cloud.legacymodel.communication.answer.UploadStatusAnswer) SecStorageSetupAnswer(com.cloud.legacymodel.communication.answer.SecStorageSetupAnswer) DataStoreTO(com.cloud.legacymodel.to.DataStoreTO) ListVolumeAnswer(com.cloud.legacymodel.communication.answer.ListVolumeAnswer) NfsTO(com.cloud.legacymodel.to.NfsTO)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)342 Test (org.junit.Test)201 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)173 CheckRouterAnswer (com.cloud.legacymodel.communication.answer.CheckRouterAnswer)116 LibvirtRequestWrapper (com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper)110 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)63 LibvirtUtilitiesHelper (com.cloud.agent.resource.kvm.wrapper.LibvirtUtilitiesHelper)61 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)58 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)54 LibvirtException (org.libvirt.LibvirtException)53 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)53 KvmStoragePoolManager (com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager)48 Connection (com.xensource.xenapi.Connection)48 ArrayList (java.util.ArrayList)45 KvmStoragePool (com.cloud.agent.resource.kvm.storage.KvmStoragePool)39 StoragePool (com.cloud.legacymodel.storage.StoragePool)38 Connect (org.libvirt.Connect)38 NfsStoragePool (com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool)29 CopyCmdAnswer (com.cloud.legacymodel.communication.answer.CopyCmdAnswer)29 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)27