|
38 | 38 |
|
39 | 39 | import javax.naming.ConfigurationException; |
40 | 40 |
|
| 41 | +import com.cloud.hypervisor.Hypervisor; |
41 | 42 | import org.apache.commons.io.FileUtils; |
42 | 43 | import org.apache.log4j.Logger; |
43 | 44 | import org.libvirt.Connect; |
@@ -955,8 +956,23 @@ protected synchronized String attachOrDetachDisk(Connect conn, boolean attach, S |
955 | 956 | } else { |
956 | 957 | diskdef = new DiskDef(); |
957 | 958 | if (attachingPool.getType() == StoragePoolType.RBD) { |
958 | | - diskdef.defNetworkBasedDisk(attachingDisk.getPath(), attachingPool.getSourceHost(), attachingPool.getSourcePort(), attachingPool.getAuthUserName(), |
959 | | - attachingPool.getUuid(), devId, DiskDef.diskBus.VIRTIO, diskProtocol.RBD, DiskDef.diskFmtType.RAW); |
| 959 | + if(resource.getHypervisorType() == Hypervisor.HypervisorType.LXC){ |
| 960 | + // For LXC, map image to host and then attach to Vm |
| 961 | + String mapRbd = Script.runSimpleBashScript("rbd map " + attachingDisk.getPath() + " --id "+attachingPool.getAuthUserName()); |
| 962 | + //Split pool and image details from disk path |
| 963 | + String[] splitPoolImage = attachingDisk.getPath().split("/"); |
| 964 | + //ToDo: rbd showmapped supports json and xml output. Use json/xml to get device |
| 965 | + String device = Script.runSimpleBashScript("rbd showmapped | grep \""+splitPoolImage[0]+" "+splitPoolImage[1]+"\" | cut -d \" \" -f10"); |
| 966 | + if (device != null) { |
| 967 | + s_logger.debug("RBD device on host is: "+device); |
| 968 | + diskdef.defBlockBasedDisk(device, devId, DiskDef.diskBus.VIRTIO); |
| 969 | + } else { |
| 970 | + throw new InternalErrorException("Error while mapping disk "+attachingDisk.getPath()+" on host"); |
| 971 | + } |
| 972 | + } else { |
| 973 | + diskdef.defNetworkBasedDisk(attachingDisk.getPath(), attachingPool.getSourceHost(), attachingPool.getSourcePort(), attachingPool.getAuthUserName(), |
| 974 | + attachingPool.getUuid(), devId, DiskDef.diskBus.VIRTIO, diskProtocol.RBD, DiskDef.diskFmtType.RAW); |
| 975 | + } |
960 | 976 | } else if (attachingPool.getType() == StoragePoolType.Gluster) { |
961 | 977 | String mountpoint = attachingPool.getLocalPath(); |
962 | 978 | String path = attachingDisk.getPath(); |
|
0 commit comments