CS-9919: Support for Nexus Swiches (Cisco Vswitches)

Description:

	Adding api to remove from a service policy
	(policy map) from a port profile.
This commit is contained in:
Devdeep Singh 2012-05-11 15:33:11 +05:30 committed by Vijayendra Bhamidipati
parent ec19facd30
commit 8d1b9c2477
2 changed files with 34 additions and 8 deletions

View File

@ -135,7 +135,7 @@ public class NetconfHelper {
public void attachServicePolicy(String policyMap, String portProfile)
throws CloudRuntimeException {
String command = VsmCommand.getAttachServicePolicy(policyMap, portProfile);
String command = VsmCommand.getServicePolicy(policyMap, portProfile, true);
if (command != null) {
command = command.concat(SSH_NETCONF_TERMINATOR);
send(command);
@ -146,6 +146,19 @@ public class NetconfHelper {
}
}
public void detachServicePolicy(String policyMap, String portProfile)
throws CloudRuntimeException {
String command = VsmCommand.getServicePolicy(policyMap, portProfile, false);
if (command != null) {
command = command.concat(SSH_NETCONF_TERMINATOR);
send(command);
// parse the rpc reply.
parseReply(receive());
} else {
throw new CloudRuntimeException("Error generating rpc request for removing policy map.");
}
}
private void exchangeHello() {
String ack = receive();
String hello = VsmCommand.getHello() + SSH_NETCONF_TERMINATOR;

View File

@ -221,7 +221,7 @@ public class VsmCommand {
}
}
public static String getAttachServicePolicy(String policyMap, String portProfile) {
public static String getServicePolicy(String policyMap, String portProfile, boolean attach) {
try {
// Create the document and root element.
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
@ -241,7 +241,7 @@ public class VsmCommand {
// Command to create the port profile with the desired configuration.
Element config = doc.createElement("nf:config");
config.appendChild(attachServiceDetails(doc, policyMap, portProfile));
config.appendChild(serviceDetails(doc, policyMap, portProfile, attach));
editConfig.appendChild(config);
return serialize(domImpl, doc);
@ -511,7 +511,8 @@ public class VsmCommand {
return configure;
}
private static Element attachServiceDetails(Document doc, String policyMap, String portProfile) {
private static Element serviceDetails(Document doc, String policyMap,
String portProfile, boolean attach) {
// In mode, exec_configure.
Element configure = doc.createElementNS(s_ciscons, "nxos:configure");
Element modeConfigure = doc.createElement("nxos:" + s_configuremode);
@ -535,11 +536,23 @@ public class VsmCommand {
Element portProfMode = doc.createElement(s_portprofmode);
portDetails.appendChild(portProfMode);
// Associate the policy for input.
portProfMode.appendChild(getServicePolicyCmd(doc, policyMap, "input"));
// Associate/Remove the policy for input.
if (attach) {
portProfMode.appendChild(getServicePolicyCmd(doc, policyMap, "input"));
} else {
Element detach = doc.createElement("no");
portProfMode.appendChild(detach);
detach.appendChild(getServicePolicyCmd(doc, policyMap, "input"));
}
// Associate the policy for output.
portProfMode.appendChild(getServicePolicyCmd(doc, policyMap, "output"));
// Associate/Remove the policy for output.
if (attach) {
portProfMode.appendChild(getServicePolicyCmd(doc, policyMap, "output"));
} else {
Element detach = doc.createElement("no");
portProfMode.appendChild(detach);
detach.appendChild(getServicePolicyCmd(doc, policyMap, "output"));
}
// Persist the configuration across reboots.
modeConfigure.appendChild(persistConfiguration(doc));