use of com.cloud.utils.xmlobject.XmlObject in project cloudstack by apache.
the class UcsManagerImpl method getCookie.
private String getCookie(Long ucsMgrId) {
try {
UcsCookie ucsCookie = cookies.get(ucsMgrId);
long currentTime = System.currentTimeMillis();
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
String cmd = null;
if (ucsCookie == null) {
cmd = UcsCommands.loginCmd(mgrvo.getUsername(), mgrvo.getPassword());
} else {
String cookie = ucsCookie.getCookie();
long cookieStartTime = ucsCookie.getStartTime();
if (currentTime - cookieStartTime > COOKIE_TTL) {
cmd = UcsCommands.loginCmd(mgrvo.getUsername(), mgrvo.getPassword());
} else if (currentTime - cookieStartTime > COOKIE_REFRESH_TTL) {
cmd = UcsCommands.refreshCmd(mgrvo.getUsername(), mgrvo.getPassword(), cookie);
}
}
if (!(cmd == null)) {
String ret = client.call(cmd);
XmlObject xo = XmlObjectParser.parseFromString(ret);
String cookie = xo.get("outCookie");
ucsCookie = new UcsCookie(cookie, currentTime);
cookies.put(ucsMgrId, ucsCookie);
//cookiesTime.put(cookie, currentTime); //This is currentTime on purpose, and not latest time.
}
return ucsCookie.getCookie();
} catch (Exception e) {
throw new CloudRuntimeException("Cannot get cookie", e);
}
}
use of com.cloud.utils.xmlobject.XmlObject in project cloudstack by apache.
the class UcsManagerImpl method isProfileAssociated.
private boolean isProfileAssociated(Long ucsMgrId, String dn) {
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
String cookie = getCookie(ucsMgrId);
String cmd = UcsCommands.configResolveDn(cookie, dn);
String res = client.call(cmd);
XmlObject xo = XmlObjectParser.parseFromString(res);
s_logger.debug(String.format("association response is %s", res));
if (xo.get("outConfig.computeBlade.association").equals("none")) {
throw new CloudRuntimeException(String.format("cannot associated a profile to blade[dn:%s]. please check your UCS manasger for detailed error information", dn));
}
return xo.get("outConfig.computeBlade.association").equals("associated");
}
use of com.cloud.utils.xmlobject.XmlObject in project cloudstack by apache.
the class ComputeBlade method fromXmString.
public static List<ComputeBlade> fromXmString(String xmlstr) {
XmlObject root = XmlObjectParser.parseFromString(xmlstr);
List<XmlObject> lst = root.getAsList("outConfigs.computeBlade");
List<ComputeBlade> blades = new ArrayList<ComputeBlade>();
if (lst == null) {
return blades;
}
for (XmlObject xo : lst) {
blades.add(fromXmlObject(xo));
}
return blades;
}
use of com.cloud.utils.xmlobject.XmlObject in project cloudstack by apache.
the class UcsCommands method cloneProfile.
public static String cloneProfile(String cookie, String srcDn, String newProfileName) {
XmlObject cmd = new XmlObject("lsClone");
cmd.putElement("cookie", cookie);
cmd.putElement("dn", srcDn);
cmd.putElement("inTargetOrg", "org-root");
cmd.putElement("inServerName", newProfileName);
cmd.putElement("inHierarchical", "false");
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