Skip to content

Commit 8edaf63

Browse files
author
Frank.Zhang
committed
CLOUDSTACK-4850
[UCS] using template instead of cloning profile
1 parent 999c1bc commit 8edaf63

13 files changed

Lines changed: 588 additions & 80 deletions

File tree

api/src/com/cloud/event/EventTypes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,9 @@ public class EventTypes {
443443
public static final String EVENT_CLEANUP_VM_RESERVATION = "VM.RESERVATION.CLEANUP";
444444

445445
public static final String EVENT_UCS_ASSOCIATED_PROFILE = "UCS.ASSOCIATEPROFILE";
446+
public static final String EVENT_UCS_INSTANTIATE_TEMPLATE_AND_ASSOCIATE = "UCS.TEMPLATEASSOCIATION";
446447
public static final String EVENT_UCS_DISASSOCIATED_PROFILE = "UCS.DISASSOCIATEPROFILE";
448+
public static final String EVENT_UCS_REFRESH_BLADES = "UCS.REFRESHBLADES";
447449

448450
static {
449451

api/src/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,11 @@ public class ApiConstants {
493493
public static final String RESERVED_IP_RANGE = "reservediprange";
494494
public static final String UCS_MANAGER_ID = "ucsmanagerid";
495495
public static final String UCS_PROFILE_DN = "profiledn";
496+
public static final String UCS_TEMPLATE_DN = "templatedn";
496497
public static final String UCS_BLADE_DN = "bladedn";
497498
public static final String UCS_BLADE_ID = "bladeid";
499+
public static final String UCS_PROFILE_NAME = "profilename";
500+
public static final String UCS_DELETE_PROFILE = "deleteprofile";
498501
public static final String VM_GUEST_IP = "vmguestip";
499502
public static final String HEALTHCHECK_RESPONSE_TIMEOUT = "responsetimeout";
500503
public static final String HEALTHCHECK_INTERVAL_TIME = "intervaltime";

client/tomcatconf/commands.properties.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,12 @@ addUcsManager=1
616616
listUcsManagers=1
617617
listUcsProfiles=1
618618
listUcsBlades=1
619+
listUcsTemplates=1
619620
associateUcsProfileToBlade=1
620621
deleteUcsManager=1
621622
disassociateUcsProfileFromBlade=1
623+
refreshUcsBlades=1
624+
instantiateUcsTemplateAndAssocaciateToBlade=1
622625

623626
#### New Load Balancer commands
624627
createLoadBalancer=15

plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsCommands.java

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@ public static String listProfiles(String cookie) {
5050
return cmd.dump();
5151
}
5252

53+
public static String listTemplates(String cookie) {
54+
XmlObject cmd = new XmlObject("configResolveClass");
55+
cmd.putElement("cookie", cookie);
56+
cmd.putElement("inHierarchical", "false");
57+
cmd.putElement("classId", "lsServer");
58+
cmd.putElement("inFilter", new XmlObject("inFilter")
59+
.putElement("eq", new XmlObject("eq")
60+
.putElement("class", "lsServer").putElement("property", "type").putElement("value", "initial-template")));
61+
return cmd.dump();
62+
}
63+
64+
public static String instantiateTemplate(String cookie, String dn, String name) {
65+
XmlObject cmd = new XmlObject("lsInstantiateTemplate");
66+
cmd.putElement("dn",dn);
67+
cmd.putElement("cookie", cookie);
68+
cmd.putElement("inTargetOrg", "org-root");
69+
cmd.putElement("inServerName", name);
70+
cmd.putElement("inHierarchical", "no");
71+
return cmd.toString();
72+
}
73+
5374
public static String cloneProfile(String cookie, String srcDn, String newProfileName) {
5475
XmlObject cmd = new XmlObject("lsClone");
5576
cmd.putElement("cookie", cookie);
@@ -93,38 +114,38 @@ public static String deleteProfile(String cookie, String profileDn) {
93114
public static String associateProfileToBlade(String cookie, String profileDn, String bladeDn) {
94115
XmlObject cmd = new XmlObject("configConfMos").putElement("cookie", cookie).putElement("inHierarchical", "true").putElement(
95116
"inConfigs", new XmlObject("inConfigs").putElement(
96-
"pair", new XmlObject("pair").putElement("key", profileDn).putElement(
97-
"lsServer", new XmlObject("lsServer")
98-
.putElement("agentPolicyName", "")
99-
.putElement("biosProfileName", "")
100-
.putElement("bootPolicyName", "")
101-
.putElement("descr", "")
102-
.putElement("dn", profileDn)
103-
.putElement("dynamicConPolicyName", "")
104-
.putElement("extIPState", "none")
105-
.putElement("hostFwPolicyName", "")
106-
.putElement("identPoolName", "")
107-
.putElement("localDiskPolicyName", "")
108-
.putElement("maintPolicyName", "")
109-
.putElement("mgmtAccessPolicyName", "")
110-
.putElement("mgmtFwPolicyName", "")
111-
.putElement("powerPolicyName", "")
112-
.putElement("scrubPolicyName", "")
113-
.putElement("solPolicyName", "")
114-
.putElement("srcTemplName", "")
115-
.putElement("statsPolicyName", "default")
116-
.putElement("status", "")
117-
.putElement("usrLbl", "")
118-
.putElement("uuid", "")
119-
.putElement("vconProfileName", "")
120-
.putElement("lsBinding", new XmlObject("lsBinding")
121-
.putElement("pnDn", bladeDn)
122-
.putElement("restrictMigration", "no")
123-
.putElement("rn", "pn")
124-
)
125-
)
126-
)
127-
);
117+
"pair", new XmlObject("pair").putElement("key", profileDn).putElement(
118+
"lsServer", new XmlObject("lsServer")
119+
.putElement("agentPolicyName", "")
120+
.putElement("biosProfileName", "")
121+
.putElement("bootPolicyName", "")
122+
.putElement("descr", "")
123+
.putElement("dn", profileDn)
124+
.putElement("dynamicConPolicyName", "")
125+
.putElement("extIPState", "none")
126+
.putElement("hostFwPolicyName", "")
127+
.putElement("identPoolName", "")
128+
.putElement("localDiskPolicyName", "")
129+
.putElement("maintPolicyName", "")
130+
.putElement("mgmtAccessPolicyName", "")
131+
.putElement("mgmtFwPolicyName", "")
132+
.putElement("powerPolicyName", "")
133+
.putElement("scrubPolicyName", "")
134+
.putElement("solPolicyName", "")
135+
.putElement("srcTemplName", "")
136+
.putElement("statsPolicyName", "default")
137+
.putElement("status", "")
138+
.putElement("usrLbl", "")
139+
.putElement("uuid", "")
140+
.putElement("vconProfileName", "")
141+
.putElement("lsBinding", new XmlObject("lsBinding")
142+
.putElement("pnDn", bladeDn)
143+
.putElement("restrictMigration", "no")
144+
.putElement("rn", "pn")
145+
)
146+
)
147+
)
148+
);
128149

129150
return cmd.dump();
130151
}

plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsHttpClient.java

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,78 @@
1717
//
1818
package com.cloud.ucs.manager;
1919

20-
import org.apache.commons.httpclient.Header;
21-
import org.apache.commons.httpclient.HttpClient;
22-
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
23-
import org.apache.commons.httpclient.URI;
2420
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory;
2521
import org.apache.commons.httpclient.methods.PostMethod;
2622
import org.apache.commons.httpclient.methods.StringRequestEntity;
2723
import org.apache.commons.httpclient.protocol.Protocol;
2824

2925
import com.cloud.utils.exception.CloudRuntimeException;
26+
import org.apache.log4j.Logger;
27+
import org.springframework.http.*;
28+
import org.springframework.http.HttpMethod;
29+
import org.springframework.http.HttpStatus;
30+
import org.springframework.web.client.RestTemplate;
31+
32+
import java.net.URI;
33+
import java.net.URISyntaxException;
3034

3135
public class UcsHttpClient {
32-
private static HttpClient client;
36+
private static final Logger logger = Logger.getLogger(UcsHttpClient.class);
37+
//private static HttpClient client;
3338
private static Protocol ucsHttpsProtocol = new org.apache.commons.httpclient.protocol.Protocol("https", new EasySSLProtocolSocketFactory(), 443);
3439
private final String url;
40+
private static RestTemplate template;
3541

3642
static {
37-
client = new HttpClient();
43+
//client = new HttpClient();
44+
template = new RestTemplate();
3845
}
3946

4047
public UcsHttpClient(String ip) {
4148
url = String.format("http://%s/nuova", ip);
4249
Protocol.registerProtocol("https", ucsHttpsProtocol);
4350
}
4451

45-
public String call(String xml) {
52+
53+
private String call(URI uri, String body) {
54+
HttpHeaders requestHeaders = new HttpHeaders();
55+
requestHeaders.setContentType(MediaType.APPLICATION_XML);
56+
requestHeaders.setContentLength(body.length());
57+
HttpEntity<String> req = new HttpEntity<String>(body, requestHeaders);
58+
logger.debug(String.format("UCS call: %s", body));
59+
ResponseEntity<String> rsp = template.exchange(uri, HttpMethod.POST, req, String.class);
60+
if (rsp.getStatusCode() == org.springframework.http.HttpStatus.OK) {
61+
return rsp.getBody();
62+
} else if (rsp.getStatusCode().value() == 302) {
63+
// Handle HTTPS redirect
64+
// Ideal way might be to configure from add manager API
65+
// for using either HTTP / HTTPS
66+
// Allow only one level of redirect
67+
java.net.URI location = rsp.getHeaders().getLocation();
68+
if (location == null) {
69+
throw new CloudRuntimeException("Call failed: Bad redirect from UCS Manager");
70+
}
71+
call(location, body);
72+
}
73+
if (rsp.getStatusCode() != org.springframework.http.HttpStatus.OK) {
74+
String err = String.format("http status: %s, response body:%s", rsp.getStatusCode().toString(), rsp.getBody());
75+
throw new CloudRuntimeException(String.format("UCS API call failed, details: %s\n", err));
76+
}
77+
78+
if (rsp.getBody().contains("errorCode")) {
79+
String err = String.format("ucs call failed:\nsubmitted doc:%s\nresponse:%s\n", body, rsp.getBody());
80+
throw new CloudRuntimeException(err);
81+
}
82+
return rsp.getBody();
83+
}
84+
85+
public String call(String body) {
86+
try {
87+
return call(new URI(url), body);
88+
} catch (URISyntaxException e) {
89+
throw new CloudRuntimeException(e);
90+
}
91+
/*
4692
PostMethod post = new PostMethod(url);
4793
post.setRequestEntity(new StringRequestEntity(xml));
4894
post.setRequestHeader("Content-type", "text/xml");
@@ -80,5 +126,6 @@ public String call(String xml) {
80126
} finally {
81127
post.releaseConnection();
82128
}
129+
*/
83130
}
84131
}

plugins/hypervisors/ucs/src/com/cloud/ucs/manager/UcsManager.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,8 @@
1717
//
1818
package com.cloud.ucs.manager;
1919

20-
import org.apache.cloudstack.api.AddUcsManagerCmd;
21-
import org.apache.cloudstack.api.AssociateUcsProfileToBladeCmd;
22-
import org.apache.cloudstack.api.ListUcsBladeCmd;
23-
import org.apache.cloudstack.api.ListUcsManagerCmd;
24-
import org.apache.cloudstack.api.ListUcsProfileCmd;
25-
import org.apache.cloudstack.api.response.ListResponse;
26-
import org.apache.cloudstack.api.response.UcsBladeResponse;
27-
import org.apache.cloudstack.api.response.UcsManagerResponse;
28-
import org.apache.cloudstack.api.response.UcsProfileResponse;
20+
import org.apache.cloudstack.api.*;
21+
import org.apache.cloudstack.api.response.*;
2922

3023
import com.cloud.utils.component.Manager;
3124
import com.cloud.utils.component.PluggableService;
@@ -35,13 +28,19 @@ public interface UcsManager extends Manager, PluggableService {
3528

3629
ListResponse<UcsProfileResponse> listUcsProfiles(ListUcsProfileCmd cmd);
3730

31+
ListResponse<UcsTemplateResponse> listUcsTemplates(ListUcsTemplatesCmd cmd);
32+
3833
ListResponse<UcsManagerResponse> listUcsManager(ListUcsManagerCmd cmd);
3934

4035
UcsBladeResponse associateProfileToBlade(AssociateUcsProfileToBladeCmd cmd);
4136

37+
UcsBladeResponse instantiateTemplateAndAssociateToBlade(InstantiateUcsTemplateAndAssociateToBladeCmd cmd);
38+
4239
ListResponse<UcsBladeResponse> listUcsBlades(ListUcsBladeCmd cmd);
4340

4441
void deleteUcsManager(Long id);
4542

46-
UcsBladeResponse disassociateProfile(Long bladeId);
43+
ListResponse<UcsBladeResponse> refreshBlades(Long mgrId);
44+
45+
UcsBladeResponse disassociateProfile(DisassociateUcsProfileCmd cmd);
4746
}

0 commit comments

Comments
 (0)