Search in sources :

Example 6 with XmlObject

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);
    }
}
Also used : UcsManagerVO(com.cloud.ucs.database.UcsManagerVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UcsCookie(com.cloud.ucs.structure.UcsCookie) XmlObject(com.cloud.utils.xmlobject.XmlObject) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 7 with XmlObject

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");
}
Also used : UcsManagerVO(com.cloud.ucs.database.UcsManagerVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XmlObject(com.cloud.utils.xmlobject.XmlObject)

Example 8 with XmlObject

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;
}
Also used : ArrayList(java.util.ArrayList) XmlObject(com.cloud.utils.xmlobject.XmlObject)

Example 9 with XmlObject

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();
}
Also used : XmlObject(com.cloud.utils.xmlobject.XmlObject)

Example 10 with XmlObject

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();
}
Also used : XmlObject(com.cloud.utils.xmlobject.XmlObject)

Aggregations

XmlObject (com.cloud.utils.xmlobject.XmlObject)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 ArrayList (java.util.ArrayList)4 UcsManagerVO (com.cloud.ucs.database.UcsManagerVO)3 List (java.util.List)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 UcsCookie (com.cloud.ucs.structure.UcsCookie)1 ConfigurationException (javax.naming.ConfigurationException)1