GutoVeronezi commented on a change in pull request #4994:
URL: https://github.com/apache/cloudstack/pull/4994#discussion_r630184204
##########
File path:
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java
##########
@@ -0,0 +1,566 @@
+package com.cloud.hypervisor.kvm.storage;
+
+import com.linbit.linstor.api.ApiCallChecker;
+import com.linbit.linstor.api.ApiClient;
+import com.linbit.linstor.api.ApiException;
+import com.linbit.linstor.api.Configuration;
+import com.linbit.linstor.api.DevelopersApi;
+import com.linbit.linstor.api.model.ApiCallRc;
+import com.linbit.linstor.api.model.ApiCallRcList;
+import com.linbit.linstor.api.model.Properties;
+import com.linbit.linstor.api.model.ProviderKind;
+import com.linbit.linstor.api.model.Resource;
+import com.linbit.linstor.api.model.ResourceCreate;
+import com.linbit.linstor.api.model.ResourceDefinitionModify;
+import com.linbit.linstor.api.model.ResourceGroup;
+import com.linbit.linstor.api.model.ResourceGroupSpawn;
+import com.linbit.linstor.api.model.ResourceWithVolumes;
+import com.linbit.linstor.api.model.StoragePool;
+import com.linbit.linstor.api.model.VolumeDefinition;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.StringJoiner;
+
+import com.cloud.storage.Storage;
+import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.cloudstack.utils.qemu.QemuImg;
+import org.apache.cloudstack.utils.qemu.QemuImgException;
+import org.apache.cloudstack.utils.qemu.QemuImgFile;
+import org.apache.log4j.Logger;
+import org.libvirt.LibvirtException;
+
+@StorageAdaptorInfo(storagePoolType=Storage.StoragePoolType.Linstor)
+public class LinstorStorageAdaptor implements StorageAdaptor {
+ private static final Logger s_logger =
Logger.getLogger(LinstorStorageAdaptor.class);
+ private static final Map<String, KVMStoragePool>
MapStorageUuidToStoragePool = new HashMap<>();
+
+ private DevelopersApi getLinstorAPI(KVMStoragePool pool) {
+ ApiClient client = Configuration.getDefaultApiClient();
+ client.setBasePath(pool.getSourceHost());
+ return new DevelopersApi(client);
+ }
+
+ private String getLinstorRscName(String name) {
+ return "cs-" + name;
+ }
+
+ private String getHostname() {
+ // either there is already some function for that in the agent or a
better way.
+ ProcessBuilder pb = new ProcessBuilder("hostname");
+ try
+ {
+ String result;
+ Process p = pb.start();
+ final BufferedReader reader = new BufferedReader(new
InputStreamReader(p.getInputStream()));
+
+ StringJoiner sj = new
StringJoiner(System.getProperty("line.separator"));
+ reader.lines().iterator().forEachRemaining(sj::add);
+ result = sj.toString();
Review comment:
I did a little search and found a similar usage in `Agent.java`
https://github.com/apache/cloudstack/blob/6b9f3fb5015c29bbfaee0b08220174541ce40ab0/agent/src/main/java/com/cloud/agent/Agent.java#L475-L478
If we go deeper we may find another implementations.
I would suggest you to create an agent utility and implement a method to
retrieve the `hostname`, then use it instead of this whole method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]