WIP : dhcp server policy

Signed-off-by: Chiradeep Vittal <chiradeep@apache.org>
This commit is contained in:
Chiradeep Vittal 2013-01-16 15:30:24 -08:00
parent 446a9b8491
commit e32295e8cf
4 changed files with 52 additions and 17 deletions

View File

@ -0,0 +1,14 @@
<configConfMos
cookie="%cookie%"
inHierarchical="false">
<inConfigs>
<pair key="%dhcpdn%" >
<policyDhcpPolicyAssoc
dn="%dhcpdn%"
interfaceName="%insideintf%"
policyRef="%dhcpserverpolicyname%"
status="modified"
type="server"/>
</pair>
</inConfigs>
</configConfMos>

View File

@ -4,9 +4,6 @@
<inConfigs>
<pair key="%dhcpserverdn%">
<policyDhcpServerPolicy
adminState="enabled"
autoConfigIfName=""
descr="%dhcpserverdescr%"
dn="%dhcpserverdn%"
dnsDomainRef=""
@ -18,7 +15,6 @@
<pair key="%iprangedn%" >
<policyIPAddressRange
descr=""
dn="%iprangedn%"
endip="%endip%"
name="iprange"
@ -29,25 +25,18 @@
<pair key="%dnsservicedn%">
<commDns
adminState="enabled"
descr=""
dn="%dnsservicedn%"
domain="%domain%"
name="%dnsservicename%"
port="0"
proto="none"
status="created"/>
</pair>
<pair key="%nameserverdn%">
<commDnsProvider
adminState="enabled"
descr=""
dn="%nameserverdn%"
hostip="%nameserverip%"
hostname=""
intfName=""
name=""
order="100"
status="created"/>
</pair>
@ -57,6 +46,7 @@
<!--"org-root/org-TestTenant3/org-Tenant3-VDC/dhcp-server-Tenant3-DHCP-Policy"
"org-root/org-TestTenant3/org-Tenant3-VDC/dhcp-server-Tenant3-DHCP-Policy/ip-range-iprange"
org-root/org-TenantC/org-VDC-TenantC/dhcp-server-TenantC-Dhcp-Policy/ip-range-iprange
"org-root/org-TestTenant3/org-Tenant3-VDC/dhcp-server-Tenant3-DHCP-Policy/dns-svc-Tenant3-DNS"
"org-root/org-TestTenant3/org-Tenant3-VDC/dhcp-server-Tenant3-DHCP-Policy/dns-svc-Tenant3-DNS/dns-8.8.8.8"
--!>

View File

@ -88,10 +88,8 @@ public class CiscoVnmcResource implements ServerResource {
CREATE_EDGE_ROUTE("create-edge-device-route.xml", "policy-mgr"),
RESOLVE_EDGE_ROUTE_POLICY("associate-route-policy.xml", "policy-mgr"),
RESOLVE_EDGE_DHCP_POLICY("associate-dhcp-policy.xml", "policy-mgr"),
CREATE_DHCP_POLICY("create-dhcp-policy.xml", "policy-mgr");
CREATE_DHCP_POLICY("create-dhcp-policy.xml", "policy-mgr"),
RESOLVE_EDGE_DHCP_SERVER_POLICY("associate-dhcp-server.xml", "policy-mgr");
private String scriptsDir = "scripts/network/cisco";
private String xml;
@ -565,7 +563,7 @@ public class CiscoVnmcResource implements ServerResource {
xml = replaceXmlValue(xml, "cookie", _cookie);
xml = replaceXmlValue(xml, "dhcpserverdn", getDnForDhcpServerPolicy(tenantName));
xml = replaceXmlValue(xml, "dhcpserverdescr", "DHCP server for " + tenantName);
xml = replaceXmlValue(xml, "dhcpservername", getNameForDhcpServer(tenantName));
xml = replaceXmlValue(xml, "dhcpservername", getNameForDhcpPolicy(tenantName));
xml = replaceXmlValue(xml, "iprangedn", getDnForDhcpIpRange(tenantName));
xml = replaceXmlValue(xml, "startip", startIp);
xml = replaceXmlValue(xml, "endip", endIp);
@ -589,6 +587,28 @@ public class CiscoVnmcResource implements ServerResource {
}
return true;
}
public boolean associateTenantVDCEdgeDhcpServerPolicy(String tenantName, String intfName) throws ExecutionException {
String xml = VnmcXml.RESOLVE_EDGE_DHCP_SERVER_POLICY.getXml();
String service = VnmcXml.RESOLVE_EDGE_DHCP_SERVER_POLICY.getService();
xml = replaceXmlValue(xml, "cookie", _cookie);
xml = replaceXmlValue(xml, "dhcpdn", getDnForDhcpPolicy(tenantName, intfName));
xml = replaceXmlValue(xml, "insideintf", intfName);
xml = replaceXmlValue(xml, "dhcpserverpolicyname", getNameForDhcpServer(tenantName));
String response = sendRequest(service, xml);
Map<String, String> checked = checkResponse(response, "errorCode", "response");
if (checked.get("errorCode") != null) {
String errorCode = checked.get("errorCode");
if (errorCode.equals("103")) {
//already exists
return true;
}
return false;
}
return true;
}
private String sendRequest(String service, String xmlRequest) throws ExecutionException {
org.apache.commons.httpclient.protocol.Protocol myhttps =

View File

@ -28,7 +28,7 @@ import com.cloud.utils.exception.ExecutionException;
public class CiscoVnmcResourceTest {
static CiscoVnmcResource resource;
static String tenantName = "TenantD";
static String tenantName = "TenantE";
@BeforeClass
public static void setUpClass() throws Exception {
resource = new CiscoVnmcResource("10.223.56.5", "admin", "C1sco123");
@ -146,4 +146,15 @@ public class CiscoVnmcResourceTest {
e.printStackTrace();
}
}
@Test
public void testAssociateTenantVDCEdgeDhcpServerPolicy() {
try {
boolean response = resource.associateTenantVDCEdgeDhcpServerPolicy(tenantName, "Edge_Inside");
assertTrue(response);
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}