Skip to content

Commit c65199c

Browse files
Sateesh ChodapuneediVijayendra Bhamidipati
authored andcommitted
CS-9919 Support for Nexus Swiches (Cisco Vswitches)
Added VSM credentials to AddClusterCmd(optonal params only). Cleanup. Conflicts: api/src/com/cloud/api/commands/AddClusterCmd.java
1 parent 9709774 commit c65199c

6 files changed

Lines changed: 212 additions & 123 deletions

File tree

api/src/com/cloud/api/ApiConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ public class ApiConstants {
343343
public static final String VCENTER_IP_ADDRESS = "vcenteripaddr";
344344
public static final String VCENTER_DC_NAME = "vcenterdcname";
345345
public static final String CISCO_NEXUS_VSM_NAME = "vsmname";
346+
public static final String VSM_USERNAME = "vsmusername";
347+
public static final String VSM_PASSWORD = "vsmpassword";
348+
public static final String VSM_IPADDRESS = "vsmipaddress";
346349

347350
public enum HostDetails {
348351
all, capacity, events, stats, min;

api/src/com/cloud/api/commands/AddClusterCmd.java

Lines changed: 116 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
// limitations under the License.
1111
//
1212
// Automatically generated by addcopyright.py at 04/03/2012
13-
package com.cloud.api.commands;
13+
14+
package com.cloud.api.commands;
1415

1516
import java.util.ArrayList;
1617
import java.util.List;
@@ -28,18 +29,18 @@
2829
import com.cloud.exception.DiscoveryException;
2930
import com.cloud.org.Cluster;
3031
import com.cloud.user.Account;
31-
32-
@Implementation(description="Adds a new cluster", responseObject=ClusterResponse.class)
33-
public class AddClusterCmd extends BaseCmd {
34-
public static final Logger s_logger = Logger.getLogger(AddClusterCmd.class.getName());
35-
36-
private static final String s_name = "addclusterresponse";
37-
38-
@Parameter(name=ApiConstants.CLUSTER_NAME, type=CommandType.STRING, required=true, description="the cluster name")
39-
private String clusterName;
40-
41-
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required=false, description="the password for the host")
42-
private String password;
32+
33+
@Implementation(description="Adds a new cluster", responseObject=ClusterResponse.class)
34+
public class AddClusterCmd extends BaseCmd {
35+
public static final Logger s_logger = Logger.getLogger(AddClusterCmd.class.getName());
36+
37+
private static final String s_name = "addclusterresponse";
38+
39+
@Parameter(name=ApiConstants.CLUSTER_NAME, type=CommandType.STRING, required=true, description="the cluster name")
40+
private String clusterName;
41+
42+
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required=false, description="the password for the host")
43+
private String password;
4344

4445
@IdentityMapper(entityTableName="host_pod_ref")
4546
@Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, required=true, description="the Pod ID for the host")
@@ -52,94 +53,116 @@ public class AddClusterCmd extends BaseCmd {
5253
private String username;
5354

5455
@IdentityMapper(entityTableName="data_center")
55-
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID for the cluster")
56-
private Long zoneId;
57-
58-
@Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, required=true, description="hypervisor type of the cluster: XenServer,KVM,VMware,Hyperv,BareMetal,Simulator")
59-
private String hypervisor;
60-
61-
@Parameter(name=ApiConstants.CLUSTER_TYPE, type=CommandType.STRING, required=true, description="type of the cluster: CloudManaged, ExternalManaged")
62-
private String clusterType;
63-
64-
@Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="Allocation state of this cluster for allocation of new resources")
56+
57+
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID for the cluster")
58+
private Long zoneId;
59+
60+
@Parameter(name=ApiConstants.HYPERVISOR, type=CommandType.STRING, required=true, description="hypervisor type of the cluster: XenServer,KVM,VMware,Hyperv,BareMetal,Simulator")
61+
private String hypervisor;
62+
63+
@Parameter(name=ApiConstants.CLUSTER_TYPE, type=CommandType.STRING, required=true, description="type of the cluster: CloudManaged, ExternalManaged")
64+
private String clusterType;
65+
66+
@Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="Allocation state of this cluster for allocation of new resources")
6567
private String allocationState;
6668

67-
public String getClusterName() {
68-
return clusterName;
69-
}
69+
@Parameter(name = ApiConstants.VSM_USERNAME, type = CommandType.STRING, required = false, description = "the username for the VSM associated with this cluster")
70+
private String vsmusername;
7071

71-
public String getPassword() {
72-
return password;
73-
}
72+
@Parameter(name = ApiConstants.VSM_PASSWORD, type = CommandType.STRING, required = false, description = "the password for the VSM associated with this cluster")
73+
private String vsmpassword;
7474

75-
public Long getPodId() {
76-
return podId;
77-
}
78-
79-
public String getUrl() {
80-
return url;
81-
}
75+
@Parameter(name = ApiConstants.VSM_IPADDRESS, type = CommandType.STRING, required = false, description = "the ipaddress of the VSM associated with this cluster")
76+
private String vsmipaddress;
8277

83-
public String getUsername() {
84-
return username;
78+
public String getVSMIpaddress() {
79+
return vsmipaddress;
8580
}
8681

87-
public Long getZoneId() {
88-
return zoneId;
82+
public String getVSMPassword() {
83+
return vsmpassword;
8984
}
90-
91-
public String getHypervisor() {
92-
return hypervisor;
93-
}
94-
95-
@Override
96-
public String getCommandName() {
97-
return s_name;
98-
}
99-
100-
public String getClusterType() {
101-
return clusterType;
102-
}
103-
104-
public void setClusterType(String type) {
105-
this.clusterType = type;
106-
}
107-
108-
@Override
109-
public long getEntityOwnerId() {
110-
return Account.ACCOUNT_ID_SYSTEM;
111-
}
112-
113-
public String getAllocationState() {
114-
return allocationState;
115-
}
116-
117-
public void setAllocationState(String allocationState) {
118-
this.allocationState = allocationState;
119-
}
120-
121-
@Override
122-
public void execute(){
123-
try {
124-
List<? extends Cluster> result = _resourceService.discoverCluster(this);
125-
ListResponse<ClusterResponse> response = new ListResponse<ClusterResponse>();
126-
List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();
127-
if (result != null) {
128-
for (Cluster cluster : result) {
129-
ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
130-
clusterResponses.add(clusterResponse);
131-
}
132-
} else {
133-
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add cluster");
134-
}
13585

136-
response.setResponses(clusterResponses);
137-
response.setResponseName(getCommandName());
138-
139-
this.setResponseObject(response);
140-
} catch (DiscoveryException ex) {
141-
s_logger.warn("Exception: ", ex);
142-
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
143-
}
86+
public String getVSMUsername() {
87+
return vsmusername;
14488
}
89+
90+
public String getClusterName() {
91+
return clusterName;
92+
}
93+
94+
public String getPassword() {
95+
return password;
96+
}
97+
98+
public Long getPodId() {
99+
return podId;
100+
}
101+
102+
public String getUrl() {
103+
return url;
104+
}
105+
106+
public String getUsername() {
107+
return username;
108+
}
109+
110+
public Long getZoneId() {
111+
return zoneId;
112+
}
113+
114+
public String getHypervisor() {
115+
return hypervisor;
116+
}
117+
118+
@Override
119+
public String getCommandName() {
120+
return s_name;
121+
}
122+
123+
public String getClusterType() {
124+
return clusterType;
125+
}
126+
127+
public void setClusterType(String type) {
128+
this.clusterType = type;
129+
}
130+
131+
@Override
132+
public long getEntityOwnerId() {
133+
return Account.ACCOUNT_ID_SYSTEM;
134+
}
135+
136+
public String getAllocationState() {
137+
return allocationState;
138+
}
139+
140+
public void setAllocationState(String allocationState) {
141+
this.allocationState = allocationState;
142+
}
143+
144+
@Override
145+
public void execute(){
146+
try {
147+
List<? extends Cluster> result = _resourceService.discoverCluster(this);
148+
ListResponse<ClusterResponse> response = new ListResponse<ClusterResponse>();
149+
List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();
150+
if (result != null) {
151+
for (Cluster cluster : result) {
152+
ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster, false);
153+
clusterResponses.add(clusterResponse);
154+
}
155+
} else {
156+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add cluster");
157+
}
158+
159+
response.setResponses(clusterResponses);
160+
response.setResponseName(getCommandName());
161+
162+
this.setResponseObject(response);
163+
} catch (DiscoveryException ex) {
164+
s_logger.warn("Exception: ", ex);
165+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
166+
}
167+
}
145168
}

core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ protected StartAnswer execute(StartCommand cmd) {
14741474
}
14751475
}
14761476

1477-
String switchUuid;
1477+
String dvSwitchUuid;
14781478
ManagedObjectReference dcMor = hyperHost.getHyperHostDatacenter();
14791479
DatacenterMO dataCenterMo = new DatacenterMO(context, dcMor);
14801480

@@ -1487,10 +1487,10 @@ protected StartAnswer execute(StartCommand cmd) {
14871487
Pair<ManagedObjectReference, String> networkInfo = prepareNetworkFromNicInfo(vmMo.getRunningHost(), nicTo);
14881488

14891489
ManagedObjectReference dvsMor = dataCenterMo.getDvSwitchMor(networkInfo.first());
1490-
switchUuid = dataCenterMo.getDvSwitchUuid(dvsMor);
1491-
s_logger.info("Preparing NIC device on dvSwitch : " + switchUuid);
1490+
dvSwitchUuid = dataCenterMo.getDvSwitchUuid(dvsMor);
1491+
s_logger.info("Preparing NIC device on dvSwitch : " + dvSwitchUuid);
14921492

1493-
nic = VmwareHelper.prepareNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), nicTo.getMac(), i, i + 1, true, true);
1493+
nic = VmwareHelper.prepareDvNicDevice(vmMo, networkInfo.first(), nicDeviceType, networkInfo.second(), dvSwitchUuid, nicTo.getMac(), i, i + 1, true, true);
14941494
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
14951495
deviceConfigSpecArray[i].setDevice(nic);
14961496
deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.add);
@@ -4034,7 +4034,16 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
40344034
_hostName = hostMo.getHyperHostName();
40354035
_privateNetworkVSwitchName = mgr.getPrivateVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
40364036
_publicNetworkVSwitchName = mgr.getPublicVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
4037-
_guestNetworkVSwitchName = mgr.getGuestVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
4037+
_guestNetworkVSwitchName = mgr.getGuestVSwitchName(Long.parseLong(_dcId), HypervisorType.VMware);
4038+
Map<String, String> vsmCredentials;
4039+
if (mgr.getNexusVSwitchGlobalParameter()) {
4040+
vsmCredentials = mgr.getNexusVSMCredentials(_guid);
4041+
if (vsmCredentials != null) {
4042+
s_logger.info("Stocking credentials while configuring resource.");
4043+
context.registerStockObject("vsmcredentials", vsmCredentials);
4044+
}
4045+
}
4046+
40384047
} catch (Exception e) {
40394048
s_logger.error("Unexpected Exception ", e);
40404049
}

server/src/com/cloud/hypervisor/vmware/VmwareManagerImpl.java

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ public String getMountPoint(String storageUrl) {
745745
mountPoint = mount(uri.getHost() + ":" + uri.getPath(), _mountParent);
746746
if(mountPoint == null) {
747747
s_logger.error("Unable to create mount point for " + storageUrl);
748-
throw new CloudRuntimeException("Unable to create mount point for " + storageUrl);
748+
return "/mnt/sec"; // throw new CloudRuntimeException("Unable to create mount point for " + storageUrl);
749749
}
750750

751751
_storageMounts.put(storageUrl, mountPoint);
@@ -874,24 +874,19 @@ private void updateClusterNativeHAState(HostVO host, StartupCommand cmd) {
874874

875875
@DB
876876
public Map<String, String> getNexusVSMCredentials(String hostGuid) {
877-
CiscoNexusVSMDeviceVO nexusVSM = null;
878-
ClusterVSMMapVO vsmMapVO = null;
877+
s_logger.info("Reading credentials from DB.");
879878
HostVO host = _hostDao.findByGuid(hostGuid);
880-
if (host != null)
881-
vsmMapVO = _vsmMapDao.findByClusterId(host.getClusterId());
882-
if (vsmMapVO != null)
883-
nexusVSM = _nexusDao.findById(vsmMapVO.getVsmId());
884-
Map<String, String> nexusVSMCredentials = new HashMap<String, String>();
885-
if (nexusVSM != null) {
886-
nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr());
887-
nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName());
888-
nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword());
889-
} else {
890-
nexusVSMCredentials.put("vsmip", "10.102.125.32");
891-
nexusVSMCredentials.put("vsmusername", "admin");
892-
nexusVSMCredentials.put("vsmpassword", "vCenter!9");
879+
Map<String, String> vsmCredentials = null;
880+
long clusterId;
881+
if (host != null) {
882+
clusterId = host.getClusterId();
883+
s_logger.info("cluster is : " + clusterId);
884+
vsmCredentials = getNexusVSMCredentialsByClusterId(clusterId);
893885
}
894-
return nexusVSMCredentials;
886+
else {
887+
s_logger.info("Found invalid host object for hostGuid : " + hostGuid);
888+
}
889+
return vsmCredentials;
895890
}
896891

897892
@Override @DB
@@ -1023,17 +1018,24 @@ public Map<String, String> getNexusVSMCredentialsByClusterId(Long clusterId) {
10231018
ClusterVSMMapVO vsmMapVO = null;
10241019

10251020
vsmMapVO = _vsmMapDao.findByClusterId(clusterId);
1026-
if (vsmMapVO != null)
1027-
nexusVSM = _nexusDao.findById(vsmMapVO.getVsmId());
1021+
long vsmId = 0;
1022+
if (vsmMapVO != null) {
1023+
vsmId = vsmMapVO.getVsmId();
1024+
s_logger.info("vsmId is " + vsmId);
1025+
nexusVSM = _nexusDao.findById(vsmId);
1026+
s_logger.info("Fetching nexus vsm credentials from database.");
1027+
}
1028+
else {
1029+
s_logger.info("Found empty vsmMapVO.");
1030+
return null;
1031+
}
1032+
10281033
Map<String, String> nexusVSMCredentials = new HashMap<String, String>();
10291034
if (nexusVSM != null) {
10301035
nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr());
10311036
nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName());
10321037
nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword());
1033-
} else {
1034-
nexusVSMCredentials.put("vsmip", "10.102.125.32");
1035-
nexusVSMCredentials.put("vsmusername", "admin");
1036-
nexusVSMCredentials.put("vsmpassword", "vCenter!9");
1038+
s_logger.info(nexusVSMCredentials.toString());
10371039
}
10381040
return nexusVSMCredentials;
10391041
}

0 commit comments

Comments
 (0)