Skip to content

Commit

Permalink
Implement localstorage based on LVM
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Schrijver committed Jun 7, 2018
1 parent b87bca2 commit 3065a94
Show file tree
Hide file tree
Showing 108 changed files with 882 additions and 835 deletions.
17 changes: 14 additions & 3 deletions cosmic-agent/bindir/cosmic-setup-agent.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/python

from optparse import OptionParser

import os
import uuid
import yaml
from optparse import OptionParser

if __name__ == '__main__':
parser = OptionParser()
Expand All @@ -24,7 +24,18 @@
config['cosmic']['cluster'] = options.cluster
config['cosmic']['pod'] = options.pod
config['cosmic']['zone'] = options.zone
config['cosmic']['localstorage']['uuid'] = options.guid
config['cosmic']['localstorages'] = [
{
'uuid': str(uuid.uuid4()),
'path': 'vg_vdb',
'type': 'LVM'
},
{
'uuid': str(uuid.uuid4()),
'path': 'vg_vdc',
'type': 'LVM'
}
]

with open('/etc/cosmic/agent/application.yml', 'w') as f:
yaml.dump(config, f, default_flow_style=False)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.cloud.agent.resource;

import com.cloud.agent.service.AgentConfiguration;
import com.cloud.common.agent.IAgentControl;
import com.cloud.legacymodel.communication.answer.Answer;
import com.cloud.legacymodel.communication.command.Command;
import com.cloud.legacymodel.communication.command.PingCommand;
import com.cloud.legacymodel.communication.command.StartupCommand;
import com.cloud.legacymodel.communication.command.startup.StartupCommand;
import com.cloud.model.enumeration.HostType;

import javax.naming.ConfigurationException;
Expand All @@ -17,6 +18,8 @@ public interface AgentResource {

boolean configure(Map<String, Object> params) throws ConfigurationException;

void configure(AgentConfiguration agentConfiguration);

boolean start();

boolean stop();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cloud.agent.resource;

import com.cloud.common.agent.IAgentControl;
import com.cloud.legacymodel.communication.command.StartupCommand;
import com.cloud.legacymodel.communication.command.startup.StartupCommand;
import com.cloud.utils.net.NetUtils;

import javax.naming.ConfigurationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cloud.agent.resource.AgentResource;
import com.cloud.agent.resource.AgentResourceBase;
import com.cloud.agent.service.AgentConfiguration;
import com.cloud.common.managed.context.ManagedContextRunnable;
import com.cloud.legacymodel.communication.answer.Answer;
import com.cloud.legacymodel.communication.answer.CheckHealthAnswer;
Expand All @@ -13,9 +14,9 @@
import com.cloud.legacymodel.communication.command.PingCommand;
import com.cloud.legacymodel.communication.command.ReadyCommand;
import com.cloud.legacymodel.communication.command.StartConsoleProxyAgentHttpHandlerCommand;
import com.cloud.legacymodel.communication.command.StartupCommand;
import com.cloud.legacymodel.communication.command.StartupProxyCommand;
import com.cloud.legacymodel.communication.command.WatchConsoleProxyLoadCommand;
import com.cloud.legacymodel.communication.command.startup.StartupCommand;
import com.cloud.legacymodel.communication.command.startup.StartupProxyCommand;
import com.cloud.model.enumeration.ExitStatus;
import com.cloud.model.enumeration.HostType;
import com.cloud.utils.NumbersUtil;
Expand Down Expand Up @@ -56,6 +57,8 @@
public class ConsoleProxyResource extends AgentResourceBase implements AgentResource {
static final Logger s_logger = LoggerFactory.getLogger(ConsoleProxyResource.class);

private AgentConfiguration agentConfiguration;

private final Properties _properties = new Properties();
long _proxyVmId;
int _proxyPort;
Expand Down Expand Up @@ -293,6 +296,11 @@ public boolean configure(final Map<String, Object> params) throws ConfigurationE
return true;
}

@Override
public void configure(final AgentConfiguration agentConfiguration) {
this.agentConfiguration = agentConfiguration;
}

@Override
public void disconnected() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.GraphicDef;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.GuestDef;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.GuestResourceDef;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.HyperVEnlightenmentFeatureDef;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InputDef;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.InterfaceDef;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.MetadataDef;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.QemuGuestAgentDef;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.HyperVEnlightenmentFeatureDef;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.RngDef;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.ScsiDef;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.SerialDef;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.TermPolicy;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.VideoDef;
import com.cloud.agent.resource.kvm.xml.LibvirtVmDef.WatchDogDef;
import com.cloud.agent.service.AgentConfiguration;
import com.cloud.common.resource.ServerResource;
import com.cloud.common.storageprocessor.resource.StorageSubsystemCommandHandler;
import com.cloud.common.storageprocessor.resource.StorageSubsystemCommandHandlerBase;
Expand All @@ -66,10 +67,10 @@
import com.cloud.legacymodel.communication.command.NetworkElementCommand;
import com.cloud.legacymodel.communication.command.PingCommand;
import com.cloud.legacymodel.communication.command.PingRoutingCommand;
import com.cloud.legacymodel.communication.command.StartupCommand;
import com.cloud.legacymodel.communication.command.StartupRoutingCommand;
import com.cloud.legacymodel.communication.command.StartupStorageCommand;
import com.cloud.legacymodel.communication.command.UpdateNetworkOverviewCommand;
import com.cloud.legacymodel.communication.command.startup.StartupCommand;
import com.cloud.legacymodel.communication.command.startup.StartupLocalstorageCommand;
import com.cloud.legacymodel.communication.command.startup.StartupRoutingCommand;
import com.cloud.legacymodel.exceptions.CloudRuntimeException;
import com.cloud.legacymodel.exceptions.InternalErrorException;
import com.cloud.legacymodel.network.VRScripts;
Expand All @@ -95,12 +96,11 @@
import com.cloud.model.enumeration.GuestNetType;
import com.cloud.model.enumeration.HostType;
import com.cloud.model.enumeration.HypervisorType;
import com.cloud.model.enumeration.OptimiseFor;
import com.cloud.model.enumeration.ImageFormat;
import com.cloud.model.enumeration.OptimiseFor;
import com.cloud.model.enumeration.RngBackendModel;
import com.cloud.model.enumeration.RouterPrivateIpStrategy;
import com.cloud.model.enumeration.StoragePoolType;
import com.cloud.model.enumeration.StorageResourceType;
import com.cloud.model.enumeration.TrafficType;
import com.cloud.model.enumeration.VirtualMachineType;
import com.cloud.model.enumeration.VolumeType;
Expand Down Expand Up @@ -230,6 +230,7 @@ public class LibvirtComputingResource extends AgentResourceBase implements Agent
}

private final LibvirtComputingResourceProperties libvirtComputingResourceProperties = new LibvirtComputingResourceProperties();
private AgentConfiguration agentConfiguration;

private final Map<String, String> pifs = new HashMap<>();
private final Map<String, VmStats> vmStats = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -715,6 +716,11 @@ public boolean configure(final Map<String, Object> params) throws ConfigurationE
return true;
}

@Override
public void configure(final AgentConfiguration agentConfiguration) {
this.agentConfiguration = agentConfiguration;
}

private void initLibvirtLifecycleListener() {
try {
final Connect conn = LibvirtConnection.getConnection();
Expand Down Expand Up @@ -1239,6 +1245,8 @@ public String getResizeScriptType(final KvmStoragePool pool, final KvmPhysicalDi

if (pool.getType() == StoragePoolType.CLVM && volFormat == PhysicalDiskFormat.RAW) {
return "CLVM";
} else if (pool.getType() == StoragePoolType.LVM && volFormat == PhysicalDiskFormat.RAW) {
return "LVM";
} else if ((poolType == StoragePoolType.NetworkFilesystem
|| poolType == StoragePoolType.SharedMountPoint
|| poolType == StoragePoolType.Filesystem
Expand Down Expand Up @@ -1669,13 +1677,12 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
final String mountpoint = pool.getLocalPath();
final String path = physicalDisk.getPath();
final String glusterVolume = pool.getSourceDir().replace("/", "");
disk.defNetworkBasedDisk(glusterVolume + path.replace(mountpoint, ""), pool.getSourceHost(),
pool.getSourcePort(), null,
null, devId, volume.getDiskController(), DiskProtocol.GLUSTER, ImageFormat.QCOW2);
} else if (volume.getDiskFormat() == ImageFormat.RAW) {
disk.defFileBasedDisk(physicalDisk.getPath(), devId, volume.getDiskController(), ImageFormat.RAW);
} else {
disk.defFileBasedDisk(physicalDisk.getPath(), devId, volume.getDiskController(), ImageFormat.QCOW2);
disk.defNetworkBasedDisk(glusterVolume + path.replace(mountpoint, ""), pool.getSourceHost(), pool.getSourcePort(), null, null, devId, volume.getDiskController(), DiskProtocol
.GLUSTER, ImageFormat.QCOW2);
} else if (pool.getType() == StoragePoolType.CLVM || pool.getType() == StoragePoolType.LVM) {
disk.defBlockBasedDisk(physicalDisk.getPath(), devId, volume.getDiskController());
} else if (pool.getType() == StoragePoolType.NetworkFilesystem) {
disk.defFileBasedDisk(physicalDisk.getPath(), devId, volume.getDiskController(), volume.getDiskFormat());
}
}

Expand Down Expand Up @@ -1743,12 +1750,20 @@ public String diskUuidToSerial(final String uuid) {

@Override
public StartupCommand[] initialize() {
final List<StartupCommand> startupCommandList = new ArrayList<>();

final List<Object> info = getHostInfo();
this.totalMemory = (Long) info.get(1);

final StartupRoutingCommand cmd = new StartupRoutingCommand((Integer) info.get(0), (Long) info.get(1), (Long) info.get(3), (String) info.get(2), getHypervisorType(),
RouterPrivateIpStrategy.HostLocal);
final StartupRoutingCommand cmd = new StartupRoutingCommand(
(Integer) info.get(0),
(Long) info.get(1),
(Long) info.get(3),
(String) info.get(2),
getHypervisorType(),
RouterPrivateIpStrategy.HostLocal
);

cmd.setCpuSockets((Integer) info.get(4));
fillNetworkInformation(cmd);
this.privateIp = cmd.getPrivateIpAddress();
Expand All @@ -1759,44 +1774,46 @@ public StartupCommand[] initialize() {
cmd.setIqn(getIqn());
cmd.setVersion(LibvirtComputingResource.class.getPackage().getImplementationVersion());

StartupStorageCommand sscmd = null;
try {
startupCommandList.add(cmd);
startupCommandList.addAll(initializeLocalstorage());

return startupCommandList.toArray(new StartupCommand[startupCommandList.size()]);
}

private List<StartupLocalstorageCommand> initializeLocalstorage() {
final List<StartupLocalstorageCommand> startupLocalstorageCommandList = new ArrayList<>();

final String localStoragePath = getLocalStoragePath();
final KvmStoragePool localStoragePool = this.storagePoolMgr.createStoragePool(getLocalStorageUuid(), "localhost", -1,
localStoragePath, "", StoragePoolType.Filesystem);
final StoragePoolInfo pi = new StoragePoolInfo(localStoragePool.getUuid(),
cmd.getPrivateIpAddress(), localStoragePath, localStoragePath,
StoragePoolType.Filesystem, localStoragePool.getCapacity(), localStoragePool.getAvailable());

sscmd = new StartupStorageCommand();
sscmd.setPoolInfo(pi);
sscmd.setGuid(pi.getUuid());
sscmd.setDataCenter(getZone());
sscmd.setResourceType(StorageResourceType.STORAGE_POOL);
try {
for (final AgentConfiguration.Localstorage localstorage : this.agentConfiguration.getLocalstorages()) {
if (localstorage.getType() == StoragePoolType.LVM) {
logger.debug("Found local LVM storage pool: " + localstorage.getPath() + ", with uuid: " + localstorage.getUuid() + ", in the agent configuration");
final KvmStoragePool localStoragePool = this.storagePoolMgr.createStoragePool(localstorage.getUuid(), "localhost", -1, localstorage.getPath(), "", StoragePoolType.LVM);

final StoragePoolInfo storagePoolInfo = new StoragePoolInfo();
storagePoolInfo.setUuid(localstorage.getUuid());
storagePoolInfo.setHost(getName());
storagePoolInfo.setLocalPath(localstorage.getPath());
storagePoolInfo.setPoolType(StoragePoolType.LVM);
storagePoolInfo.setCapacityBytes(localStoragePool.getCapacity());
storagePoolInfo.setAvailableBytes(localStoragePool.getAvailable());

final StartupLocalstorageCommand startupLocalstorageCommand = new StartupLocalstorageCommand();
startupLocalstorageCommand.setPoolInfo(storagePoolInfo);

startupLocalstorageCommandList.add(startupLocalstorageCommand);
}
}
} catch (final CloudRuntimeException e) {
logger.debug("Unable to initialize local storage pool: " + e);
}

if (sscmd != null) {
return new StartupCommand[]{cmd, sscmd};
} else {
return new StartupCommand[]{cmd};
}
return startupLocalstorageCommandList;
}

private String getZone() {
return this.libvirtComputingResourceProperties.getZone();
}

private String getLocalStoragePath() {
return this.libvirtComputingResourceProperties.getLocalStoragePath();
}

private String getLocalStorageUuid() {
return this.libvirtComputingResourceProperties.getLocalStorageUuid();
}

private String getCluster() {
return this.libvirtComputingResourceProperties.getCluster();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.cloud.agent.resource.kvm.event;

import com.cloud.agent.resource.kvm.LibvirtComputingResource;
import com.cloud.legacymodel.communication.command.agentcontrolcommand.ShutdownEventCommand;
import com.cloud.legacymodel.communication.command.agentcontrol.ShutdownEventCommand;
import com.cloud.legacymodel.exceptions.AgentControlChannelException;

import org.libvirt.Domain;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public KvmStoragePool getStoragePool(final StoragePoolType type, final String uu
}

// Note: due to bug CLOUDSTACK-4459, createStoragepool can be called in parallel, so need to be synced.
private synchronized KvmStoragePool createStoragePool(final String name, final String host, final int port, final String path,
final String userInfo, final StoragePoolType type, final boolean primaryStorage) {
private synchronized KvmStoragePool createStoragePool(final String name, final String host, final int port, final String path, final String userInfo, final StoragePoolType type, final boolean
primaryStorage) {
final StorageAdaptor adaptor = getStorageAdaptor(type);
final KvmStoragePool pool = adaptor.createStoragePool(name, host, port, path, userInfo, type);

Expand Down Expand Up @@ -285,8 +285,7 @@ public KvmPhysicalDisk getPhysicalDisk(final StoragePoolType type, final String
}
}

public KvmStoragePool createStoragePool(final String name, final String host, final int port, final String path, final String userInfo,
final StoragePoolType type) {
public KvmStoragePool createStoragePool(final String name, final String host, final int port, final String path, final String userInfo, final StoragePoolType type) {
// primary storage registers itself through here
return createStoragePool(name, host, port, path, userInfo, type, true);
}
Expand Down Expand Up @@ -321,17 +320,13 @@ public KvmPhysicalDisk createDiskFromTemplate(final KvmPhysicalDisk template, fi

// LibvirtStorageAdaptor-specific statement
if (destPool.getType() == StoragePoolType.RBD) {
return adaptor.createDiskFromTemplate(template, name,
PhysicalDiskFormat.RAW, provisioningType,
size, destPool, timeout);
return adaptor.createDiskFromTemplate(template, name, PhysicalDiskFormat.RAW, provisioningType, size, destPool, timeout);
} else if (destPool.getType() == StoragePoolType.CLVM) {
return adaptor.createDiskFromTemplate(template, name,
PhysicalDiskFormat.RAW, provisioningType,
size, destPool, timeout);
return adaptor.createDiskFromTemplate(template, name, PhysicalDiskFormat.RAW, provisioningType, size, destPool, timeout);
} else if (destPool.getType() == StoragePoolType.LVM) {
return adaptor.createDiskFromTemplate(template, name, PhysicalDiskFormat.RAW, provisioningType, size, destPool, timeout);
} else if (template.getFormat() == PhysicalDiskFormat.DIR) {
return adaptor.createDiskFromTemplate(template, name,
PhysicalDiskFormat.DIR, provisioningType,
size, destPool, timeout);
return adaptor.createDiskFromTemplate(template, name, PhysicalDiskFormat.DIR, provisioningType, size, destPool, timeout);
} else {
PhysicalDiskFormat diskFormat = PhysicalDiskFormat.QCOW2;
if (provisioningType == StorageProvisioningType.RAW) {
Expand Down
Loading

0 comments on commit 3065a94

Please sign in to comment.