use of com.cloud.utils.xmlobject.XmlObject in project cloudstack by apache.
the class Force10BaremetalSwitchBackend method removePortFromVlan.
@Override
public void removePortFromVlan(BaremetalVlanStruct struct) {
String link = buildLink(struct.getSwitchIp(), String.format("/api/running/ftos/interface/vlan/%s", struct.getVlan()));
HttpHeaders headers = createBasicAuthenticationHeader(struct);
HttpEntity<String> request = new HttpEntity<>(headers);
logger.debug(String.format("http get: %s, body: %s", link, request));
ResponseEntity rsp = rest.exchange(link, HttpMethod.GET, request, String.class);
if (rsp.getStatusCode() == HttpStatus.NOT_FOUND) {
logger.debug(String.format("vlan[%s] has been deleted on force10[ip:%s], no need to remove the port[%s] anymore", struct.getVlan(), struct.getSwitchIp(), struct.getPort()));
} else if (rsp.getStatusCode() == HttpStatus.OK) {
PortInfo port = new PortInfo(struct);
XmlObject xml = XmlObjectParser.parseFromString((String) rsp.getBody());
List<XmlObject> ports = xml.getAsList("untagged.tengigabitethernet");
ports.addAll(xml.<XmlObject>getAsList("untagged.gigabitethernet"));
ports.addAll(xml.<XmlObject>getAsList("untagged.fortyGigE"));
List<XmlObject> newPorts = new ArrayList<>();
boolean needRemove = false;
for (XmlObject pxml : ports) {
XmlObject name = pxml.get("name");
if (port.port.equals(name.getText())) {
needRemove = true;
continue;
}
newPorts.add(pxml);
}
if (!needRemove) {
return;
}
xml.setText(null);
xml.removeElement("mtu");
XmlObject tagged = xml.get("untagged");
tagged.removeAllChildren();
for (XmlObject p : newPorts) {
tagged.putElement(p.getTag(), p);
}
request = new HttpEntity<>(xml.dump(), headers);
logger.debug(String.format("http get: %s, body: %s", link, request));
rsp = rest.exchange(link, HttpMethod.PUT, request, String.class);
if (!successHttpStatusCode.contains(rsp.getStatusCode())) {
throw new CloudRuntimeException(String.format("failed to program vlan[%s] for port[%s] on force10[ip:%s]. http status:%s, body dump:%s", struct.getVlan(), struct.getPort(), struct.getSwitchIp(), rsp.getStatusCode(), rsp.getBody()));
} else {
logger.debug(String.format("removed port[%s] from vlan[%s] on force10[ip:%s]", struct.getPort(), struct.getVlan(), struct.getSwitchIp()));
}
} else {
throw new CloudRuntimeException(String.format("force10[ip:%s] returns unexpected error[%s] when http getting %s, body dump:%s", struct.getSwitchIp(), rsp.getStatusCode(), link, rsp.getBody()));
}
}
use of com.cloud.utils.xmlobject.XmlObject in project cloudstack by apache.
the class UcsCommands method refreshCmd.
public static String refreshCmd(String username, String password, String cookie) {
XmlObject cmd = new XmlObject("aaaRefresh");
cmd.putElement("inName", username);
cmd.putElement("inPassword", password);
cmd.putElement("inCookie", cookie);
return cmd.dump();
}
use of com.cloud.utils.xmlobject.XmlObject in project cloudstack by apache.
the class UcsCommands method listComputeBlades.
public static String listComputeBlades(String cookie) {
XmlObject cmd = new XmlObject("configResolveClass");
cmd.putElement("classId", "computeBlade");
cmd.putElement("cookie", cookie);
cmd.putElement("inHierarchical", "false");
return cmd.dump();
}
use of com.cloud.utils.xmlobject.XmlObject in project cloudstack by apache.
the class UcsCommands method listProfiles.
public static String listProfiles(String cookie) {
XmlObject cmd = new XmlObject("configFindDnsByClassId");
cmd.putElement("classId", "lsServer");
cmd.putElement("cookie", cookie);
return cmd.dump();
}
use of com.cloud.utils.xmlobject.XmlObject in project cloudstack by apache.
the class UcsCommands method loginCmd.
public static String loginCmd(String username, String password) {
XmlObject cmd = new XmlObject("aaaLogin");
cmd.putElement("inName", username);
cmd.putElement("inPassword", password);
return cmd.dump();
}
Aggregations