use of com.cloud.utils.cisco.n1kv.vsm.NetconfHelper in project CloudStack-archive by CloudStack-extras.
the class HypervisorHostHelper method createPortProfile.
public static void createPortProfile(VmwareContext context, String ethPortProfileName, String networkName, Integer vlanId, Integer networkRateMbps, long peakBandwidth, long burstSize) throws Exception {
Map<String, String> vsmCredentials = getValidatedVsmCredentials(context);
String vsmIp = vsmCredentials.get("vsmip");
String vsmUserName = vsmCredentials.get("vsmusername");
String vsmPassword = vsmCredentials.get("vsmpassword");
String msg;
NetconfHelper netconfClient;
try {
s_logger.info("Connecting to Nexus 1000v: " + vsmIp);
netconfClient = new NetconfHelper(vsmIp, vsmUserName, vsmPassword);
s_logger.info("Successfully connected to Nexus 1000v : " + vsmIp);
} 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);
}
String policyName = s_policyNamePrefix;
int averageBandwidth = 0;
if (networkRateMbps != null) {
averageBandwidth = networkRateMbps.intValue();
policyName += averageBandwidth;
}
try {
// PolicyMap to long.
if (averageBandwidth > 0) {
s_logger.debug("Adding policy map " + policyName);
netconfClient.addPolicyMap(policyName, averageBandwidth, (int) peakBandwidth, (int) burstSize);
}
} catch (CloudRuntimeException e) {
msg = "Failed to add policy map of " + policyName + " with parameters " + "committed rate = " + averageBandwidth + "peak bandwidth = " + peakBandwidth + "burst size = " + burstSize + ". Exception: " + e.toString();
s_logger.error(msg);
if (netconfClient != null) {
netconfClient.disconnect();
s_logger.debug("Disconnected Nexus 1000v session.");
}
throw new CloudRuntimeException(msg);
}
List<Pair<OperationType, String>> params = new ArrayList<Pair<OperationType, String>>();
if (vlanId != null) {
// No need to update ethernet port profile for untagged vlans
params.add(new Pair<OperationType, String>(OperationType.addvlanid, vlanId.toString()));
try {
s_logger.info("Updating Ethernet port profile " + ethPortProfileName + " with VLAN " + vlanId);
netconfClient.updatePortProfile(ethPortProfileName, SwitchPortMode.trunk, params);
s_logger.info("Added " + vlanId + " to Ethernet port profile " + ethPortProfileName);
} catch (CloudRuntimeException e) {
msg = "Failed to update Ethernet port profile " + ethPortProfileName + " with VLAN " + vlanId + ". Exception: " + e.toString();
s_logger.error(msg);
if (netconfClient != null) {
netconfClient.disconnect();
s_logger.debug("Disconnected Nexus 1000v session.");
}
throw new CloudRuntimeException(msg);
}
}
try {
if (vlanId == null) {
s_logger.info("Adding port profile configured over untagged VLAN.");
netconfClient.addPortProfile(networkName, PortProfileType.vethernet, BindingType.portbindingstatic, SwitchPortMode.access, 0);
} else {
s_logger.info("Adding port profile configured over VLAN : " + vlanId.toString());
netconfClient.addPortProfile(networkName, PortProfileType.vethernet, BindingType.portbindingstatic, SwitchPortMode.access, vlanId.intValue());
}
} catch (CloudRuntimeException e) {
msg = "Failed to add vEthernet port profile " + networkName + "." + ". Exception: " + e.toString();
s_logger.error(msg);
if (netconfClient != null) {
netconfClient.disconnect();
s_logger.debug("Disconnected Nexus 1000v session.");
}
throw new CloudRuntimeException(msg);
}
try {
if (averageBandwidth > 0) {
s_logger.info("Associating policy map " + policyName + " with port profile " + networkName + ".");
netconfClient.attachServicePolicy(policyName, networkName);
}
} catch (CloudRuntimeException e) {
msg = "Failed to associate policy map " + policyName + " with port profile " + networkName + ". Exception: " + e.toString();
s_logger.error(msg);
throw new CloudRuntimeException(msg);
} finally {
if (netconfClient != null) {
netconfClient.disconnect();
s_logger.debug("Disconnected Nexus 1000v session.");
}
}
}
use of com.cloud.utils.cisco.n1kv.vsm.NetconfHelper in project cloudstack by apache.
the class CiscoNexusVSMDeviceManagerImpl method addCiscoNexusVSM.
@DB
public CiscoNexusVSMDeviceVO addCiscoNexusVSM(long clusterId, String ipaddress, String username, String password, String vCenterIpaddr, String vCenterDcName) {
// In this function, we associate this VSM with each host
// in the clusterId specified.
// First check if the cluster is of type vmware. If not,
// throw an exception. VSMs are tightly integrated with vmware clusters.
ClusterVO cluster = _clusterDao.findById(clusterId);
if (cluster == null) {
throw new InvalidParameterValueException("Cluster with specified ID not found!");
}
if (cluster.getHypervisorType() != HypervisorType.VMware) {
InvalidParameterValueException ex = new InvalidParameterValueException("Cluster with specified id is not a VMWare hypervisor cluster");
throw ex;
}
if (_clusterVSMDao.findByClusterId(clusterId) != null) {
// We can't have two VSMs for the same cluster. Throw exception.
throw new InvalidParameterValueException("Cluster with specified id already has a VSM tied to it. Please remove that first and retry the operation.");
}
// TODO: Confirm whether we should be checking for VSM reachability here.
// Next, check if this VSM is reachable. Use the XML-RPC VSM API Java bindings to talk to
// the VSM.
//NetconfHelper (String ip, String username, String password)
NetconfHelper netconfClient;
try {
netconfClient = new NetconfHelper(ipaddress, username, password);
} catch (CloudRuntimeException e) {
String msg = "Failed to connect to Nexus VSM " + ipaddress + " with credentials of user " + username;
s_logger.error(msg);
throw new CloudRuntimeException(msg);
}
// Disconnect from the VSM. A VSM has a default of 8 maximum parallel connections that it allows.
netconfClient.disconnect();
// Now, go ahead and associate the cluster with this VSM.
// First, check if VSM already exists in the table "virtual_supervisor_module".
// If it's not there already, create it.
// If it's there already, return success.
// TODO - Right now, we only check if the ipaddress matches for both requests.
// We must really check whether every field of the VSM matches. Anyway, the
// advantage of our approach for now is that existing infrastructure using
// the existing VSM won't be affected if the new request to add the VSM
// assumed different information on the VSM (mgmt vlan, username, password etc).
CiscoNexusVSMDeviceVO VSMObj;
try {
VSMObj = _ciscoNexusVSMDeviceDao.getVSMbyIpaddress(ipaddress);
} catch (Exception e) {
throw new CloudRuntimeException(e.getMessage());
}
if (VSMObj == null) {
// Create the VSM record. For now, we aren't using the vsmName field.
VSMObj = new CiscoNexusVSMDeviceVO(ipaddress, username, password);
_ciscoNexusVSMDeviceDao.persist(VSMObj);
}
// At this stage, we have a VSM record for sure. Connect the VSM to the cluster Id.
long vsmId = _ciscoNexusVSMDeviceDao.getVSMbyIpaddress(ipaddress).getId();
ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsmId);
_clusterVSMDao.persist(connectorObj);
return VSMObj;
}
use of com.cloud.utils.cisco.n1kv.vsm.NetconfHelper in project cloudstack by apache.
the class CiscoNexusVSMElement method validateAndAddVsm.
@Override
@DB
public Pair<Boolean, Long> validateAndAddVsm(final String vsmIp, final String vsmUser, final String vsmPassword, final long clusterId, String clusterName) throws ResourceInUseException {
CiscoNexusVSMDeviceVO vsm = null;
boolean vsmAdded = false;
Long vsmId = 0L;
if (vsmIp != null && vsmUser != null && vsmPassword != null) {
NetconfHelper netconfClient;
try {
netconfClient = new NetconfHelper(vsmIp, vsmUser, vsmPassword);
netconfClient.disconnect();
} catch (CloudRuntimeException e) {
String msg = "Invalid credentials supplied for user " + vsmUser + " for Cisco Nexus 1000v VSM at " + vsmIp;
s_logger.error(msg);
_clusterDao.remove(clusterId);
throw new CloudRuntimeException(msg);
}
// If VSM already exists and is mapped to a cluster, fail this operation.
vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
if (vsm != null) {
List<ClusterVSMMapVO> clusterList = _clusterVSMDao.listByVSMId(vsm.getId());
if (clusterList != null && !clusterList.isEmpty()) {
s_logger.error("Failed to add cluster: specified Nexus VSM is already associated with another cluster");
ResourceInUseException ex = new ResourceInUseException("Failed to add cluster: specified Nexus VSM is already associated with another cluster with specified Id");
// get clusterUuid to report error
ClusterVO cluster = _clusterDao.findById(clusterList.get(0).getClusterId());
ex.addProxyObject(cluster.getUuid());
_clusterDao.remove(clusterId);
throw ex;
}
}
// persist credentials to database if the VSM entry is not already in the db.
vsm = Transaction.execute(new TransactionCallback<CiscoNexusVSMDeviceVO>() {
@Override
public CiscoNexusVSMDeviceVO doInTransaction(TransactionStatus status) {
CiscoNexusVSMDeviceVO vsm = null;
if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) {
vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword);
_vsmDao.persist(vsm);
}
// Create a mapping between the cluster and the vsm.
vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
if (vsm != null) {
ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsm.getId());
_clusterVSMDao.persist(connectorObj);
}
return vsm;
}
});
} else {
String msg;
msg = "The global parameter " + Config.VmwareUseNexusVSwitch.toString() + " is set to \"true\". Following mandatory parameters are not specified. ";
if (vsmIp == null) {
msg += "vsmipaddress: Management IP address of Cisco Nexus 1000v dvSwitch. ";
}
if (vsmUser == null) {
msg += "vsmusername: Name of a user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
}
if (vsmPassword == null) {
if (vsmUser != null) {
msg += "vsmpassword: Password of user account " + vsmUser + ". ";
} else {
msg += "vsmpassword: Password of user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
}
}
s_logger.error(msg);
// Cleaning up the cluster record as addCluster operation failed because of invalid credentials of Nexus dvSwitch.
_clusterDao.remove(clusterId);
throw new CloudRuntimeException(msg);
}
if (vsm != null) {
vsmAdded = true;
vsmId = vsm.getId();
}
return new Pair<Boolean, Long>(vsmAdded, vsmId);
}
use of com.cloud.utils.cisco.n1kv.vsm.NetconfHelper in project cloudstack by apache.
the class CiscoVnmcResource method execute.
private Answer execute(ConfigureNexusVsmForAsaCommand cmd, int numRetries) {
String vlanId = Long.toString(cmd.getVlanId());
NetconfHelper helper = null;
List<Pair<OperationType, String>> params = new ArrayList<Pair<OperationType, String>>();
params.add(new Pair<OperationType, String>(OperationType.addvlanid, vlanId));
try {
helper = new NetconfHelper(cmd.getVsmIp(), cmd.getVsmUsername(), cmd.getVsmPassword());
s_logger.debug("Connected to Cisco VSM " + cmd.getVsmIp());
helper.addVServiceNode(vlanId, cmd.getIpAddress());
s_logger.debug("Created vservice node for ASA appliance in Cisco VSM for vlan " + vlanId);
helper.updatePortProfile(cmd.getAsaInPortProfile(), SwitchPortMode.access, params);
s_logger.debug("Updated inside port profile for ASA appliance in Cisco VSM with new vlan " + vlanId);
} catch (CloudRuntimeException e) {
String msg = "ConfigureVSMForASACommand failed due to " + e.getMessage();
s_logger.error(msg, e);
return new Answer(cmd, false, msg);
} finally {
if (helper != null) {
helper.disconnect();
}
}
return new Answer(cmd, true, "Success");
}
use of com.cloud.utils.cisco.n1kv.vsm.NetconfHelper in project cloudstack by apache.
the class HypervisorHostHelper method createPortProfile.
public static void createPortProfile(VmwareContext context, String ethPortProfileName, String networkName, Integer vlanId, Integer networkRateMbps, long peakBandwidth, long burstSize, String gateway, boolean configureVServiceInNexus) throws Exception {
Map<String, String> vsmCredentials = getValidatedVsmCredentials(context);
String vsmIp = vsmCredentials.get("vsmip");
String vsmUserName = vsmCredentials.get("vsmusername");
String vsmPassword = vsmCredentials.get("vsmpassword");
String msg;
NetconfHelper netconfClient;
try {
s_logger.info("Connecting to Nexus 1000v: " + vsmIp);
netconfClient = new NetconfHelper(vsmIp, vsmUserName, vsmPassword);
s_logger.info("Successfully connected to Nexus 1000v : " + vsmIp);
} 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);
}
String policyName = s_policyNamePrefix;
int averageBandwidth = 0;
if (networkRateMbps != null) {
averageBandwidth = networkRateMbps.intValue();
policyName += averageBandwidth;
}
try {
// PolicyMap to long.
if (averageBandwidth > 0) {
s_logger.debug("Adding policy map " + policyName);
netconfClient.addPolicyMap(policyName, averageBandwidth, (int) peakBandwidth, (int) burstSize);
}
} catch (CloudRuntimeException e) {
msg = "Failed to add policy map of " + policyName + " with parameters " + "committed rate = " + averageBandwidth + "peak bandwidth = " + peakBandwidth + "burst size = " + burstSize + ". Exception: " + e.toString();
s_logger.error(msg);
if (netconfClient != null) {
netconfClient.disconnect();
s_logger.debug("Disconnected Nexus 1000v session.");
}
throw new CloudRuntimeException(msg);
}
List<Pair<OperationType, String>> params = new ArrayList<Pair<OperationType, String>>();
if (vlanId != null) {
// No need to update ethernet port profile for untagged vlans
params.add(new Pair<OperationType, String>(OperationType.addvlanid, vlanId.toString()));
try {
s_logger.info("Updating Ethernet port profile " + ethPortProfileName + " with VLAN " + vlanId);
netconfClient.updatePortProfile(ethPortProfileName, SwitchPortMode.trunk, params);
s_logger.info("Added " + vlanId + " to Ethernet port profile " + ethPortProfileName);
} catch (CloudRuntimeException e) {
msg = "Failed to update Ethernet port profile " + ethPortProfileName + " with VLAN " + vlanId + ". Exception: " + e.toString();
s_logger.error(msg);
if (netconfClient != null) {
netconfClient.disconnect();
s_logger.debug("Disconnected Nexus 1000v session.");
}
throw new CloudRuntimeException(msg);
}
}
try {
if (vlanId == null) {
s_logger.info("Adding port profile configured over untagged VLAN.");
netconfClient.addPortProfile(networkName, PortProfileType.vethernet, BindingType.portbindingstatic, SwitchPortMode.access, 0);
} else {
if (!configureVServiceInNexus) {
s_logger.info("Adding port profile configured over VLAN : " + vlanId.toString());
netconfClient.addPortProfile(networkName, PortProfileType.vethernet, BindingType.portbindingstatic, SwitchPortMode.access, vlanId.intValue());
} else {
String tenant = "vlan-" + vlanId.intValue();
String vdc = "root/" + tenant + "/VDC-" + tenant;
String esp = "ESP-" + tenant;
s_logger.info("Adding vservice node in Nexus VSM for VLAN : " + vlanId.toString());
netconfClient.addVServiceNode(vlanId.toString(), gateway);
s_logger.info("Adding port profile with vservice details configured over VLAN : " + vlanId.toString());
netconfClient.addPortProfile(networkName, PortProfileType.vethernet, BindingType.portbindingstatic, SwitchPortMode.access, vlanId.intValue(), vdc, esp);
}
}
} catch (CloudRuntimeException e) {
msg = "Failed to add vEthernet port profile " + networkName + "." + ". Exception: " + e.toString();
s_logger.error(msg);
if (netconfClient != null) {
netconfClient.disconnect();
s_logger.debug("Disconnected Nexus 1000v session.");
}
throw new CloudRuntimeException(msg);
}
try {
if (averageBandwidth > 0) {
s_logger.info("Associating policy map " + policyName + " with port profile " + networkName + ".");
netconfClient.attachServicePolicy(policyName, networkName);
}
} catch (CloudRuntimeException e) {
msg = "Failed to associate policy map " + policyName + " with port profile " + networkName + ". Exception: " + e.toString();
s_logger.error(msg);
throw new CloudRuntimeException(msg);
} finally {
if (netconfClient != null) {
netconfClient.disconnect();
s_logger.debug("Disconnected Nexus 1000v session.");
}
}
}
Aggregations