|
18 | 18 | */ |
19 | 19 | package org.apache.cloudstack.storage.volume.datastore; |
20 | 20 |
|
| 21 | +import java.io.UnsupportedEncodingException; |
| 22 | +import java.net.URLEncoder; |
21 | 23 | import java.util.List; |
22 | 24 | import java.util.Map; |
23 | 25 |
|
|
36 | 38 | import com.cloud.capacity.Capacity; |
37 | 39 | import com.cloud.capacity.CapacityVO; |
38 | 40 | import com.cloud.capacity.dao.CapacityDao; |
| 41 | +import com.cloud.exception.InvalidParameterValueException; |
39 | 42 | import com.cloud.storage.DataStoreRole; |
40 | 43 | import com.cloud.storage.ScopeType; |
41 | 44 | import com.cloud.hypervisor.Hypervisor.HypervisorType; |
42 | 45 | import com.cloud.storage.StorageManager; |
43 | 46 | import com.cloud.storage.StoragePoolHostVO; |
44 | 47 | import com.cloud.storage.StoragePoolStatus; |
| 48 | +import com.cloud.storage.Storage.StoragePoolType; |
45 | 49 | import com.cloud.storage.dao.StoragePoolHostDao; |
| 50 | +import com.cloud.utils.UriUtils; |
| 51 | +import com.cloud.utils.crypt.DBEncryptionUtil; |
46 | 52 | import com.cloud.utils.db.TransactionLegacy; |
47 | 53 | import com.cloud.utils.exception.CloudRuntimeException; |
48 | 54 |
|
@@ -86,6 +92,29 @@ public DataStore createPrimaryDataStore(PrimaryDataStoreParameters params) { |
86 | 92 | dataStoreVO.setHypervisor(params.getHypervisorType()); |
87 | 93 |
|
88 | 94 | Map<String, String> details = params.getDetails(); |
| 95 | + if (params.getType() == StoragePoolType.SMB && details != null) { |
| 96 | + String user = details.get("user"); |
| 97 | + String password = details.get("password"); |
| 98 | + String domain = details.get("domain"); |
| 99 | + String updatedPath = params.getPath(); |
| 100 | + |
| 101 | + if (user == null || password == null) { |
| 102 | + String errMsg = "Missing cifs user and password details. Add them as details parameter."; |
| 103 | + s_logger.warn(errMsg); |
| 104 | + throw new InvalidParameterValueException(errMsg); |
| 105 | + } else { |
| 106 | + try { |
| 107 | + password = DBEncryptionUtil.encrypt(URLEncoder.encode(password, "UTF-8")); |
| 108 | + details.put("password", password); |
| 109 | + updatedPath += "?user=" + user + "&password=" + password + "&domain=" + domain; |
| 110 | + } catch (UnsupportedEncodingException e) { |
| 111 | + throw new CloudRuntimeException("Error while generating the cifs url. " + e.getMessage()); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + dataStoreVO.setPath(updatedPath); |
| 116 | + } |
| 117 | + |
89 | 118 | String tags = params.getTags(); |
90 | 119 | if (tags != null) { |
91 | 120 | String[] tokens = tags.split(","); |
|
0 commit comments