mirror of https://github.com/apache/cloudstack.git
Added helper method to create port profile in n1kv VSM with additional parameters VDC tenant and edge security profile
Added helper method to create a vservice node in n1kv VSM
This commit is contained in:
parent
db42da17e9
commit
d6cdfe35f8
|
|
@ -79,6 +79,17 @@ public class NetconfHelper {
|
|||
parseOkReply(receive());
|
||||
}
|
||||
|
||||
public void addPortProfile(String name, PortProfileType type, BindingType binding,
|
||||
SwitchPortMode mode, int vlanid, String vdc, String espName) throws CloudRuntimeException {
|
||||
String command = VsmCommand.getAddPortProfile(name, type, binding, mode, vlanid, vdc, espName);
|
||||
if (command != null) {
|
||||
command = command.concat(SSH_NETCONF_TERMINATOR);
|
||||
parseOkReply(sendAndReceive(command));
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error generating rpc request for adding port profile.");
|
||||
}
|
||||
}
|
||||
|
||||
public void addPortProfile(String name, PortProfileType type, BindingType binding,
|
||||
SwitchPortMode mode, int vlanid) throws CloudRuntimeException {
|
||||
String command = VsmCommand.getAddPortProfile(name, type, binding, mode, vlanid);
|
||||
|
|
@ -160,6 +171,17 @@ public class NetconfHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void addVServiceNode(String vlanId, String ipAddr)
|
||||
throws CloudRuntimeException {
|
||||
String command = VsmCommand.getVServiceNode(vlanId, ipAddr);
|
||||
if (command != null) {
|
||||
command = command.concat(SSH_NETCONF_TERMINATOR);
|
||||
parseOkReply(sendAndReceive(command));
|
||||
} else {
|
||||
throw new CloudRuntimeException("Error generating rpc request for adding vservice node for vlan " + vlanId);
|
||||
}
|
||||
}
|
||||
|
||||
public PortProfile getPortProfileByName(String name) throws CloudRuntimeException {
|
||||
String command = VsmCommand.getPortProfile(name);
|
||||
if (command != null) {
|
||||
|
|
|
|||
|
|
@ -69,6 +69,40 @@ public class VsmCommand {
|
|||
removevlanid
|
||||
}
|
||||
|
||||
public static String getAddPortProfile(String name, PortProfileType type,
|
||||
BindingType binding, SwitchPortMode mode, int vlanid, String vdc, String espName) {
|
||||
try {
|
||||
// Create the document and root element.
|
||||
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||
DOMImplementation domImpl = docBuilder.getDOMImplementation();
|
||||
Document doc = createDocument(domImpl);
|
||||
|
||||
// Edit configuration command.
|
||||
Element editConfig = doc.createElement("nf:edit-config");
|
||||
doc.getDocumentElement().appendChild(editConfig);
|
||||
|
||||
// Command to get into exec configure mode.
|
||||
Element target = doc.createElement("nf:target");
|
||||
Element running = doc.createElement("nf:running");
|
||||
target.appendChild(running);
|
||||
editConfig.appendChild(target);
|
||||
|
||||
// Command to create the port profile with the desired configuration.
|
||||
Element config = doc.createElement("nf:config");
|
||||
config.appendChild(configPortProfileDetails(doc, name, type, binding, mode, vlanid, vdc, espName));
|
||||
editConfig.appendChild(config);
|
||||
|
||||
return serialize(domImpl, doc);
|
||||
} catch (ParserConfigurationException e) {
|
||||
s_logger.error("Error while creating add port profile message : " + e.getMessage());
|
||||
return null;
|
||||
} catch (DOMException e) {
|
||||
s_logger.error("Error while creating add port profile message : " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getAddPortProfile(String name, PortProfileType type,
|
||||
BindingType binding, SwitchPortMode mode, int vlanid) {
|
||||
try {
|
||||
|
|
@ -366,8 +400,86 @@ public class VsmCommand {
|
|||
}
|
||||
}
|
||||
|
||||
public static String getVServiceNode(String vlanId, String ipAddr) {
|
||||
try {
|
||||
// Create the document and root element.
|
||||
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
|
||||
DOMImplementation domImpl = docBuilder.getDOMImplementation();
|
||||
Document doc = createDocument(domImpl);
|
||||
|
||||
// Edit configuration command.
|
||||
Element editConfig = doc.createElement("nf:edit-config");
|
||||
doc.getDocumentElement().appendChild(editConfig);
|
||||
|
||||
// Command to get into exec configure mode.
|
||||
Element target = doc.createElement("nf:target");
|
||||
Element running = doc.createElement("nf:running");
|
||||
target.appendChild(running);
|
||||
editConfig.appendChild(target);
|
||||
|
||||
// Command to create the port profile with the desired configuration.
|
||||
Element config = doc.createElement("nf:config");
|
||||
config.appendChild(configVServiceNodeDetails(doc, vlanId, ipAddr));
|
||||
editConfig.appendChild(config);
|
||||
|
||||
return serialize(domImpl, doc);
|
||||
} catch (ParserConfigurationException e) {
|
||||
s_logger.error("Error while adding vservice node for vlan " + vlanId + ", " + e.getMessage());
|
||||
return null;
|
||||
} catch (DOMException e) {
|
||||
s_logger.error("Error while adding vservice node for vlan " + vlanId + ", " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Element configVServiceNodeDetails(Document doc, String vlanId, String ipAddr) {
|
||||
// In mode, exec_configure.
|
||||
Element configure = doc.createElementNS(s_ciscons, "nxos:configure");
|
||||
Element modeConfigure = doc.createElement("nxos:" + s_configuremode);
|
||||
configure.appendChild(modeConfigure);
|
||||
|
||||
// vservice node %name% type asa
|
||||
Element vservice = doc.createElement("vservice");
|
||||
vservice.appendChild(doc.createElement("node"))
|
||||
.appendChild(doc.createElement("ASA_" + vlanId))
|
||||
.appendChild(doc.createElement("type"))
|
||||
.appendChild(doc.createElement("asa"));
|
||||
modeConfigure.appendChild(vservice);
|
||||
|
||||
Element address = doc.createElement(s_paramvalue);
|
||||
address.setAttribute("isKey", "true");
|
||||
address.setTextContent(ipAddr);
|
||||
|
||||
// ip address %ipAddr%
|
||||
modeConfigure.appendChild(doc.createElement("ip"))
|
||||
.appendChild(doc.createElement("address"))
|
||||
.appendChild(doc.createElement("value"))
|
||||
.appendChild(address);
|
||||
|
||||
Element vlan = doc.createElement(s_paramvalue);
|
||||
vlan.setAttribute("isKey", "true");
|
||||
vlan.setTextContent(vlanId);
|
||||
|
||||
// adjacency l2 vlan %vlanId%
|
||||
modeConfigure.appendChild(doc.createElement("adjacency"))
|
||||
.appendChild(doc.createElement("l2"))
|
||||
.appendChild(doc.createElement("vlan"))
|
||||
.appendChild(doc.createElement("value"))
|
||||
.appendChild(vlan);
|
||||
|
||||
// fail-mode close
|
||||
modeConfigure.appendChild(doc.createElement("fail-mode"))
|
||||
.appendChild(doc.createElement("close"));
|
||||
|
||||
// Persist the configuration across reboots.
|
||||
modeConfigure.appendChild(persistConfiguration(doc));
|
||||
|
||||
return configure;
|
||||
}
|
||||
|
||||
private static Element configPortProfileDetails(Document doc, String name, PortProfileType type,
|
||||
BindingType binding, SwitchPortMode mode, int vlanid, String VDC, String espName) {
|
||||
BindingType binding, SwitchPortMode mode, int vlanid, String vdc, String espName) {
|
||||
|
||||
// In mode, exec_configure.
|
||||
Element configure = doc.createElementNS(s_ciscons, "nxos:configure");
|
||||
|
|
@ -433,21 +545,19 @@ public class VsmCommand {
|
|||
Element portgroup = doc.createElement("port-group");
|
||||
vmware.appendChild(portgroup);
|
||||
portProf.appendChild(vmware);
|
||||
|
||||
//org root/TestTenant1/TestVDC
|
||||
//vservice node <Node Name> profile <Edge Security Profile Name in VNMC>
|
||||
|
||||
// org root/%vdc%
|
||||
// vservice node <Node Name> profile <Edge Security Profile Name in VNMC>
|
||||
Element org = doc.createElement("org");
|
||||
Element vdc = doc.createElement(VDC);
|
||||
org.appendChild(vdc);
|
||||
org.appendChild(doc.createElement(vdc));
|
||||
portProf.appendChild(org);
|
||||
|
||||
|
||||
String asaNodeName = "ASA_" + vlanid;
|
||||
Element vservice = doc.createElement("vservice");
|
||||
vservice.appendChild(doc.createElement("node"))
|
||||
.appendChild(doc.createElement(asaNodeName))
|
||||
.appendChild(doc.createElement("profile"))
|
||||
.appendChild(doc.createElement(espName));
|
||||
|
||||
portProf.appendChild(vservice);
|
||||
|
||||
// no shutdown.
|
||||
|
|
|
|||
Loading…
Reference in New Issue