Search in sources :

Example 6 with NetconfHelper

use of com.cloud.utils.cisco.n1kv.vsm.NetconfHelper in project CloudStack-archive by CloudStack-extras.

the class HypervisorHostHelper method updatePortProfile.

public static void updatePortProfile(VmwareContext context, String ethPortProfileName, String vethPortProfileName, Integer vlanId, Integer networkRateMbps, long peakBandwidth, long burstRate) throws Exception {
    NetconfHelper netconfClient = null;
    Map<String, String> vsmCredentials = getValidatedVsmCredentials(context);
    String vsmIp = vsmCredentials.get("vsmip");
    String vsmUserName = vsmCredentials.get("vsmusername");
    String vsmPassword = vsmCredentials.get("vsmpassword");
    String msg;
    try {
        netconfClient = new NetconfHelper(vsmIp, vsmUserName, vsmPassword);
    } catch (CloudRuntimeException e) {
        msg = "Failed to connect to Nexus 1000v " + vsmIp + " with credentials of user " + vsmUserName + ". Exception: " + e.toString();
        s_logger.error(msg);
        throw new CloudRuntimeException(msg);
    }
    PortProfile portProfile = netconfClient.getPortProfileByName(vethPortProfileName);
    int averageBandwidth = 0;
    String policyName = s_policyNamePrefix;
    if (networkRateMbps != null) {
        averageBandwidth = networkRateMbps.intValue();
        policyName += averageBandwidth;
    }
    if (averageBandwidth > 0) {
        PolicyMap policyMap = netconfClient.getPolicyMapByName(portProfile.inputPolicyMap);
        if (policyMap.committedRate == averageBandwidth && policyMap.peakRate == peakBandwidth && policyMap.burstRate == burstRate) {
            s_logger.debug("Detected that policy map is already applied to port profile " + vethPortProfileName);
            if (netconfClient != null) {
                netconfClient.disconnect();
                s_logger.debug("Disconnected Nexus 1000v session.");
            }
            return;
        } else {
            try {
                // TODO(sateesh): Change the type of peakBandwidth &
                // burstRate in PolicyMap to long.
                s_logger.info("Adding policy map " + policyName);
                netconfClient.addPolicyMap(policyName, averageBandwidth, (int) peakBandwidth, (int) burstRate);
            } catch (CloudRuntimeException e) {
                msg = "Failed to add policy map of " + policyName + " with parameters " + "committed rate = " + averageBandwidth + "peak bandwidth = " + peakBandwidth + "burst size = " + burstRate + ". Exception: " + e.toString();
                s_logger.error(msg);
                if (netconfClient != null) {
                    netconfClient.disconnect();
                    s_logger.debug("Disconnected Nexus 1000v session.");
                }
                throw new CloudRuntimeException(msg);
            }
            try {
                s_logger.info("Associating policy map " + policyName + " with port profile " + vethPortProfileName + ".");
                netconfClient.attachServicePolicy(policyName, vethPortProfileName);
            } catch (CloudRuntimeException e) {
                msg = "Failed to associate policy map " + policyName + " with port profile " + vethPortProfileName + ". Exception: " + e.toString();
                s_logger.error(msg);
                if (netconfClient != null) {
                    netconfClient.disconnect();
                    s_logger.debug("Disconnected Nexus 1000v session.");
                }
                throw new CloudRuntimeException(msg);
            }
        }
    }
    if (vlanId == null) {
        s_logger.info("Skipping update operation over ethernet port profile " + ethPortProfileName + " for untagged VLAN.");
        if (netconfClient != null) {
            netconfClient.disconnect();
            s_logger.debug("Disconnected Nexus 1000v session.");
        }
        return;
    }
    String currentVlan = portProfile.vlan;
    String newVlan = Integer.toString(vlanId.intValue());
    if (currentVlan.equalsIgnoreCase(newVlan)) {
        if (netconfClient != null) {
            netconfClient.disconnect();
            s_logger.debug("Disconnected Nexus 1000v session.");
        }
        return;
    }
    List<Pair<OperationType, String>> params = new ArrayList<Pair<OperationType, String>>();
    params.add(new Pair<OperationType, String>(OperationType.addvlanid, newVlan));
    try {
        s_logger.info("Updating vEthernet port profile with VLAN " + vlanId.toString());
        netconfClient.updatePortProfile(ethPortProfileName, SwitchPortMode.trunk, params);
    } catch (CloudRuntimeException e) {
        msg = "Failed to update ethernet port profile " + ethPortProfileName + " with parameters " + params.toString() + ". Exception: " + e.toString();
        s_logger.error(msg);
        if (netconfClient != null) {
            netconfClient.disconnect();
            s_logger.debug("Disconnected Nexus 1000v session.");
        }
        throw new CloudRuntimeException(msg);
    }
    try {
        netconfClient.updatePortProfile(vethPortProfileName, SwitchPortMode.access, params);
    } catch (CloudRuntimeException e) {
        msg = "Failed to update vEthernet port profile " + vethPortProfileName + " with parameters " + params.toString() + ". Exception: " + e.toString();
        s_logger.error(msg);
        if (netconfClient != null) {
            netconfClient.disconnect();
            s_logger.debug("Disconnected Nexus 1000v session.");
        }
        throw new CloudRuntimeException(msg);
    }
}
Also used : PortProfile(com.cloud.utils.cisco.n1kv.vsm.PortProfile) PolicyMap(com.cloud.utils.cisco.n1kv.vsm.PolicyMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) OperationType(com.cloud.utils.cisco.n1kv.vsm.VsmCommand.OperationType) NetconfHelper(com.cloud.utils.cisco.n1kv.vsm.NetconfHelper) Pair(com.cloud.utils.Pair)

Example 7 with NetconfHelper

use of com.cloud.utils.cisco.n1kv.vsm.NetconfHelper in project cloudstack by apache.

the class HypervisorHostHelper method updatePortProfile.

public static void updatePortProfile(VmwareContext context, String ethPortProfileName, String vethPortProfileName, Integer vlanId, Integer networkRateMbps, long peakBandwidth, long burstRate) throws Exception {
    NetconfHelper netconfClient = null;
    Map<String, String> vsmCredentials = getValidatedVsmCredentials(context);
    String vsmIp = vsmCredentials.get("vsmip");
    String vsmUserName = vsmCredentials.get("vsmusername");
    String vsmPassword = vsmCredentials.get("vsmpassword");
    String msg;
    try {
        netconfClient = new NetconfHelper(vsmIp, vsmUserName, vsmPassword);
    } catch (CloudRuntimeException e) {
        msg = "Failed to connect to Nexus 1000v " + vsmIp + " with credentials of user " + vsmUserName + ". Exception: " + e.toString();
        s_logger.error(msg);
        throw new CloudRuntimeException(msg);
    }
    PortProfile portProfile = netconfClient.getPortProfileByName(vethPortProfileName);
    int averageBandwidth = 0;
    String policyName = s_policyNamePrefix;
    if (networkRateMbps != null) {
        averageBandwidth = networkRateMbps.intValue();
        policyName += averageBandwidth;
    }
    if (averageBandwidth > 0) {
        PolicyMap policyMap = netconfClient.getPolicyMapByName(portProfile.inputPolicyMap);
        if (policyMap.committedRate == averageBandwidth && policyMap.peakRate == peakBandwidth && policyMap.burstRate == burstRate) {
            s_logger.debug("Detected that policy map is already applied to port profile " + vethPortProfileName);
            if (netconfClient != null) {
                netconfClient.disconnect();
                s_logger.debug("Disconnected Nexus 1000v session.");
            }
            return;
        } else {
            try {
                // TODO(sateesh): Change the type of peakBandwidth &
                // burstRate in PolicyMap to long.
                s_logger.info("Adding policy map " + policyName);
                netconfClient.addPolicyMap(policyName, averageBandwidth, (int) peakBandwidth, (int) burstRate);
            } catch (CloudRuntimeException e) {
                msg = "Failed to add policy map of " + policyName + " with parameters " + "committed rate = " + averageBandwidth + "peak bandwidth = " + peakBandwidth + "burst size = " + burstRate + ". Exception: " + e.toString();
                s_logger.error(msg);
                if (netconfClient != null) {
                    netconfClient.disconnect();
                    s_logger.debug("Disconnected Nexus 1000v session.");
                }
                throw new CloudRuntimeException(msg);
            }
            try {
                s_logger.info("Associating policy map " + policyName + " with port profile " + vethPortProfileName + ".");
                netconfClient.attachServicePolicy(policyName, vethPortProfileName);
            } catch (CloudRuntimeException e) {
                msg = "Failed to associate policy map " + policyName + " with port profile " + vethPortProfileName + ". Exception: " + e.toString();
                s_logger.error(msg);
                if (netconfClient != null) {
                    netconfClient.disconnect();
                    s_logger.debug("Disconnected Nexus 1000v session.");
                }
                throw new CloudRuntimeException(msg);
            }
        }
    }
    if (vlanId == null) {
        s_logger.info("Skipping update operation over ethernet port profile " + ethPortProfileName + " for untagged VLAN.");
        if (netconfClient != null) {
            netconfClient.disconnect();
            s_logger.debug("Disconnected Nexus 1000v session.");
        }
        return;
    }
    String currentVlan = portProfile.vlan;
    String newVlan = Integer.toString(vlanId.intValue());
    if (currentVlan.equalsIgnoreCase(newVlan)) {
        if (netconfClient != null) {
            netconfClient.disconnect();
            s_logger.debug("Disconnected Nexus 1000v session.");
        }
        return;
    }
    List<Pair<OperationType, String>> params = new ArrayList<Pair<OperationType, String>>();
    params.add(new Pair<OperationType, String>(OperationType.addvlanid, newVlan));
    try {
        s_logger.info("Updating vEthernet port profile with VLAN " + vlanId.toString());
        netconfClient.updatePortProfile(ethPortProfileName, SwitchPortMode.trunk, params);
    } catch (CloudRuntimeException e) {
        msg = "Failed to update ethernet port profile " + ethPortProfileName + " with parameters " + params.toString() + ". Exception: " + e.toString();
        s_logger.error(msg);
        if (netconfClient != null) {
            netconfClient.disconnect();
            s_logger.debug("Disconnected Nexus 1000v session.");
        }
        throw new CloudRuntimeException(msg);
    }
    try {
        netconfClient.updatePortProfile(vethPortProfileName, SwitchPortMode.access, params);
    } catch (CloudRuntimeException e) {
        msg = "Failed to update vEthernet port profile " + vethPortProfileName + " with parameters " + params.toString() + ". Exception: " + e.toString();
        s_logger.error(msg);
        if (netconfClient != null) {
            netconfClient.disconnect();
            s_logger.debug("Disconnected Nexus 1000v session.");
        }
        throw new CloudRuntimeException(msg);
    }
}
Also used : PortProfile(com.cloud.utils.cisco.n1kv.vsm.PortProfile) PolicyMap(com.cloud.utils.cisco.n1kv.vsm.PolicyMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) OperationType(com.cloud.utils.cisco.n1kv.vsm.VsmCommand.OperationType) NetconfHelper(com.cloud.utils.cisco.n1kv.vsm.NetconfHelper) Pair(com.cloud.utils.Pair)

Aggregations

NetconfHelper (com.cloud.utils.cisco.n1kv.vsm.NetconfHelper)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 Pair (com.cloud.utils.Pair)6 OperationType (com.cloud.utils.cisco.n1kv.vsm.VsmCommand.OperationType)5 ArrayList (java.util.ArrayList)5 ClusterVO (com.cloud.dc.ClusterVO)2 ClusterVSMMapVO (com.cloud.dc.ClusterVSMMapVO)2 ResourceInUseException (com.cloud.exception.ResourceInUseException)2 PolicyMap (com.cloud.utils.cisco.n1kv.vsm.PolicyMap)2 PortProfile (com.cloud.utils.cisco.n1kv.vsm.PortProfile)2 DB (com.cloud.utils.db.DB)2 Answer (com.cloud.agent.api.Answer)1 ExternalNetworkResourceUsageAnswer (com.cloud.agent.api.ExternalNetworkResourceUsageAnswer)1 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)1 ReadyAnswer (com.cloud.agent.api.ReadyAnswer)1 IpAssocAnswer (com.cloud.agent.api.routing.IpAssocAnswer)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 CiscoNexusVSMDeviceVO (com.cloud.network.CiscoNexusVSMDeviceVO)1 TransactionCallback (com.cloud.utils.db.TransactionCallback)1 TransactionStatus (com.cloud.utils.db.TransactionStatus)1