Skip to content

Commit ef6038f

Browse files
author
Frank.Zhang
committed
commit 8edaf63
Author: Frank.Zhang <frank.zhang@citrix.com> Date: Thu Oct 10 14:45:03 2013 -0700 CLOUDSTACK-4850 [UCS] using template instead of cloning profile
1 parent 3b59dfe commit ef6038f

11 files changed

Lines changed: 393 additions & 125 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ public class EventTypes {
452452
public static final String EVENT_CLEANUP_VM_RESERVATION = "VM.RESERVATION.CLEANUP";
453453

454454
public static final String EVENT_UCS_ASSOCIATED_PROFILE = "UCS.ASSOCIATEPROFILE";
455+
public static final String EVENT_UCS_INSTANTIATE_TEMPLATE_AND_ASSOCIATE = "UCS.TEMPLATEASSOCIATION";
456+
public static final String EVENT_UCS_DISASSOCIATED_PROFILE = "UCS.DISASSOCIATEPROFILE";
457+
public static final String EVENT_UCS_REFRESH_BLADES = "UCS.REFRESHBLADES";
455458

456459
// Object store migration
457460
public static final String EVENT_MIGRATE_PREPARE_SECONDARY_STORAGE = "MIGRATE.PREPARE.SS";

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,11 @@ public class ApiConstants {
506506
public static final String RESERVED_IP_RANGE = "reservediprange";
507507
public static final String UCS_MANAGER_ID = "ucsmanagerid";
508508
public static final String UCS_PROFILE_DN = "profiledn";
509+
public static final String UCS_TEMPLATE_DN = "templatedn";
509510
public static final String UCS_BLADE_DN = "bladedn";
510511
public static final String UCS_BLADE_ID = "bladeid";
512+
public static final String UCS_PROFILE_NAME = "profilename";
513+
public static final String UCS_DELETE_PROFILE = "deleteprofile";
511514
public static final String VM_GUEST_IP = "vmguestip";
512515
public static final String HEALTHCHECK_RESPONSE_TIMEOUT = "responsetimeout";
513516
public static final String HEALTHCHECK_INTERVAL_TIME = "intervaltime";

‎client/tomcatconf/commands.properties.in‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,12 @@ addUcsManager=1
637637
listUcsManagers=1
638638
listUcsProfiles=1
639639
listUcsBlades=1
640+
listUcsTemplates=1
640641
associateUcsProfileToBlade=1
641642
deleteUcsManager=1
643+
disassociateUcsProfileFromBlade=1
644+
refreshUcsBlades=1
645+
instantiateUcsTemplateAndAssocaciateToBlade=1
642646

643647
#### New Load Balancer commands
644648
createLoadBalancer=15

‎plugins/hypervisors/ucs/pom.xml‎

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,47 @@
1-
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
2-
license agreements. See the NOTICE file distributed with this work for additional
3-
information regarding copyright ownership. The ASF licenses this file to you under
4-
the Apache License, Version 2.0 (the "License"); you may not use this file except
5-
in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6-
Unless required by applicable law or agreed to in writing, software distributed under
7-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
8-
OF ANY KIND, either express or implied. See the License for the specific language
9-
governing permissions and limitations under the License. -->
10-
<project
11-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
1220
http://maven.apache.org/xsd/maven-4.0.0.xsd"
13-
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
21+
xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1423
<modelVersion>4.0.0</modelVersion>
1524
<parent>
1625
<groupId>org.apache.cloudstack</groupId>
1726
<artifactId>cloudstack-plugins</artifactId>
1827
<version>4.3.0-SNAPSHOT</version>
1928
<relativePath>../../pom.xml</relativePath>
2029
</parent>
30+
<groupId>org.apache.cloudstack</groupId>
2131
<artifactId>cloud-plugin-hypervisor-ucs</artifactId>
32+
<version>4.3.0-SNAPSHOT</version>
2233
<name>Apache CloudStack Plugin - Hypervisor UCS</name>
2334
<url>http://maven.apache.org</url>
2435
<properties>
2536
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2637
</properties>
2738
<dependencies>
39+
<dependency>
40+
<groupId>junit</groupId>
41+
<artifactId>junit</artifactId>
42+
<version>3.8.1</version>
43+
<scope>test</scope>
44+
</dependency>
2845
<dependency>
2946
<groupId>org.apache.cloudstack</groupId>
3047
<artifactId>cloud-utils</artifactId>
@@ -35,5 +52,10 @@
3552
<artifactId>cloud-api</artifactId>
3653
<version>${project.version}</version>
3754
</dependency>
55+
<dependency>
56+
<groupId>javax.inject</groupId>
57+
<artifactId>javax.inject</artifactId>
58+
<version>1</version>
59+
</dependency>
3860
</dependencies>
3961
</project>

‎plugins/hypervisors/ucs/src/com/cloud/ucs/database/UcsBladeDaoImpl.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import javax.ejb.Local;
2121

22+
import org.springframework.stereotype.Component;
23+
2224
import com.cloud.utils.db.DB;
2325
import com.cloud.utils.db.GenericDaoBase;
2426
@Local(value = { UcsBladeDao.class })

‎plugins/hypervisors/ucs/src/com/cloud/ucs/database/UcsManagerDao.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.cloud.utils.db.GenericSearchBuilder;
2828
import com.cloud.utils.db.SearchBuilder;
2929
import com.cloud.utils.db.SearchCriteria;
30-
import com.cloud.utils.db.GenericQueryBuilder;
3130

3231
public interface UcsManagerDao extends GenericDao<UcsManagerVO, Long> {
3332
}

‎plugins/hypervisors/ucs/src/com/cloud/ucs/database/UcsManagerDaoImpl.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import javax.ejb.Local;
2121

22+
import org.springframework.stereotype.Component;
23+
2224
import com.cloud.utils.db.DB;
2325
import com.cloud.utils.db.GenericDaoBase;
2426

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

Lines changed: 76 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);
@@ -67,41 +88,64 @@ public static String configResolveDn(String cookie, String dn) {
6788
return cmd.toString();
6889
}
6990

91+
public static String disassociateProfileFromBlade(String cookie, String profileDn) {
92+
XmlObject cmd = new XmlObject("configConfMo");
93+
cmd.putElement("cookie", cookie);
94+
cmd.putElement("inHierarchical", "false")
95+
.putElement("inConfig", new XmlObject("inConfig")
96+
.putElement("lsServer", new XmlObject("lsServer")
97+
.putElement("dn", profileDn).putElement("lsBinding", new XmlObject("lsBinding").putElement("rn", "pn").putElement("status", "deleted"))
98+
)
99+
);
100+
101+
return cmd.dump();
102+
}
103+
104+
public static String deleteProfile(String cookie, String profileDn) {
105+
XmlObject cmd = new XmlObject("configConfMos");
106+
cmd.putElement("cookie", cookie);
107+
cmd.putElement("inHierarchical", "true")
108+
.putElement("inConfigs", new XmlObject("inConfigs").putElement("pair", new XmlObject("pair").putElement("key", profileDn)
109+
.putElement("lsServer", new XmlObject("lsServer").putElement("dn", profileDn).putElement("status", "deleted"))
110+
));
111+
return cmd.dump();
112+
}
113+
70114
public static String associateProfileToBlade(String cookie, String profileDn, String bladeDn) {
71115
XmlObject cmd = new XmlObject("configConfMos").putElement("cookie", cookie).putElement("inHierarchical", "true").putElement(
72116
"inConfigs", new XmlObject("inConfigs").putElement(
73-
"pair", new XmlObject("pair").putElement("key", profileDn).putElement(
74-
"lsServer", new XmlObject("lsServer")
75-
.putElement("agentPolicyName", "")
76-
.putElement("biosProfileName", "")
77-
.putElement("bootPolicyName", "")
78-
.putElement("descr", "")
79-
.putElement("dn", profileDn)
80-
.putElement("dynamicConPolicyName", "")
81-
.putElement("extIPState", "none")
82-
.putElement("hostFwPolicyName", "")
83-
.putElement("identPoolName", "")
84-
.putElement("localDiskPolicyName", "")
85-
.putElement("maintPolicyName", "")
86-
.putElement("mgmtAccessPolicyName", "")
87-
.putElement("mgmtFwPolicyName", "")
88-
.putElement("powerPolicyName", "")
89-
.putElement("scrubPolicyName", "")
90-
.putElement("solPolicyName", "")
91-
.putElement("srcTemplName", "")
92-
.putElement("statsPolicyName", "default")
93-
.putElement("status", "")
94-
.putElement("usrLbl", "")
95-
.putElement("uuid", "")
96-
.putElement("vconProfileName", "")
97-
.putElement("lsBinding", new XmlObject("lsBinding")
98-
.putElement("pnDn", bladeDn)
99-
.putElement("restrictMigration", "no")
100-
.putElement("rn", "pn")
101-
)
102-
)
103-
)
104-
);
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+
);
105149

106150
return cmd.dump();
107151
}

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

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,76 @@
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.URI;
20+
import com.cloud.utils.exception.CloudRuntimeException;
2321
import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory;
24-
import org.apache.commons.httpclient.methods.PostMethod;
25-
import org.apache.commons.httpclient.methods.StringRequestEntity;
2622
import org.apache.commons.httpclient.protocol.Protocol;
23+
import org.apache.log4j.Logger;
24+
import org.springframework.http.*;
25+
import org.springframework.web.client.RestTemplate;
2726

28-
import com.cloud.utils.exception.CloudRuntimeException;
27+
import java.net.URI;
28+
import java.net.URISyntaxException;
2929

3030
public class UcsHttpClient {
31-
private static HttpClient client = new HttpClient();
31+
private static final Logger logger = Logger.getLogger(UcsHttpClient.class);
32+
//private static HttpClient client;
3233
private static Protocol ucsHttpsProtocol = new org.apache.commons.httpclient.protocol.Protocol("https", new EasySSLProtocolSocketFactory(), 443);
3334
private final String url;
35+
private static RestTemplate template;
36+
37+
static {
38+
//client = new HttpClient();
39+
template = new RestTemplate();
40+
}
3441

3542
public UcsHttpClient(String ip) {
3643
url = String.format("http://%s/nuova", ip);
3744
Protocol.registerProtocol("https", ucsHttpsProtocol);
3845
}
3946

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

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

Lines changed: 10 additions & 9 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,11 +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);
42+
43+
ListResponse<UcsBladeResponse> refreshBlades(Long mgrId);
44+
45+
UcsBladeResponse disassociateProfile(DisassociateUcsProfileCmd cmd);
4546
}

0 commit comments

Comments
 (0)