mirror of https://github.com/apache/cloudstack.git
add nsxresource
This commit is contained in:
parent
bc8504952b
commit
5ef6ac103f
|
|
@ -810,7 +810,9 @@ public class ApiConstants {
|
|||
public static final String NICIRA_NVP_L2_GATEWAYSERVICE_UUID = "l2gatewayserviceuuid";
|
||||
public static final String NSX_LOGICAL_SWITCH = "nsxlogicalswitch";
|
||||
public static final String NSX_LOGICAL_SWITCH_PORT = "nsxlogicalswitchport";
|
||||
public static final String NSX_CONTROLLER_ID = "nsxcontrollerid";
|
||||
public static final String NSX_PROVIDER_HOSTNAME = "nsxproviderhostname";
|
||||
public static final String NSX_PROVIDER_PORT = "nsxproviderport";
|
||||
|
||||
public static final String S3_ACCESS_KEY = "accesskey";
|
||||
public static final String S3_SECRET_KEY = "secretkey";
|
||||
public static final String S3_END_POINT = "endpoint";
|
||||
|
|
|
|||
|
|
@ -17,16 +17,21 @@
|
|||
package com.cloud.network.dao;
|
||||
|
||||
import com.cloud.network.element.NsxProviderVO;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@DB()
|
||||
public class NsxProviderDaoImpl extends GenericDaoBase<NsxProviderVO, Long>
|
||||
implements NsxProviderDao {
|
||||
|
||||
final SearchBuilder<NsxProviderVO> allFieldsSearch;
|
||||
|
||||
public NsxProviderDaoImpl() {
|
||||
super();
|
||||
allFieldsSearch = createSearchBuilder();
|
||||
|
|
@ -48,11 +53,13 @@ public class NsxProviderDaoImpl extends GenericDaoBase<NsxProviderVO, Long>
|
|||
}
|
||||
@Override
|
||||
public NsxProviderVO findByZoneId(long zoneId) {
|
||||
return null;
|
||||
SearchCriteria<NsxProviderVO> sc = allFieldsSearch.create();
|
||||
sc.setParameters("zone_id", zoneId);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<NsxProviderVO> findAll() {
|
||||
return null;
|
||||
return listAll();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,9 @@ public class NsxProviderVO implements NsxProvider {
|
|||
@Column(name = "edge_cluster")
|
||||
private String edgeCluster;
|
||||
|
||||
public NsxProviderVO() {
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public NsxProviderVO( long zoneId,String providerName, String hostname, String username, String password, String tier0Gateway, String edgeCluster) {
|
||||
this.zoneId = zoneId;
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@
|
|||
<bean id="nicIpAliasDaoImpl" class="com.cloud.vm.dao.NicIpAliasDaoImpl" />
|
||||
<bean id="objectInDataStoreDaoImpl" class="org.apache.cloudstack.storage.db.ObjectInDataStoreDaoImpl" />
|
||||
<bean id="ovsProviderDaoImpl" class="com.cloud.network.dao.OvsProviderDaoImpl" />
|
||||
<bean id="nsxProviderDao" class="com.cloud.network.dao.NsxProviderDaoImpl" />
|
||||
<bean id="nsxControllerDaoImpl" class="com.cloud.network.dao.NsxProviderDaoImpl" />
|
||||
<bean id="tungstenControllerDaoImpl" class="com.cloud.network.dao.TungstenProviderDaoImpl"/>
|
||||
<bean id="physicalNetworkDaoImpl" class="com.cloud.network.dao.PhysicalNetworkDaoImpl" />
|
||||
<bean id="physicalNetworkIsolationMethodDaoImpl" class="com.cloud.network.dao.PhysicalNetworkIsolationMethodDaoImpl" />
|
||||
|
|
|
|||
|
|
@ -41,5 +41,20 @@
|
|||
<artifactId>nsx-gpm-java-sdk</artifactId>
|
||||
<version>4.1.0.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vmware</groupId>
|
||||
<artifactId>nsx-policy-java-sdk</artifactId>
|
||||
<version>4.1.0.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vmware.vapi</groupId>
|
||||
<artifactId>vapi-authentication</artifactId>
|
||||
<version>2.40.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vmware.vapi</groupId>
|
||||
<artifactId>vapi-authentication</artifactId>
|
||||
<version>2.37.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -50,9 +50,12 @@ public class AddNsxControllerCmd extends BaseCmd {
|
|||
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "NSX controller / provider name")
|
||||
private String name;
|
||||
|
||||
@Parameter(name = ApiConstants.TUNGSTEN_PROVIDER_HOSTNAME, type = CommandType.STRING, required = true, description = "NSX controller hostname / IP address")
|
||||
@Parameter(name = ApiConstants.NSX_PROVIDER_HOSTNAME, type = CommandType.STRING, required = true, description = "NSX controller hostname / IP address")
|
||||
private String hostname;
|
||||
|
||||
// TODO: May not be required
|
||||
@Parameter(name = ApiConstants.NSX_PROVIDER_PORT, type = CommandType.STRING, description = "NSX controller port")
|
||||
private String port;
|
||||
@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, required = true, description = "Username to log into NSX controller")
|
||||
private String username;
|
||||
@Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, required = true, description = "Password to login into NSX controller")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,122 @@
|
|||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.resource;
|
||||
|
||||
import com.cloud.agent.IAgentControl;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.PingCommand;
|
||||
import com.cloud.agent.api.StartupCommand;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.vmware.vapi.cis.authn.SecurityContextFactory;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.util.Map;
|
||||
|
||||
public class NsxResource implements ServerResource {
|
||||
private static final Logger s_logger = Logger.getLogger(NsxResource.class);
|
||||
private String name;
|
||||
protected String hostname;
|
||||
protected String username;
|
||||
protected String password;
|
||||
protected String guid;
|
||||
protected String tier0Gateway;
|
||||
protected String edgeCluster;
|
||||
|
||||
@Override
|
||||
public Host.Type getType() {
|
||||
return Host.Type.Routing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
return new StartupCommand[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer executeRequest(Command cmd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnected() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAgentControl getAgentControl() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAgentControl(IAgentControl agentControl) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfigParams(Map<String, Object> params) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getConfigParams() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRunLevel() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRunLevel(int level) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,9 @@ import com.amazonaws.util.CollectionUtils;
|
|||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.host.DetailVO;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.dao.HostDetailsDao;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Networks;
|
||||
import com.cloud.network.NsxProvider;
|
||||
|
|
@ -29,6 +32,7 @@ import com.cloud.network.dao.PhysicalNetworkDao;
|
|||
import com.cloud.network.dao.PhysicalNetworkVO;
|
||||
import com.cloud.network.dao.NetworkVO;
|
||||
import com.cloud.network.element.NsxProviderVO;
|
||||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.db.TransactionCallback;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
|
@ -36,11 +40,11 @@ import org.apache.cloudstack.api.command.ListNsxControllersCmd;
|
|||
import org.apache.cloudstack.api.BaseResponse;
|
||||
import org.apache.cloudstack.api.command.AddNsxControllerCmd;
|
||||
import org.apache.cloudstack.api.response.NsxControllerResponse;
|
||||
import org.apache.cloudstack.resource.NsxResource;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.util.*;
|
||||
|
||||
public class NsxProviderServiceImpl implements NsxProviderService {
|
||||
|
||||
|
|
@ -52,17 +56,57 @@ public class NsxProviderServiceImpl implements NsxProviderService {
|
|||
PhysicalNetworkDao physicalNetworkDao;
|
||||
@Inject
|
||||
NetworkDao networkDao;
|
||||
@Inject
|
||||
ResourceManager resourceManager;
|
||||
@Inject
|
||||
HostDetailsDao hostDetailsDao;
|
||||
|
||||
@Override
|
||||
public NsxProvider addProvider(AddNsxControllerCmd cmd) {
|
||||
NsxProviderVO nsxProvider = Transaction.execute((TransactionCallback<NsxProviderVO>) status -> {
|
||||
NsxProviderVO nsxProviderVO = new NsxProviderVO(cmd.getZoneId(), cmd.getName(), cmd.getHostname(),
|
||||
cmd.getUsername(), cmd.getPassword(),
|
||||
cmd.getTier0Gateway(), cmd.getEdgeCluster());
|
||||
nsxProviderDao.persist(nsxProviderVO);
|
||||
return nsxProviderVO;
|
||||
});
|
||||
return null;
|
||||
Long zoneId = cmd.getZoneId();
|
||||
String name = cmd.getName();
|
||||
String hostname = cmd.getHostname();
|
||||
String username = cmd.getUsername();
|
||||
String password = cmd.getPassword();
|
||||
String tier0Gateway = cmd.getTier0Gateway();
|
||||
String edgeCluster = cmd.getEdgeCluster();
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("guid", UUID.randomUUID().toString());
|
||||
params.put("zoneId", zoneId.toString());
|
||||
params.put("name", name);
|
||||
params.put("hostname", hostname);
|
||||
params.put("username", username);
|
||||
params.put("password", password);
|
||||
params.put("tier0Gateway", tier0Gateway);
|
||||
params.put("edgeCluster", edgeCluster);
|
||||
|
||||
Map<String, Object> hostdetails = new HashMap<>(params);
|
||||
NsxProvider nsxProvider;
|
||||
|
||||
NsxResource nsxResource = new NsxResource();
|
||||
try {
|
||||
nsxResource.configure(hostname, hostdetails);
|
||||
final Host host = resourceManager.addHost(zoneId, nsxResource, nsxResource.getType(), params);
|
||||
if (host != null) {
|
||||
nsxProvider = Transaction.execute((TransactionCallback<NsxProviderVO>) status -> {
|
||||
NsxProviderVO nsxProviderVO = new NsxProviderVO(zoneId, name, hostname,
|
||||
username, password, tier0Gateway, edgeCluster);
|
||||
nsxProviderDao.persist(nsxProviderVO);
|
||||
|
||||
DetailVO detail = new DetailVO(host.getId(), "nsxcontrollerid",
|
||||
String.valueOf(nsxProviderVO.getId()));
|
||||
hostDetailsDao.persist(detail);
|
||||
|
||||
return nsxProviderVO;
|
||||
});
|
||||
} else {
|
||||
throw new CloudRuntimeException("Failed to add NSX controller due to internal error.");
|
||||
}
|
||||
} catch (ConfigurationException e) {
|
||||
throw new CloudRuntimeException(e.getMessage());
|
||||
}
|
||||
return nsxProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue