use of com.cloud.utils.xmlobject.XmlObject in project cloudstack by apache.
the class Force10BaremetalSwitchBackend method prepareVlan.
@Override
public void prepareVlan(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);
ResponseEntity rsp = rest.exchange(link, HttpMethod.GET, request, String.class);
logger.debug(String.format("http get: %s", link));
if (rsp.getStatusCode() == HttpStatus.NOT_FOUND) {
PortInfo port = new PortInfo(struct);
XmlObject xml = new XmlObject("vlan").putElement("vlan-id", new XmlObject("vlan-id").setText(String.valueOf(struct.getVlan()))).putElement("untagged", new XmlObject("untagged").putElement(port.interfaceType, new XmlObject(port.interfaceType).putElement("name", new XmlObject("name").setText(port.port)))).putElement("shutdown", new XmlObject("shutdown").setText("false"));
request = new HttpEntity<>(xml.dump(), headers);
link = buildLink(struct.getSwitchIp(), String.format("/api/running/ftos/interface/"));
logger.debug(String.format("http get: %s, body: %s", link, request));
rsp = rest.exchange(link, HttpMethod.POST, request, String.class);
if (!successHttpStatusCode.contains(rsp.getStatusCode())) {
throw new CloudRuntimeException(String.format("unable to create vlan[%s] on force10 switch[ip:%s]. HTTP status code:%s, body dump:%s", struct.getVlan(), struct.getSwitchIp(), rsp.getStatusCode(), rsp.getBody()));
} else {
logger.debug(String.format("successfully programmed vlan[%s] on Force10[ip:%s, port:%s]. http response[status code:%s, body:%s]", struct.getVlan(), struct.getSwitchIp(), struct.getPort(), rsp.getStatusCode(), rsp.getBody()));
}
} else if (successHttpStatusCode.contains(rsp.getStatusCode())) {
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"));
for (XmlObject pxml : ports) {
XmlObject name = pxml.get("name");
if (port.port.equals(name.getText())) {
logger.debug(String.format("port[%s] has joined in vlan[%s], no need to program again", struct.getPort(), struct.getVlan()));
return;
}
}
xml.removeElement("mtu");
xml.setText(null);
XmlObject tag = xml.get("untagged");
if (tag == null) {
tag = new XmlObject("untagged");
xml.putElement("untagged", tag);
}
tag.putElement(port.interfaceType, new XmlObject(port.interfaceType).putElement("name", new XmlObject("name").setText(port.port)));
request = new HttpEntity<>(xml.dump(), headers);
link = buildLink(struct.getSwitchIp(), String.format("/api/running/ftos/interface/vlan/%s", struct.getVlan()));
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("successfully join port[%s] into vlan[%s] on Force10[ip:%s]. http response[status code:%s, body:%s]", struct.getPort(), struct.getVlan(), struct.getSwitchIp(), rsp.getStatusCode(), rsp.getBody()));
}
} 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 configResolveDn.
public static String configResolveDn(String cookie, String dn) {
XmlObject cmd = new XmlObject("configResolveDn");
cmd.putElement("cookie", cookie);
cmd.putElement("dn", dn);
return cmd.toString();
}
use of com.cloud.utils.xmlobject.XmlObject in project cloudstack by apache.
the class UcsManagerImpl method cloneProfile.
private String cloneProfile(Long ucsMgrId, String srcDn, String newProfileName) {
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
String cookie = getCookie(ucsMgrId);
String cmd = UcsCommands.cloneProfile(cookie, srcDn, newProfileName);
String res = client.call(cmd);
XmlObject xo = XmlObjectParser.parseFromString(res);
return xo.get("outConfig.lsServer.dn");
}
Aggregations