Search in sources :

Example 1 with XmlObject

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()));
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) HttpEntity(org.springframework.http.HttpEntity) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XmlObject(com.cloud.utils.xmlobject.XmlObject) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with XmlObject

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

Example 3 with XmlObject

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

Example 4 with XmlObject

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

Example 5 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