Merge pull request #1494 from nlivens/master_nuage

Remodeling of Nuage VSP Plugin + CLOUDSTACK-9294Hi all,

We've remodeled the Nuage VSP plugin to use the same model as VMWare is using (non-OSS). Before, we had a runtime dependency to the Nuage Client, this has been changed to a compile-time dependency instead because of multiple reasons (build management, readability, maintainability, ...)

We've adapted the code so it now uses model objects defined in the Nuage client instead of passing a list of parameters to the Nuage client. This is a lot more readable, and a lot more maintainable.

I've had a chat with @DaanHoogland about this approach, and he told me that ACS is trying to move away from the whole non-OSS approach. We're looking into the Juniper approach, we would set up a custom maven repository which would host the required dependencies for the Nuage VSP plugin.

Any remarks or suggestions are always welcome :)

* pr/1494:
  Nuage VSP : Extending Marvin test coverage
  Nuage VSP : Fix for NPE while cleaning up account when there are still resources belonging to that account
  CLOUDSTACK-9294 : Make sure to remove VR from VSD when removing the VPC
  CLOUDSTACK-9242 : Remodel Nuage VSP plugin

Signed-off-by: Will Stevens <williamstevens@gmail.com>
This commit is contained in:
Will Stevens 2016-05-25 22:58:10 -04:00
commit 05a7beccfe
51 changed files with 1847 additions and 3286 deletions

View File

@ -156,4 +156,6 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long> {
List<DomainRouterVO> listRunningByDataCenter(long dcId);
List<DomainRouterVO> listStopped(long networkId);
List<DomainRouterVO> listIncludingRemovedByVpcId(long vpcId);
}

View File

@ -432,4 +432,12 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
sc.setParameters("states", State.Stopped);
return listBy(sc);
}
@Override
public List<DomainRouterVO> listIncludingRemovedByVpcId(long vpcId) {
SearchCriteria<DomainRouterVO> sc = VpcSearch.create();
sc.setParameters("vpcId", vpcId);
sc.setParameters("role", Role.VIRTUAL_ROUTER);
return listIncludingRemovedBy(sc);
}
}

View File

@ -28,11 +28,17 @@
<version>4.9.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<repositories>
<repository>
<id>nuage-vsp</id>
<url>http://cs.mv.nuagenetworks.net/releases/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${cs.commons-lang3.version}</version>
<groupId>net.nuage.vsp</groupId>
<artifactId>nuage-vsp-acs-client</artifactId>
<version>3.2.8.0</version>
</dependency>
</dependencies>
<build>

View File

@ -37,5 +37,5 @@
<property name="name" value="NuageVspElement" />
</bean>
<bean id="NuageVspManager" class="com.cloud.network.manager.NuageVspManagerImpl" />
<bean id="NuageVspSync" class="com.cloud.network.sync.NuageVspSyncImpl" />
<bean id="NuageVspEntityBuilder" class="com.cloud.util.NuageVspEntityBuilder" />
</beans>

View File

@ -1,60 +0,0 @@
//
// 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 com.cloud.agent.api;
public class VspResourceAnswer extends Answer {
private String _resourceInfo;
public VspResourceAnswer(Command cmd, String resourceInfo, String details) {
super(cmd, true, details);
this._resourceInfo = resourceInfo;
}
public VspResourceAnswer(VspResourceCommand cmd, boolean success, String details) {
super(cmd, success, details);
}
public VspResourceAnswer(VspResourceCommand cmd, Exception e) {
super(cmd, e);
}
public String getResourceInfo() {
return this._resourceInfo;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VspResourceAnswer that = (VspResourceAnswer) o;
if (_resourceInfo != null ? !_resourceInfo.equals(that._resourceInfo) : that._resourceInfo != null)
return false;
return true;
}
@Override
public int hashCode() {
return _resourceInfo != null ? _resourceInfo.hashCode() : 0;
}
}

View File

@ -1,119 +0,0 @@
//
// 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 com.cloud.agent.api;
public class VspResourceCommand extends Command {
private final String _method;
private final String _resource;
private final String _resourceId;
private final String _childResource;
private final Object _entityDetails;
private final String _resourceFilter;
private final String _proxyUserUuid;
private final String _proxyUserDomainuuid;
public VspResourceCommand(String method, String resource, String resourceId, String childResource, Object entityDetails, String resourceFilter, String proxyUserUuid,
String proxyUserDomainuuid) {
super();
this._method = method;
this._resource = resource;
this._resourceId = resourceId;
this._childResource = childResource;
this._entityDetails = entityDetails;
this._resourceFilter = resourceFilter;
this._proxyUserUuid = proxyUserUuid;
this._proxyUserDomainuuid = proxyUserDomainuuid;
}
public String getRequestType() {
return _method;
}
public String getResource() {
return _resource;
}
public String getResourceId() {
return _resourceId;
}
public String getChildResource() {
return _childResource;
}
public Object getEntityDetails() {
return _entityDetails;
}
public String getResourceFilter() {
return _resourceFilter;
}
public String getProxyUserUuid() {
return _proxyUserUuid;
}
public String getProxyUserDomainuuid() {
return _proxyUserDomainuuid;
}
@Override
public boolean executeInSequence() {
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VspResourceCommand that = (VspResourceCommand) o;
if (_childResource != null ? !_childResource.equals(that._childResource) : that._childResource != null)
return false;
if (_entityDetails != null ? !_entityDetails.equals(that._entityDetails) : that._entityDetails != null)
return false;
if (_method != null ? !_method.equals(that._method) : that._method != null) return false;
if (_proxyUserDomainuuid != null ? !_proxyUserDomainuuid.equals(that._proxyUserDomainuuid) : that._proxyUserDomainuuid != null)
return false;
if (_proxyUserUuid != null ? !_proxyUserUuid.equals(that._proxyUserUuid) : that._proxyUserUuid != null)
return false;
if (_resource != null ? !_resource.equals(that._resource) : that._resource != null) return false;
if (_resourceFilter != null ? !_resourceFilter.equals(that._resourceFilter) : that._resourceFilter != null)
return false;
if (_resourceId != null ? !_resourceId.equals(that._resourceId) : that._resourceId != null) return false;
return true;
}
@Override
public int hashCode() {
int result = _method != null ? _method.hashCode() : 0;
result = 31 * result + (_resource != null ? _resource.hashCode() : 0);
result = 31 * result + (_resourceId != null ? _resourceId.hashCode() : 0);
result = 31 * result + (_childResource != null ? _childResource.hashCode() : 0);
result = 31 * result + (_entityDetails != null ? _entityDetails.hashCode() : 0);
result = 31 * result + (_resourceFilter != null ? _resourceFilter.hashCode() : 0);
result = 31 * result + (_proxyUserUuid != null ? _proxyUserUuid.hashCode() : 0);
result = 31 * result + (_proxyUserDomainuuid != null ? _proxyUserDomainuuid.hashCode() : 0);
return result;
}
}

View File

@ -19,173 +19,43 @@
package com.cloud.agent.api.element;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
import net.nuage.vsp.acs.client.api.model.VspAclRule;
import net.nuage.vsp.acs.client.api.model.VspNetwork;
import java.util.List;
import java.util.Map;
public class ApplyAclRuleVspCommand extends Command {
private final boolean _networkAcl;
private final String _networkUuid;
private final String _networkDomainUuid;
private final String _vpcOrSubnetUuid;
private final String _networkName;
private final boolean _isL2Network;
private final List<Map<String, Object>> _aclRules;
private final long _networkId;
private final boolean _egressDefaultPolicy;
private final Boolean _acsIngressAcl;
private final VspAclRule.ACLType _aclType;
private final VspNetwork _network;
private final List<VspAclRule> _aclRules;
private final boolean _networkReset;
private final String _domainTemplateName;
private ApplyAclRuleVspCommand(boolean networkAcl, String networkUuid, String networkDomainUuid, String vpcOrSubnetUuid, String networkName, boolean isL2Network,
List<Map<String, Object>> aclRules, long networkId, boolean egressDefaultPolicy, Boolean acsIngressAcl, boolean networkReset, String domainTemplateName) {
public ApplyAclRuleVspCommand(VspAclRule.ACLType aclType, VspNetwork network, List<VspAclRule> aclRules, boolean networkReset) {
super();
this._networkAcl = networkAcl;
this._networkUuid = networkUuid;
this._networkDomainUuid = networkDomainUuid;
this._vpcOrSubnetUuid = vpcOrSubnetUuid;
this._networkName = networkName;
this._isL2Network = isL2Network;
this._aclType = aclType;
this._network = network;
this._aclRules = aclRules;
this._networkId = networkId;
this._egressDefaultPolicy = egressDefaultPolicy;
this._acsIngressAcl = acsIngressAcl;
this._networkReset = networkReset;
this._domainTemplateName = domainTemplateName;
}
public boolean isNetworkAcl() {
return _networkAcl;
public VspAclRule.ACLType getAclType() {
return _aclType;
}
public String getNetworkUuid() {
return _networkUuid;
public VspNetwork getNetwork() {
return _network;
}
public String getNetworkDomainUuid() {
return _networkDomainUuid;
}
public String getVpcOrSubnetUuid() {
return _vpcOrSubnetUuid;
}
public String getNetworkName() {
return _networkName;
}
public boolean isL2Network() {
return _isL2Network;
}
public List<Map<String, Object>> getAclRules() {
public List<VspAclRule> getAclRules() {
return _aclRules;
}
public long getNetworkId() {
return _networkId;
}
public boolean isEgressDefaultPolicy() {
return _egressDefaultPolicy;
}
public Boolean getAcsIngressAcl() {
return _acsIngressAcl;
}
public boolean isNetworkReset() {
return _networkReset;
}
public String getDomainTemplateName() {
return _domainTemplateName;
}
public static class Builder implements CmdBuilder<ApplyAclRuleVspCommand> {
private boolean _networkAcl;
private String _networkUuid;
private String _networkDomainUuid;
private String _vpcOrSubnetUuid;
private String _networkName;
private boolean _isL2Network;
private List<Map<String, Object>> _aclRules;
private long _networkId;
private boolean _egressDefaultPolicy;
private Boolean _acsIngressAcl;
private boolean _networkReset;
private String _domainTemplateName;
public Builder networkAcl(boolean networkAcl) {
this._networkAcl = networkAcl;
return this;
}
public Builder networkUuid(String networkUuid) {
this._networkUuid = networkUuid;
return this;
}
public Builder networkDomainUuid(String networkDomainUuid) {
this._networkDomainUuid = networkDomainUuid;
return this;
}
public Builder vpcOrSubnetUuid(String vpcOrSubnetUuid) {
this._vpcOrSubnetUuid = vpcOrSubnetUuid;
return this;
}
public Builder networkName(String networkName) {
this._networkName = networkName;
return this;
}
public Builder isL2Network(boolean isL2Network) {
this._isL2Network = isL2Network;
return this;
}
public Builder aclRules(List<Map<String, Object>> aclRules) {
this._aclRules = aclRules;
return this;
}
public Builder networkId(long networkId) {
this._networkId = networkId;
return this;
}
public Builder egressDefaultPolicy(boolean egressDefaultPolicy) {
this._egressDefaultPolicy = egressDefaultPolicy;
return this;
}
public Builder acsIngressAcl(Boolean acsIngressAcl) {
this._acsIngressAcl = acsIngressAcl;
return this;
}
public Builder networkReset(boolean networkReset) {
this._networkReset = networkReset;
return this;
}
public Builder domainTemplateName(String domainTemplateName) {
this._domainTemplateName = domainTemplateName;
return this;
}
@Override
public ApplyAclRuleVspCommand build() {
return new ApplyAclRuleVspCommand(_networkAcl, _networkUuid, _networkDomainUuid, _vpcOrSubnetUuid, _networkName, _isL2Network, _aclRules,
_networkId, _egressDefaultPolicy, _acsIngressAcl, _networkReset, _domainTemplateName);
}
}
@Override
public boolean executeInSequence() {
return false;
@ -199,22 +69,10 @@ public class ApplyAclRuleVspCommand extends Command {
ApplyAclRuleVspCommand that = (ApplyAclRuleVspCommand) o;
if (_egressDefaultPolicy != that._egressDefaultPolicy) return false;
if (_isL2Network != that._isL2Network) return false;
if (_networkAcl != that._networkAcl) return false;
if (_networkId != that._networkId) return false;
if (_networkReset != that._networkReset) return false;
if (_aclRules != null ? !_aclRules.equals(that._aclRules) : that._aclRules != null) return false;
if (_acsIngressAcl != null ? !_acsIngressAcl.equals(that._acsIngressAcl) : that._acsIngressAcl != null)
return false;
if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
return false;
if (_networkDomainUuid != null ? !_networkDomainUuid.equals(that._networkDomainUuid) : that._networkDomainUuid != null)
return false;
if (_networkName != null ? !_networkName.equals(that._networkName) : that._networkName != null) return false;
if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
if (_vpcOrSubnetUuid != null ? !_vpcOrSubnetUuid.equals(that._vpcOrSubnetUuid) : that._vpcOrSubnetUuid != null)
return false;
if (_aclType != that._aclType) return false;
if (_network != null ? !_network.equals(that._network) : that._network != null) return false;
return true;
}
@ -222,18 +80,10 @@ public class ApplyAclRuleVspCommand extends Command {
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_networkAcl ? 1 : 0);
result = 31 * result + (_networkUuid != null ? _networkUuid.hashCode() : 0);
result = 31 * result + (_networkDomainUuid != null ? _networkDomainUuid.hashCode() : 0);
result = 31 * result + (_vpcOrSubnetUuid != null ? _vpcOrSubnetUuid.hashCode() : 0);
result = 31 * result + (_networkName != null ? _networkName.hashCode() : 0);
result = 31 * result + (_isL2Network ? 1 : 0);
result = 31 * result + (_aclType != null ? _aclType.hashCode() : 0);
result = 31 * result + (_network != null ? _network.hashCode() : 0);
result = 31 * result + (_aclRules != null ? _aclRules.hashCode() : 0);
result = 31 * result + (int) (_networkId ^ (_networkId >>> 32));
result = 31 * result + (_egressDefaultPolicy ? 1 : 0);
result = 31 * result + (_acsIngressAcl != null ? _acsIngressAcl.hashCode() : 0);
result = 31 * result + (_networkReset ? 1 : 0);
result = 31 * result + (_domainTemplateName != null ? _domainTemplateName.hashCode() : 0);
return result;
}
}

View File

@ -19,100 +19,31 @@
package com.cloud.agent.api.element;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
import net.nuage.vsp.acs.client.api.model.VspNetwork;
import net.nuage.vsp.acs.client.api.model.VspStaticNat;
import java.util.List;
import java.util.Map;
public class ApplyStaticNatVspCommand extends Command {
private final String _networkDomainUuid;
private final String _networkUuid;
private final String _vpcOrSubnetUuid;
private final boolean _isL3Network;
private final boolean _isVpc;
private final List<Map<String, Object>> _staticNatDetails;
private final VspNetwork _network;
private final List<VspStaticNat> _staticNatDetails;
private ApplyStaticNatVspCommand(String networkDomainUuid, String networkUuid, String vpcOrSubnetUuid, boolean isL3Network, boolean isVpc,
List<Map<String, Object>> staticNatDetails) {
public ApplyStaticNatVspCommand(VspNetwork network, List<VspStaticNat> staticNatDetails) {
super();
this._networkDomainUuid = networkDomainUuid;
this._networkUuid = networkUuid;
this._vpcOrSubnetUuid = vpcOrSubnetUuid;
this._isL3Network = isL3Network;
this._isVpc = isVpc;
this._network = network;
this._staticNatDetails = staticNatDetails;
}
public String getNetworkDomainUuid() {
return _networkDomainUuid;
public VspNetwork getNetwork() {
return _network;
}
public String getNetworkUuid() {
return _networkUuid;
}
public String getVpcOrSubnetUuid() {
return _vpcOrSubnetUuid;
}
public boolean isL3Network() {
return _isL3Network;
}
public boolean isVpc() {
return _isVpc;
}
public List<Map<String, Object>> getStaticNatDetails() {
public List<VspStaticNat> getStaticNatDetails() {
return _staticNatDetails;
}
public static class Builder implements CmdBuilder<ApplyStaticNatVspCommand> {
private String _networkDomainUuid;
private String _networkUuid;
private String _vpcOrSubnetUuid;
private boolean _isL3Network;
private boolean _isVpc;
private List<Map<String, Object>> _staticNatDetails;
public Builder networkDomainUuid(String networkDomainUuid) {
this._networkDomainUuid = networkDomainUuid;
return this;
}
public Builder networkUuid(String networkUuid) {
this._networkUuid = networkUuid;
return this;
}
public Builder vpcOrSubnetUuid(String vpcOrSubnetUuid) {
this._vpcOrSubnetUuid = vpcOrSubnetUuid;
return this;
}
public Builder isL3Network(boolean isL3Network) {
this._isL3Network = isL3Network;
return this;
}
public Builder isVpc(boolean isVpc) {
this._isVpc = isVpc;
return this;
}
public Builder staticNatDetails(List<Map<String, Object>> staticNatDetails) {
this._staticNatDetails = staticNatDetails;
return this;
}
@Override
public ApplyStaticNatVspCommand build() {
return new ApplyStaticNatVspCommand(_networkDomainUuid, _networkUuid, _vpcOrSubnetUuid, _isL3Network, _isVpc, _staticNatDetails);
}
}
@Override
public boolean executeInSequence() {
return false;
@ -126,15 +57,9 @@ public class ApplyStaticNatVspCommand extends Command {
ApplyStaticNatVspCommand that = (ApplyStaticNatVspCommand) o;
if (_isL3Network != that._isL3Network) return false;
if (_isVpc != that._isVpc) return false;
if (_networkDomainUuid != null ? !_networkDomainUuid.equals(that._networkDomainUuid) : that._networkDomainUuid != null)
return false;
if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
if (_network != null ? !_network.equals(that._network) : that._network != null) return false;
if (_staticNatDetails != null ? !_staticNatDetails.equals(that._staticNatDetails) : that._staticNatDetails != null)
return false;
if (_vpcOrSubnetUuid != null ? !_vpcOrSubnetUuid.equals(that._vpcOrSubnetUuid) : that._vpcOrSubnetUuid != null)
return false;
return true;
}
@ -142,11 +67,7 @@ public class ApplyStaticNatVspCommand extends Command {
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_networkDomainUuid != null ? _networkDomainUuid.hashCode() : 0);
result = 31 * result + (_networkUuid != null ? _networkUuid.hashCode() : 0);
result = 31 * result + (_vpcOrSubnetUuid != null ? _vpcOrSubnetUuid.hashCode() : 0);
result = 31 * result + (_isL3Network ? 1 : 0);
result = 31 * result + (_isVpc ? 1 : 0);
result = 31 * result + (_network != null ? _network.hashCode() : 0);
result = 31 * result + (_staticNatDetails != null ? _staticNatDetails.hashCode() : 0);
return result;
}

View File

@ -19,220 +19,48 @@
package com.cloud.agent.api.element;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
import net.nuage.vsp.acs.client.api.model.VspAclRule;
import net.nuage.vsp.acs.client.api.model.VspNetwork;
import java.util.List;
import java.util.Map;
public class ImplementVspCommand extends Command {
private final long _networkId;
private final String _networkDomainUuid;
private final String _networkUuid;
private final String _networkName;
private final String _vpcOrSubnetUuid;
private final boolean _isL2Network;
private final boolean _isL3Network;
private final boolean _isVpc;
private final boolean _isShared;
private final String _domainTemplateName;
private final boolean _isFirewallServiceSupported;
private final VspNetwork _network;
private final List<String> _dnsServers;
private final List<Map<String, Object>> _ingressFirewallRules;
private final List<Map<String, Object>> _egressFirewallRules;
private final List<String> _acsFipUuid;
private final boolean _egressDefaultPolicy;
private final List<VspAclRule> _ingressFirewallRules;
private final List<VspAclRule> _egressFirewallRules;
private final List<String> _floatingIpUuids;
private ImplementVspCommand(long networkId, String networkDomainUuid, String networkUuid, String networkName, String vpcOrSubnetUuid, boolean isL2Network, boolean isL3Network,
boolean isVpc, boolean isShared, String domainTemplateName, boolean isFirewallServiceSupported, List<String> dnsServers, List<Map<String, Object>> ingressFirewallRules,
List<Map<String, Object>> egressFirewallRules, List<String> acsFipUuid, boolean egressDefaultPolicy) {
public ImplementVspCommand(VspNetwork network, List<String> dnsServers, List<VspAclRule> ingressFirewallRules,
List<VspAclRule> egressFirewallRules, List<String> floatingIpUuids) {
super();
this._networkId = networkId;
this._networkDomainUuid = networkDomainUuid;
this._networkUuid = networkUuid;
this._networkName = networkName;
this._vpcOrSubnetUuid = vpcOrSubnetUuid;
this._isL2Network = isL2Network;
this._isL3Network = isL3Network;
this._isVpc = isVpc;
this._isShared = isShared;
this._domainTemplateName = domainTemplateName;
this._isFirewallServiceSupported = isFirewallServiceSupported;
this._network = network;
this._dnsServers = dnsServers;
this._ingressFirewallRules = ingressFirewallRules;
this._egressFirewallRules = egressFirewallRules;
this._acsFipUuid = acsFipUuid;
this._egressDefaultPolicy = egressDefaultPolicy;
this._floatingIpUuids = floatingIpUuids;
}
public long getNetworkId() {
return _networkId;
}
public String getNetworkDomainUuid() {
return _networkDomainUuid;
}
public String getNetworkUuid() {
return _networkUuid;
}
public String getNetworkName() {
return _networkName;
}
public String getVpcOrSubnetUuid() {
return _vpcOrSubnetUuid;
}
public boolean isL2Network() {
return _isL2Network;
}
public boolean isL3Network() {
return _isL3Network;
}
public boolean isVpc() {
return _isVpc;
}
public boolean isShared() {
return _isShared;
}
public String getDomainTemplateName() {
return _domainTemplateName;
}
public boolean isFirewallServiceSupported() {
return _isFirewallServiceSupported;
public VspNetwork getNetwork() {
return _network;
}
public List<String> getDnsServers() {
return _dnsServers;
}
public List<Map<String, Object>> getIngressFirewallRules() {
public List<VspAclRule> getIngressFirewallRules() {
return _ingressFirewallRules;
}
public List<Map<String, Object>> getEgressFirewallRules() {
public List<VspAclRule> getEgressFirewallRules() {
return _egressFirewallRules;
}
public List<String> getAcsFipUuid() {
return _acsFipUuid;
}
public boolean isEgressDefaultPolicy() {
return _egressDefaultPolicy;
}
public static class Builder implements CmdBuilder<ImplementVspCommand> {
private long _networkId;
private String _networkDomainUuid;
private String _networkUuid;
private String _networkName;
private String _vpcOrSubnetUuid;
private boolean _isL2Network;
private boolean _isL3Network;
private boolean _isVpc;
private boolean _isShared;
private String _domainTemplateName;
private boolean _isFirewallServiceSupported;
private List<String> _dnsServers;
private List<Map<String, Object>> _ingressFirewallRules;
private List<Map<String, Object>> _egressFirewallRules;
private List<String> _acsFipUuid;
private boolean _egressDefaultPolicy;
public Builder networkId(long networkId) {
this._networkId = networkId;
return this;
}
public Builder networkDomainUuid(String networkDomainUuid) {
this._networkDomainUuid = networkDomainUuid;
return this;
}
public Builder networkUuid(String networkUuid) {
this._networkUuid = networkUuid;
return this;
}
public Builder networkName(String networkName) {
this._networkName = networkName;
return this;
}
public Builder vpcOrSubnetUuid(String vpcOrSubnetUuid) {
this._vpcOrSubnetUuid = vpcOrSubnetUuid;
return this;
}
public Builder isL2Network(boolean isL2Network) {
this._isL2Network = isL2Network;
return this;
}
public Builder isL3Network(boolean isL3Network) {
this._isL3Network = isL3Network;
return this;
}
public Builder isVpc(boolean isVpc) {
this._isVpc = isVpc;
return this;
}
public Builder isShared(boolean isShared) {
this._isShared = isShared;
return this;
}
public Builder domainTemplateName(String domainTemplateName) {
this._domainTemplateName = domainTemplateName;
return this;
}
public Builder isFirewallServiceSupported(boolean isFirewallServiceSupported) {
this._isFirewallServiceSupported = isFirewallServiceSupported;
return this;
}
public Builder dnsServers(List<String> dnsServers) {
this._dnsServers = dnsServers;
return this;
}
public Builder ingressFirewallRules(List<Map<String, Object>> ingressFirewallRules) {
this._ingressFirewallRules = ingressFirewallRules;
return this;
}
public Builder egressFirewallRules(List<Map<String, Object>> egressFirewallRules) {
this._egressFirewallRules = egressFirewallRules;
return this;
}
public Builder acsFipUuid(List<String> acsFipUuid) {
this._acsFipUuid = acsFipUuid;
return this;
}
public Builder egressDefaultPolicy(boolean egressDefaultPolicy) {
this._egressDefaultPolicy = egressDefaultPolicy;
return this;
}
@Override
public ImplementVspCommand build() {
return new ImplementVspCommand(_networkId, _networkDomainUuid, _networkUuid, _networkName, _vpcOrSubnetUuid, _isL2Network, _isL3Network, _isVpc, _isShared,
_domainTemplateName, _isFirewallServiceSupported, _dnsServers, _ingressFirewallRules, _egressFirewallRules, _acsFipUuid, _egressDefaultPolicy);
}
public List<String> getFloatingIpUuids() {
return _floatingIpUuids;
}
@Override
@ -248,27 +76,14 @@ public class ImplementVspCommand extends Command {
ImplementVspCommand that = (ImplementVspCommand) o;
if (_egressDefaultPolicy != that._egressDefaultPolicy) return false;
if (_isFirewallServiceSupported != that._isFirewallServiceSupported) return false;
if (_isL2Network != that._isL2Network) return false;
if (_isL3Network != that._isL3Network) return false;
if (_isShared != that._isShared) return false;
if (_isVpc != that._isVpc) return false;
if (_networkId != that._networkId) return false;
if (_acsFipUuid != null ? !_acsFipUuid.equals(that._acsFipUuid) : that._acsFipUuid != null) return false;
if (_dnsServers != null ? !_dnsServers.equals(that._dnsServers) : that._dnsServers != null) return false;
if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
return false;
if (_egressFirewallRules != null ? !_egressFirewallRules.equals(that._egressFirewallRules) : that._egressFirewallRules != null)
return false;
if (_floatingIpUuids != null ? !_floatingIpUuids.equals(that._floatingIpUuids) : that._floatingIpUuids != null)
return false;
if (_ingressFirewallRules != null ? !_ingressFirewallRules.equals(that._ingressFirewallRules) : that._ingressFirewallRules != null)
return false;
if (_networkDomainUuid != null ? !_networkDomainUuid.equals(that._networkDomainUuid) : that._networkDomainUuid != null)
return false;
if (_networkName != null ? !_networkName.equals(that._networkName) : that._networkName != null) return false;
if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
if (_vpcOrSubnetUuid != null ? !_vpcOrSubnetUuid.equals(that._vpcOrSubnetUuid) : that._vpcOrSubnetUuid != null)
return false;
if (_network != null ? !_network.equals(that._network) : that._network != null) return false;
return true;
}
@ -276,22 +91,11 @@ public class ImplementVspCommand extends Command {
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (int) (_networkId ^ (_networkId >>> 32));
result = 31 * result + (_networkDomainUuid != null ? _networkDomainUuid.hashCode() : 0);
result = 31 * result + (_networkUuid != null ? _networkUuid.hashCode() : 0);
result = 31 * result + (_networkName != null ? _networkName.hashCode() : 0);
result = 31 * result + (_vpcOrSubnetUuid != null ? _vpcOrSubnetUuid.hashCode() : 0);
result = 31 * result + (_isL2Network ? 1 : 0);
result = 31 * result + (_isL3Network ? 1 : 0);
result = 31 * result + (_isVpc ? 1 : 0);
result = 31 * result + (_isShared ? 1 : 0);
result = 31 * result + (_domainTemplateName != null ? _domainTemplateName.hashCode() : 0);
result = 31 * result + (_isFirewallServiceSupported ? 1 : 0);
result = 31 * result + (_network != null ? _network.hashCode() : 0);
result = 31 * result + (_dnsServers != null ? _dnsServers.hashCode() : 0);
result = 31 * result + (_ingressFirewallRules != null ? _ingressFirewallRules.hashCode() : 0);
result = 31 * result + (_egressFirewallRules != null ? _egressFirewallRules.hashCode() : 0);
result = 31 * result + (_acsFipUuid != null ? _acsFipUuid.hashCode() : 0);
result = 31 * result + (_egressDefaultPolicy ? 1 : 0);
result = 31 * result + (_floatingIpUuids != null ? _floatingIpUuids.hashCode() : 0);
return result;
}
}

View File

@ -19,20 +19,23 @@
package com.cloud.agent.api.element;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
import java.util.List;
public class ShutDownVpcVspCommand extends Command {
private final String _domainUuid;
private final String _vpcUuid;
private final String _domainTemplateName;
private final List<String> _domainRouterUuids;
private ShutDownVpcVspCommand(String domainUuid, String vpcUuid, String domainTemplateName) {
public ShutDownVpcVspCommand(String domainUuid, String vpcUuid, String domainTemplateName, List<String> domainRouterUuids) {
super();
this._domainUuid = domainUuid;
this._vpcUuid = vpcUuid;
this._domainTemplateName = domainTemplateName;
this._domainRouterUuids = domainRouterUuids;
}
public String getDomainUuid() {
@ -47,30 +50,8 @@ public class ShutDownVpcVspCommand extends Command {
return _domainTemplateName;
}
public static class Builder implements CmdBuilder<ShutDownVpcVspCommand> {
private String _domainUuid;
private String _vpcUuid;
private String _domainTemplateName;
public Builder domainUuid(String domainUuid) {
this._domainUuid = domainUuid;
return this;
}
public Builder vpcUuid(String vpcUuid) {
this._vpcUuid = vpcUuid;
return this;
}
public Builder domainTemplateName(String domainTemplateName) {
this._domainTemplateName = domainTemplateName;
return this;
}
@Override
public ShutDownVpcVspCommand build() {
return new ShutDownVpcVspCommand(_domainUuid, _vpcUuid, _domainTemplateName);
}
public List<String> getDomainRouterUuids() {
return _domainRouterUuids;
}
@Override
@ -86,6 +67,8 @@ public class ShutDownVpcVspCommand extends Command {
ShutDownVpcVspCommand that = (ShutDownVpcVspCommand) o;
if (_domainRouterUuids != null ? !_domainRouterUuids.equals(that._domainRouterUuids) : that._domainRouterUuids != null)
return false;
if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
return false;
if (_domainUuid != null ? !_domainUuid.equals(that._domainUuid) : that._domainUuid != null) return false;
@ -100,6 +83,7 @@ public class ShutDownVpcVspCommand extends Command {
result = 31 * result + (_domainUuid != null ? _domainUuid.hashCode() : 0);
result = 31 * result + (_vpcUuid != null ? _vpcUuid.hashCode() : 0);
result = 31 * result + (_domainTemplateName != null ? _domainTemplateName.hashCode() : 0);
result = 31 * result + (_domainRouterUuids != null ? _domainRouterUuids.hashCode() : 0);
return result;
}
}

View File

@ -19,156 +19,34 @@
package com.cloud.agent.api.guru;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
import net.nuage.vsp.acs.client.api.model.VspNetwork;
import net.nuage.vsp.acs.client.api.model.VspNic;
import net.nuage.vsp.acs.client.api.model.VspVm;
public class DeallocateVmVspCommand extends Command {
private final String _networkUuid;
private final String _nicFromDdUuid;
private final String _nicMacAddress;
private final String _nicIp4Address;
private final boolean _isL3Network;
private final boolean _isSharedNetwork;
private final String _vpcUuid;
private final String _networksDomainUuid;
private final String _vmInstanceName;
private final String _vmUuid;
private final boolean _isExpungingState;
private final VspNetwork _network;
private final VspVm _vm;
private final VspNic _nic;
private DeallocateVmVspCommand(String networkUuid, String nicFromDdUuid, String nicMacAddress, String nicIp4Address, boolean isL3Network, boolean isSharedNetwork, String vpcUuid,
String networksDomainUuid, String vmInstanceName, String vmUuid, boolean isExpungingState) {
public DeallocateVmVspCommand(VspNetwork network, VspVm vm, VspNic nic) {
super();
this._networkUuid = networkUuid;
this._nicFromDdUuid = nicFromDdUuid;
this._nicMacAddress = nicMacAddress;
this._nicIp4Address = nicIp4Address;
this._isL3Network = isL3Network;
this._isSharedNetwork = isSharedNetwork;
this._vpcUuid = vpcUuid;
this._networksDomainUuid = networksDomainUuid;
this._vmInstanceName = vmInstanceName;
this._vmUuid = vmUuid;
this._isExpungingState = isExpungingState;
this._network = network;
this._vm = vm;
this._nic = nic;
}
public String getNetworkUuid() {
return _networkUuid;
public VspNetwork getNetwork() {
return this._network;
}
public String getNicFromDdUuid() {
return _nicFromDdUuid;
public VspVm getVm() {
return this._vm;
}
public String getNicMacAddress() {
return _nicMacAddress;
}
public String getNicIp4Address() {
return _nicIp4Address;
}
public boolean isL3Network() {
return _isL3Network;
}
public boolean isSharedNetwork() {
return _isSharedNetwork;
}
public String getVpcUuid() {
return _vpcUuid;
}
public String getNetworksDomainUuid() {
return _networksDomainUuid;
}
public String getVmInstanceName() {
return _vmInstanceName;
}
public String getVmUuid() {
return _vmUuid;
}
public boolean isExpungingState() {
return _isExpungingState;
}
public static class Builder implements CmdBuilder<DeallocateVmVspCommand> {
private String _networkUuid;
private String _nicFromDdUuid;
private String _nicMacAddress;
private String _nicIp4Address;
private boolean _isL3Network;
private boolean _isSharedNetwork;
private String _vpcUuid;
private String _networksDomainUuid;
private String _vmInstanceName;
private String _vmUuid;
private boolean _isExpungingState;
public Builder networkUuid(String networkUuid) {
this._networkUuid = networkUuid;
return this;
}
public Builder nicFromDbUuid(String nicFromDbUuid) {
this._nicFromDdUuid = nicFromDbUuid;
return this;
}
public Builder nicMacAddress(String nicMacAddress) {
this._nicMacAddress = nicMacAddress;
return this;
}
public Builder nicIp4Address(String nicIp4Address) {
this._nicIp4Address = nicIp4Address;
return this;
}
public Builder isL3Network(boolean isL3Network) {
this._isL3Network = isL3Network;
return this;
}
public Builder isSharedNetwork(boolean isSharedNetwork) {
this._isSharedNetwork = isSharedNetwork;
return this;
}
public Builder vpcUuid(String vpcUuid) {
this._vpcUuid = vpcUuid;
return this;
}
public Builder networksDomainUuid(String networksDomainUuid) {
this._networksDomainUuid = networksDomainUuid;
return this;
}
public Builder vmInstanceName(String vmInstanceName) {
this._vmInstanceName = vmInstanceName;
return this;
}
public Builder vmUuid(String vmUuid) {
this._vmUuid = vmUuid;
return this;
}
public Builder isExpungingState(boolean isExpungingState) {
this._isExpungingState = isExpungingState;
return this;
}
@Override
public DeallocateVmVspCommand build() {
return new DeallocateVmVspCommand(_networkUuid,_nicFromDdUuid, _nicMacAddress, _nicIp4Address, _isL3Network, _isSharedNetwork, _vpcUuid,
_networksDomainUuid, _vmInstanceName, _vmUuid, _isExpungingState);
}
public VspNic getNic() {
return this._nic;
}
@Override
@ -184,22 +62,9 @@ public class DeallocateVmVspCommand extends Command {
DeallocateVmVspCommand that = (DeallocateVmVspCommand) o;
if (_isExpungingState != that._isExpungingState) return false;
if (_isL3Network != that._isL3Network) return false;
if (_isSharedNetwork != that._isSharedNetwork) return false;
if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
if (_networksDomainUuid != null ? !_networksDomainUuid.equals(that._networksDomainUuid) : that._networksDomainUuid != null)
return false;
if (_nicFromDdUuid != null ? !_nicFromDdUuid.equals(that._nicFromDdUuid) : that._nicFromDdUuid != null)
return false;
if (_nicIp4Address != null ? !_nicIp4Address.equals(that._nicIp4Address) : that._nicIp4Address != null)
return false;
if (_nicMacAddress != null ? !_nicMacAddress.equals(that._nicMacAddress) : that._nicMacAddress != null)
return false;
if (_vmInstanceName != null ? !_vmInstanceName.equals(that._vmInstanceName) : that._vmInstanceName != null)
return false;
if (_vmUuid != null ? !_vmUuid.equals(that._vmUuid) : that._vmUuid != null) return false;
if (_vpcUuid != null ? !_vpcUuid.equals(that._vpcUuid) : that._vpcUuid != null) return false;
if (_network != null ? !_network.equals(that._network) : that._network != null) return false;
if (_nic != null ? !_nic.equals(that._nic) : that._nic != null) return false;
if (_vm != null ? !_vm.equals(that._vm) : that._vm != null) return false;
return true;
}
@ -207,17 +72,9 @@ public class DeallocateVmVspCommand extends Command {
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_networkUuid != null ? _networkUuid.hashCode() : 0);
result = 31 * result + (_nicFromDdUuid != null ? _nicFromDdUuid.hashCode() : 0);
result = 31 * result + (_nicMacAddress != null ? _nicMacAddress.hashCode() : 0);
result = 31 * result + (_nicIp4Address != null ? _nicIp4Address.hashCode() : 0);
result = 31 * result + (_isL3Network ? 1 : 0);
result = 31 * result + (_isSharedNetwork ? 1 : 0);
result = 31 * result + (_vpcUuid != null ? _vpcUuid.hashCode() : 0);
result = 31 * result + (_networksDomainUuid != null ? _networksDomainUuid.hashCode() : 0);
result = 31 * result + (_vmInstanceName != null ? _vmInstanceName.hashCode() : 0);
result = 31 * result + (_vmUuid != null ? _vmUuid.hashCode() : 0);
result = 31 * result + (_isExpungingState ? 1 : 0);
result = 31 * result + (_network != null ? _network.hashCode() : 0);
result = 31 * result + (_vm != null ? _vm.hashCode() : 0);
result = 31 * result + (_nic != null ? _nic.hashCode() : 0);
return result;
}
}

View File

@ -19,272 +19,30 @@
package com.cloud.agent.api.guru;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
import net.nuage.vsp.acs.client.api.model.VspNetwork;
import java.util.Collection;
import java.util.List;
public class ImplementNetworkVspCommand extends Command {
private final String _networkDomainName;
private final String _networkDomainPath;
private final String _networkDomainUuid;
private final String _networkAccountName;
private final String _networkAccountUuid;
private final String _networkName;
private final String _networkCidr;
private final String _networkGateway;
private final Long _networkAclId;
private final VspNetwork _network;
private final List<String> _dnsServers;
private final List<String> _gatewaySystemIds;
private final String _networkUuid;
private final boolean _isL3Network;
private final boolean _isVpc;
private final boolean _isSharedNetwork;
private final String _vpcName;
private final String _vpcUuid;
private final boolean _defaultEgressPolicy;
private final List<String[]> _ipAddressRange;
private final String _domainTemplateName;
private ImplementNetworkVspCommand(String networkDomainName, String networkDomainPath, String networkDomainUuid, String networkAccountName, String networkAccountUuid,
String networkName, String networkCidr, String networkGateway, Long networkAclId, List<String> dnsServers, List<String> gatewaySystemIds, String networkUuid,
boolean isL3Network, boolean isVpc, boolean isSharedNetwork, String vpcName, String vpcUuid, boolean defaultEgressPolicy, List<String[]> ipAddressRange,
String domainTemplateName) {
public ImplementNetworkVspCommand(VspNetwork network, List<String> dnsServers) {
super();
this._networkDomainName = networkDomainName;
this._networkDomainPath = networkDomainPath;
this._networkDomainUuid = networkDomainUuid;
this._networkAccountName = networkAccountName;
this._networkAccountUuid = networkAccountUuid;
this._networkName = networkName;
this._networkCidr = networkCidr;
this._networkGateway = networkGateway;
this._networkAclId = networkAclId;
this._network = network;
this._dnsServers = dnsServers;
this._gatewaySystemIds = gatewaySystemIds;
this._networkUuid = networkUuid;
this._isL3Network = isL3Network;
this._isVpc = isVpc;
this._isSharedNetwork = isSharedNetwork;
this._vpcName = vpcName;
this._vpcUuid = vpcUuid;
this._defaultEgressPolicy = defaultEgressPolicy;
this._ipAddressRange = ipAddressRange;
this._domainTemplateName = domainTemplateName;
}
public String getNetworkDomainName() {
return _networkDomainName;
}
public String getNetworkDomainPath() {
return _networkDomainPath;
}
public String getNetworkDomainUuid() {
return _networkDomainUuid;
}
public String getNetworkAccountName() {
return _networkAccountName;
}
public String getNetworkAccountUuid() {
return _networkAccountUuid;
}
public String getNetworkName() {
return _networkName;
}
public String getNetworkCidr() {
return _networkCidr;
}
public String getNetworkGateway() {
return _networkGateway;
}
public Long getNetworkAclId() {
return _networkAclId;
public VspNetwork getNetwork() {
return _network;
}
public List<String> getDnsServers() {
return _dnsServers;
}
public List<String> getGatewaySystemIds() {
return _gatewaySystemIds;
}
public String getNetworkUuid() {
return _networkUuid;
}
public boolean isL3Network() {
return _isL3Network;
}
public boolean isVpc() {
return _isVpc;
}
public boolean isSharedNetwork() {
return _isSharedNetwork;
}
public String getVpcName() {
return _vpcName;
}
public String getVpcUuid() {
return _vpcUuid;
}
public boolean isDefaultEgressPolicy() {
return _defaultEgressPolicy;
}
public Collection<String[]> getIpAddressRange() {
return _ipAddressRange;
}
public String getDomainTemplateName() {
return _domainTemplateName;
}
public static class Builder implements CmdBuilder<ImplementNetworkVspCommand> {
private String _networkDomainName;
private String _networkDomainPath;
private String _networkDomainUuid;
private String _networkAccountName;
private String _networkAccountUuid;
private String _networkName;
private String _networkCidr;
private String _networkGateway;
private Long _networkAclId;
private List<String> _dnsServers;
private List<String> _gatewaySystemIds;
private String _networkUuid;
private boolean _isL3Network;
private boolean _isVpc;
private boolean _isSharedNetwork;
private String _vpcName;
private String _vpcUuid;
private boolean _defaultEgressPolicy;
private List<String[]> _ipAddressRange;
private String _domainTemplateName;
public Builder networkDomainName(String networkDomainName) {
this._networkDomainName = networkDomainName;
return this;
}
public Builder networkDomainPath(String networkDomainPath) {
this._networkDomainPath = networkDomainPath;
return this;
}
public Builder networkDomainUuid(String networkDomainUuid) {
this._networkDomainUuid = networkDomainUuid;
return this;
}
public Builder networkAccountName(String networkAccountName) {
this._networkAccountName = networkAccountName;
return this;
}
public Builder networkAccountUuid(String networkAccountUuid) {
this._networkAccountUuid = networkAccountUuid;
return this;
}
public Builder networkName(String networkName) {
this._networkName = networkName;
return this;
}
public Builder networkCidr(String networkCidr) {
this._networkCidr = networkCidr;
return this;
}
public Builder networkGateway(String networkGateway) {
this._networkGateway = networkGateway;
return this;
}
public Builder networkAclId(Long networkAclId) {
this._networkAclId = networkAclId;
return this;
}
public Builder dnsServers(List<String> dnsServers) {
this._dnsServers = dnsServers;
return this;
}
public Builder gatewaySystemIds(List<String> gatewaySystemIds) {
this._gatewaySystemIds = gatewaySystemIds;
return this;
}
public Builder networkUuid(String networkUuid) {
this._networkUuid = networkUuid;
return this;
}
public Builder isL3Network(boolean isL3Network) {
this._isL3Network = isL3Network;
return this;
}
public Builder isVpc(boolean isVpc) {
this._isVpc = isVpc;
return this;
}
public Builder isSharedNetwork(boolean isSharedNetwork) {
this._isSharedNetwork = isSharedNetwork;
return this;
}
public Builder vpcName(String vpcName) {
this._vpcName = vpcName;
return this;
}
public Builder vpcUuid(String vpcUuid) {
this._vpcUuid = vpcUuid;
return this;
}
public Builder defaultEgressPolicy(boolean defaultEgressPolicy) {
this._defaultEgressPolicy = defaultEgressPolicy;
return this;
}
public Builder ipAddressRange(List<String[]> ipAddressRange) {
this._ipAddressRange = ipAddressRange;
return this;
}
public Builder domainTemplateName(String domainTemplateName) {
this._domainTemplateName = domainTemplateName;
return this;
}
@Override
public ImplementNetworkVspCommand build() {
return new ImplementNetworkVspCommand(_networkDomainName, _networkDomainPath, _networkDomainUuid, _networkAccountName, _networkAccountUuid, _networkName,
_networkCidr, _networkGateway, _networkAclId, _dnsServers, _gatewaySystemIds, _networkUuid, _isL3Network, _isVpc, _isSharedNetwork, _vpcName, _vpcUuid,
_defaultEgressPolicy, _ipAddressRange, _domainTemplateName);
}
}
@Override
public boolean executeInSequence() {
return false;
@ -298,36 +56,8 @@ public class ImplementNetworkVspCommand extends Command {
ImplementNetworkVspCommand that = (ImplementNetworkVspCommand) o;
if (_defaultEgressPolicy != that._defaultEgressPolicy) return false;
if (_isL3Network != that._isL3Network) return false;
if (_isSharedNetwork != that._isSharedNetwork) return false;
if (_isVpc != that._isVpc) return false;
if (_dnsServers != null ? !_dnsServers.equals(that._dnsServers) : that._dnsServers != null) return false;
if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
return false;
if (_gatewaySystemIds != null ? !_gatewaySystemIds.equals(that._gatewaySystemIds) : that._gatewaySystemIds != null)
return false;
if (_ipAddressRange != null ? !_ipAddressRange.equals(that._ipAddressRange) : that._ipAddressRange != null)
return false;
if (_networkAccountName != null ? !_networkAccountName.equals(that._networkAccountName) : that._networkAccountName != null)
return false;
if (_networkAccountUuid != null ? !_networkAccountUuid.equals(that._networkAccountUuid) : that._networkAccountUuid != null)
return false;
if (_networkAclId != null ? !_networkAclId.equals(that._networkAclId) : that._networkAclId != null)
return false;
if (_networkCidr != null ? !_networkCidr.equals(that._networkCidr) : that._networkCidr != null) return false;
if (_networkDomainName != null ? !_networkDomainName.equals(that._networkDomainName) : that._networkDomainName != null)
return false;
if (_networkDomainPath != null ? !_networkDomainPath.equals(that._networkDomainPath) : that._networkDomainPath != null)
return false;
if (_networkDomainUuid != null ? !_networkDomainUuid.equals(that._networkDomainUuid) : that._networkDomainUuid != null)
return false;
if (_networkGateway != null ? !_networkGateway.equals(that._networkGateway) : that._networkGateway != null)
return false;
if (_networkName != null ? !_networkName.equals(that._networkName) : that._networkName != null) return false;
if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
if (_vpcName != null ? !_vpcName.equals(that._vpcName) : that._vpcName != null) return false;
if (_vpcUuid != null ? !_vpcUuid.equals(that._vpcUuid) : that._vpcUuid != null) return false;
if (_network != null ? !_network.equals(that._network) : that._network != null) return false;
return true;
}
@ -335,26 +65,8 @@ public class ImplementNetworkVspCommand extends Command {
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_networkDomainName != null ? _networkDomainName.hashCode() : 0);
result = 31 * result + (_networkDomainPath != null ? _networkDomainPath.hashCode() : 0);
result = 31 * result + (_networkDomainUuid != null ? _networkDomainUuid.hashCode() : 0);
result = 31 * result + (_networkAccountName != null ? _networkAccountName.hashCode() : 0);
result = 31 * result + (_networkAccountUuid != null ? _networkAccountUuid.hashCode() : 0);
result = 31 * result + (_networkName != null ? _networkName.hashCode() : 0);
result = 31 * result + (_networkCidr != null ? _networkCidr.hashCode() : 0);
result = 31 * result + (_networkGateway != null ? _networkGateway.hashCode() : 0);
result = 31 * result + (_networkAclId != null ? _networkAclId.hashCode() : 0);
result = 31 * result + (_network != null ? _network.hashCode() : 0);
result = 31 * result + (_dnsServers != null ? _dnsServers.hashCode() : 0);
result = 31 * result + (_gatewaySystemIds != null ? _gatewaySystemIds.hashCode() : 0);
result = 31 * result + (_networkUuid != null ? _networkUuid.hashCode() : 0);
result = 31 * result + (_isL3Network ? 1 : 0);
result = 31 * result + (_isVpc ? 1 : 0);
result = 31 * result + (_isSharedNetwork ? 1 : 0);
result = 31 * result + (_vpcName != null ? _vpcName.hashCode() : 0);
result = 31 * result + (_vpcUuid != null ? _vpcUuid.hashCode() : 0);
result = 31 * result + (_defaultEgressPolicy ? 1 : 0);
result = 31 * result + (_ipAddressRange != null ? _ipAddressRange.hashCode() : 0);
result = 31 * result + (_domainTemplateName != null ? _domainTemplateName.hashCode() : 0);
return result;
}
}

View File

@ -19,303 +19,41 @@
package com.cloud.agent.api.guru;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
import net.nuage.vsp.acs.client.api.model.VspNetwork;
import net.nuage.vsp.acs.client.api.model.VspNic;
import net.nuage.vsp.acs.client.api.model.VspStaticNat;
import net.nuage.vsp.acs.client.api.model.VspVm;
public class ReserveVmInterfaceVspCommand extends Command {
private final String _nicUuid;
private final String _nicMacAddress;
private final String _networkUuid;
private final boolean _isL3Network;
private final boolean _isSharedNetwork;
private final String _vpcUuid;
private final String _networkDomainUuid;
private final String _networksAccountUuid;
private final boolean _isDomainRouter;
private final String _domainRouterIp;
private final String _vmInstanceName;
private final String _vmUuid;
private final String _vmUserName;
private final String _vmUserDomainName;
private final boolean _useStaticIp;
private final String _staticIp;
private final String _staticNatIpUuid;
private final String _staticNatIpAddress;
private final boolean _isStaticNatIpAllocated;
private final boolean _isOneToOneNat;
private final String _staticNatVlanUuid;
private final String _staticNatVlanGateway;
private final String _staticNatVlanNetmask;
private final VspNetwork _network;
private final VspVm _vm;
private final VspNic _nic;
private final VspStaticNat _staticNat;
private ReserveVmInterfaceVspCommand(String nicUuid, String nicMacAddress, String networkUuid, boolean isL3Network, boolean isSharedNetwork, String vpcUuid, String networkDomainUuid,
String networksAccountUuid, boolean isDomainRouter, String domainRouterIp, String vmInstanceName, String vmUuid, String vmUserName, String vmUserDomainName,
boolean useStaticIp, String staticIp, String staticNatIpUuid, String staticNatIpAddress, boolean isStaticNatIpAllocated, boolean isOneToOneNat, String staticNatVlanUuid,
String staticNatVlanGateway, String staticNatVlanNetmask) {
public ReserveVmInterfaceVspCommand(VspNetwork network, VspVm vm, VspNic nic, VspStaticNat staticNat) {
super();
this._nicUuid = nicUuid;
this._nicMacAddress = nicMacAddress;
this._networkUuid = networkUuid;
this._isL3Network = isL3Network;
this._isSharedNetwork = isSharedNetwork;
this._vpcUuid = vpcUuid;
this._networkDomainUuid = networkDomainUuid;
this._networksAccountUuid = networksAccountUuid;
this._isDomainRouter = isDomainRouter;
this._domainRouterIp = domainRouterIp;
this._vmInstanceName = vmInstanceName;
this._vmUuid = vmUuid;
this._vmUserName = vmUserName;
this._vmUserDomainName = vmUserDomainName;
this._useStaticIp = useStaticIp;
this._staticIp = staticIp;
this._staticNatIpUuid = staticNatIpUuid;
this._staticNatIpAddress = staticNatIpAddress;
this._isStaticNatIpAllocated = isStaticNatIpAllocated;
this._isOneToOneNat = isOneToOneNat;
this._staticNatVlanUuid = staticNatVlanUuid;
this._staticNatVlanGateway = staticNatVlanGateway;
this._staticNatVlanNetmask = staticNatVlanNetmask;
this._network = network;
this._vm = vm;
this._nic = nic;
this._staticNat = staticNat;
}
public String getNicUuid() {
return _nicUuid;
public VspNetwork getNetwork() {
return _network;
}
public String getNicMacAddress() {
return _nicMacAddress;
public VspVm getVm() {
return _vm;
}
public String getNetworkUuid() {
return _networkUuid;
public VspNic getNic() {
return _nic;
}
public boolean isL3Network() {
return _isL3Network;
}
public boolean isSharedNetwork() {
return _isSharedNetwork;
}
public String getVpcUuid() {
return _vpcUuid;
}
public String getNetworkDomainUuid() {
return _networkDomainUuid;
}
public String getNetworksAccountUuid() {
return _networksAccountUuid;
}
public boolean isDomainRouter() {
return _isDomainRouter;
}
public String getDomainRouterIp() {
return _domainRouterIp;
}
public String getVmInstanceName() {
return _vmInstanceName;
}
public String getVmUuid() {
return _vmUuid;
}
public String getVmUserName() {
return _vmUserName;
}
public String getVmUserDomainName() {
return _vmUserDomainName;
}
public boolean useStaticIp() {
return _useStaticIp;
}
public String getStaticIp() {
return _staticIp;
}
public String getStaticNatIpUuid() {
return _staticNatIpUuid;
}
public String getStaticNatIpAddress() {
return _staticNatIpAddress;
}
public boolean isStaticNatIpAllocated() {
return _isStaticNatIpAllocated;
}
public boolean isOneToOneNat() {
return _isOneToOneNat;
}
public String getStaticNatVlanUuid() {
return _staticNatVlanUuid;
}
public String getStaticNatVlanGateway() {
return _staticNatVlanGateway;
}
public String getStaticNatVlanNetmask() {
return _staticNatVlanNetmask;
}
public static class Builder implements CmdBuilder<ReserveVmInterfaceVspCommand> {
private String _nicUuid;
private String _nicMacAddress;
private String _networkUuid;
private boolean _isL3Network;
private boolean _isSharedNetwork;
private String _vpcUuid;
private String _networkDomainUuid;
private String _networksAccountUuid;
private boolean _isDomainRouter;
private String _domainRouterIp;
private String _vmInstanceName;
private String _vmUuid;
private String _vmUserName;
private String _vmUserDomainName;
private boolean _useStaticIp;
private String _staticIp;
private String _staticNatIpUuid;
private String _staticNatIpAddress;
private boolean _isStaticNatIpAllocated;
private boolean _isOneToOneNat;
private String _staticNatVlanUuid;
private String _staticNatVlanGateway;
private String _staticNatVlanNetmask;
public Builder nicUuid(String nicUuid) {
this._nicUuid = nicUuid;
return this;
}
public Builder nicMacAddress(String nicMacAddress) {
this._nicMacAddress = nicMacAddress;
return this;
}
public Builder networkUuid(String networkUuid) {
this._networkUuid = networkUuid;
return this;
}
public Builder isL3Network(boolean isL3Network) {
this._isL3Network = isL3Network;
return this;
}
public Builder isSharedNetwork(boolean isSharedNetwork) {
this._isSharedNetwork = isSharedNetwork;
return this;
}
public Builder vpcUuid(String vpcUuid) {
this._vpcUuid = vpcUuid;
return this;
}
public Builder networkDomainUuid(String networkDomainUuid) {
this._networkDomainUuid = networkDomainUuid;
return this;
}
public Builder networksAccountUuid(String networksAccountUuid) {
this._networksAccountUuid = networksAccountUuid;
return this;
}
public Builder isDomainRouter(boolean isDomainRouter) {
this._isDomainRouter = isDomainRouter;
return this;
}
public Builder domainRouterIp(String domainRouterIp) {
this._domainRouterIp = domainRouterIp;
return this;
}
public Builder vmInstanceName(String vmInstanceName) {
this._vmInstanceName = vmInstanceName;
return this;
}
public Builder vmUuid(String vmUuid) {
this._vmUuid = vmUuid;
return this;
}
public Builder vmUserName(String vmUserName) {
this._vmUserName = vmUserName;
return this;
}
public Builder vmUserDomainName(String vmUserDomainName) {
this._vmUserDomainName = vmUserDomainName;
return this;
}
public Builder useStaticIp(boolean useStaticIp) {
this._useStaticIp = useStaticIp;
return this;
}
public Builder staticIp(String staticIp) {
this._staticIp = staticIp;
return this;
}
public Builder staticNatIpUuid(String staticNatIpUuid) {
this._staticNatIpUuid = staticNatIpUuid;
return this;
}
public Builder staticNatIpAddress(String staticNatIpAddress) {
this._staticNatIpAddress = staticNatIpAddress;
return this;
}
public Builder isStaticNatIpAllocated(boolean isStaticNatIpAllocated) {
this._isStaticNatIpAllocated = isStaticNatIpAllocated;
return this;
}
public Builder isOneToOneNat(boolean isOneToOneNat) {
this._isOneToOneNat = isOneToOneNat;
return this;
}
public Builder staticNatVlanUuid(String staticNatVlanUuid) {
this._staticNatVlanUuid = staticNatVlanUuid;
return this;
}
public Builder staticNatVlanGateway(String staticNatVlanGateway) {
this._staticNatVlanGateway = staticNatVlanGateway;
return this;
}
public Builder staticNatVlanNetmask(String staticNatVlanNetmask) {
this._staticNatVlanNetmask = staticNatVlanNetmask;
return this;
}
@Override
public ReserveVmInterfaceVspCommand build() {
return new ReserveVmInterfaceVspCommand(_nicUuid, _nicMacAddress, _networkUuid, _isL3Network, _isSharedNetwork, _vpcUuid, _networkDomainUuid, _networksAccountUuid,
_isDomainRouter, _domainRouterIp, _vmInstanceName, _vmUuid, _vmUserName, _vmUserDomainName, _useStaticIp, _staticIp, _staticNatIpUuid, _staticNatIpAddress,
_isStaticNatIpAllocated, _isOneToOneNat, _staticNatVlanUuid, _staticNatVlanGateway, _staticNatVlanNetmask);
}
public VspStaticNat getStaticNat() {
return _staticNat;
}
@Override
@ -331,40 +69,10 @@ public class ReserveVmInterfaceVspCommand extends Command {
ReserveVmInterfaceVspCommand that = (ReserveVmInterfaceVspCommand) o;
if (_isDomainRouter != that._isDomainRouter) return false;
if (_isL3Network != that._isL3Network) return false;
if (_isOneToOneNat != that._isOneToOneNat) return false;
if (_isSharedNetwork != that._isSharedNetwork) return false;
if (_isStaticNatIpAllocated != that._isStaticNatIpAllocated) return false;
if (_useStaticIp != that._useStaticIp) return false;
if (_domainRouterIp != null ? !_domainRouterIp.equals(that._domainRouterIp) : that._domainRouterIp != null)
return false;
if (_networkDomainUuid != null ? !_networkDomainUuid.equals(that._networkDomainUuid) : that._networkDomainUuid != null)
return false;
if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
if (_networksAccountUuid != null ? !_networksAccountUuid.equals(that._networksAccountUuid) : that._networksAccountUuid != null)
return false;
if (_nicMacAddress != null ? !_nicMacAddress.equals(that._nicMacAddress) : that._nicMacAddress != null)
return false;
if (_nicUuid != null ? !_nicUuid.equals(that._nicUuid) : that._nicUuid != null) return false;
if (_staticIp != null ? !_staticIp.equals(that._staticIp) : that._staticIp != null) return false;
if (_staticNatIpAddress != null ? !_staticNatIpAddress.equals(that._staticNatIpAddress) : that._staticNatIpAddress != null)
return false;
if (_staticNatIpUuid != null ? !_staticNatIpUuid.equals(that._staticNatIpUuid) : that._staticNatIpUuid != null)
return false;
if (_staticNatVlanGateway != null ? !_staticNatVlanGateway.equals(that._staticNatVlanGateway) : that._staticNatVlanGateway != null)
return false;
if (_staticNatVlanNetmask != null ? !_staticNatVlanNetmask.equals(that._staticNatVlanNetmask) : that._staticNatVlanNetmask != null)
return false;
if (_staticNatVlanUuid != null ? !_staticNatVlanUuid.equals(that._staticNatVlanUuid) : that._staticNatVlanUuid != null)
return false;
if (_vmInstanceName != null ? !_vmInstanceName.equals(that._vmInstanceName) : that._vmInstanceName != null)
return false;
if (_vmUserDomainName != null ? !_vmUserDomainName.equals(that._vmUserDomainName) : that._vmUserDomainName != null)
return false;
if (_vmUserName != null ? !_vmUserName.equals(that._vmUserName) : that._vmUserName != null) return false;
if (_vmUuid != null ? !_vmUuid.equals(that._vmUuid) : that._vmUuid != null) return false;
if (_vpcUuid != null ? !_vpcUuid.equals(that._vpcUuid) : that._vpcUuid != null) return false;
if (_network != null ? !_network.equals(that._network) : that._network != null) return false;
if (_nic != null ? !_nic.equals(that._nic) : that._nic != null) return false;
if (_staticNat != null ? !_staticNat.equals(that._staticNat) : that._staticNat != null) return false;
if (_vm != null ? !_vm.equals(that._vm) : that._vm != null) return false;
return true;
}
@ -372,29 +80,10 @@ public class ReserveVmInterfaceVspCommand extends Command {
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_nicUuid != null ? _nicUuid.hashCode() : 0);
result = 31 * result + (_nicMacAddress != null ? _nicMacAddress.hashCode() : 0);
result = 31 * result + (_networkUuid != null ? _networkUuid.hashCode() : 0);
result = 31 * result + (_isL3Network ? 1 : 0);
result = 31 * result + (_isSharedNetwork ? 1 : 0);
result = 31 * result + (_vpcUuid != null ? _vpcUuid.hashCode() : 0);
result = 31 * result + (_networkDomainUuid != null ? _networkDomainUuid.hashCode() : 0);
result = 31 * result + (_networksAccountUuid != null ? _networksAccountUuid.hashCode() : 0);
result = 31 * result + (_isDomainRouter ? 1 : 0);
result = 31 * result + (_domainRouterIp != null ? _domainRouterIp.hashCode() : 0);
result = 31 * result + (_vmInstanceName != null ? _vmInstanceName.hashCode() : 0);
result = 31 * result + (_vmUuid != null ? _vmUuid.hashCode() : 0);
result = 31 * result + (_vmUserName != null ? _vmUserName.hashCode() : 0);
result = 31 * result + (_vmUserDomainName != null ? _vmUserDomainName.hashCode() : 0);
result = 31 * result + (_useStaticIp ? 1 : 0);
result = 31 * result + (_staticIp != null ? _staticIp.hashCode() : 0);
result = 31 * result + (_staticNatIpUuid != null ? _staticNatIpUuid.hashCode() : 0);
result = 31 * result + (_staticNatIpAddress != null ? _staticNatIpAddress.hashCode() : 0);
result = 31 * result + (_isStaticNatIpAllocated ? 1 : 0);
result = 31 * result + (_isOneToOneNat ? 1 : 0);
result = 31 * result + (_staticNatVlanUuid != null ? _staticNatVlanUuid.hashCode() : 0);
result = 31 * result + (_staticNatVlanGateway != null ? _staticNatVlanGateway.hashCode() : 0);
result = 31 * result + (_staticNatVlanNetmask != null ? _staticNatVlanNetmask.hashCode() : 0);
result = 31 * result + (_network != null ? _network.hashCode() : 0);
result = 31 * result + (_vm != null ? _vm.hashCode() : 0);
result = 31 * result + (_nic != null ? _nic.hashCode() : 0);
result = 31 * result + (_staticNat != null ? _staticNat.hashCode() : 0);
return result;
}
}

View File

@ -19,94 +19,20 @@
package com.cloud.agent.api.guru;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
import net.nuage.vsp.acs.client.api.model.VspNetwork;
public class TrashNetworkVspCommand extends Command {
private final String _domainUuid;
private final String _networkUuid;
private final boolean _isL3Network;
private final boolean _isSharedNetwork;
private final String _vpcUuid;
private final String _domainTemplateName;
private final VspNetwork _network;
private TrashNetworkVspCommand(String domainUuid, String networkUuid, boolean isL3Network, boolean isSharedNetwork, String vpcUuid, String domainTemplateName) {
public TrashNetworkVspCommand(VspNetwork network) {
super();
this._domainUuid = domainUuid;
this._networkUuid = networkUuid;
this._isL3Network = isL3Network;
this._isSharedNetwork = isSharedNetwork;
this._vpcUuid = vpcUuid;
this._domainTemplateName = domainTemplateName;
this._network = network;
}
public String getDomainUuid() {
return _domainUuid;
}
public String getNetworkUuid() {
return _networkUuid;
}
public boolean isL3Network() {
return _isL3Network;
}
public boolean isSharedNetwork() {
return _isSharedNetwork;
}
public String getVpcUuid() {
return _vpcUuid;
}
public String getDomainTemplateName() {
return _domainTemplateName;
}
public static class Builder implements CmdBuilder<TrashNetworkVspCommand> {
private String _domainUuid;
private String _networkUuid;
private boolean _isL3Network;
private boolean _isSharedNetwork;
private String _vpcUuid;
private String _domainTemplateName;
public Builder domainUuid(String domainUuid) {
this._domainUuid = domainUuid;
return this;
}
public Builder networkUuid(String networkUuid) {
this._networkUuid = networkUuid;
return this;
}
public Builder isL3Network(boolean isL3Network) {
this._isL3Network = isL3Network;
return this;
}
public Builder isSharedNetwork(boolean isSharedNetwork) {
this._isSharedNetwork = isSharedNetwork;
return this;
}
public Builder vpcUuid(String vpcUuid) {
this._vpcUuid = vpcUuid;
return this;
}
public Builder domainTemplateName(String domainTemplateName) {
this._domainTemplateName = domainTemplateName;
return this;
}
@Override
public TrashNetworkVspCommand build() {
return new TrashNetworkVspCommand(_domainUuid, _networkUuid, _isL3Network, _isSharedNetwork, _vpcUuid, _domainTemplateName);
}
public VspNetwork getNetwork() {
return _network;
}
@Override
@ -122,13 +48,7 @@ public class TrashNetworkVspCommand extends Command {
TrashNetworkVspCommand that = (TrashNetworkVspCommand) o;
if (_isL3Network != that._isL3Network) return false;
if (_isSharedNetwork != that._isSharedNetwork) return false;
if (_domainTemplateName != null ? !_domainTemplateName.equals(that._domainTemplateName) : that._domainTemplateName != null)
return false;
if (_domainUuid != null ? !_domainUuid.equals(that._domainUuid) : that._domainUuid != null) return false;
if (_networkUuid != null ? !_networkUuid.equals(that._networkUuid) : that._networkUuid != null) return false;
if (_vpcUuid != null ? !_vpcUuid.equals(that._vpcUuid) : that._vpcUuid != null) return false;
if (_network != null ? !_network.equals(that._network) : that._network != null) return false;
return true;
}
@ -136,12 +56,7 @@ public class TrashNetworkVspCommand extends Command {
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_domainUuid != null ? _domainUuid.hashCode() : 0);
result = 31 * result + (_networkUuid != null ? _networkUuid.hashCode() : 0);
result = 31 * result + (_isL3Network ? 1 : 0);
result = 31 * result + (_isSharedNetwork ? 1 : 0);
result = 31 * result + (_vpcUuid != null ? _vpcUuid.hashCode() : 0);
result = 31 * result + (_domainTemplateName != null ? _domainTemplateName.hashCode() : 0);
result = 31 * result + (_network != null ? _network.hashCode() : 0);
return result;
}
}

View File

@ -17,38 +17,37 @@
// under the License.
//
package com.cloud.agent.api.sync;
package com.cloud.agent.api.manager;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.Answer;
import net.nuage.vsp.acs.client.api.model.VspApiDefaults;
public class SyncVspCommand extends Command {
public class GetApiDefaultsAnswer extends Answer {
private final String _nuageVspEntity;
private VspApiDefaults _apiDefaults;
public SyncVspCommand(String nuageVspEntity) {
super();
this._nuageVspEntity = nuageVspEntity;
public GetApiDefaultsAnswer(GetApiDefaultsCommand cmd, VspApiDefaults defaults) {
super(cmd);
this._apiDefaults = defaults;
}
@Override
public boolean executeInSequence() {
return false;
public GetApiDefaultsAnswer(GetApiDefaultsCommand cmd, Exception e) {
super(cmd, e);
}
public String getNuageVspEntity() {
return _nuageVspEntity;
public VspApiDefaults getApiDefaults() {
return _apiDefaults;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SyncVspCommand)) return false;
if (!(o instanceof GetApiDefaultsAnswer)) return false;
if (!super.equals(o)) return false;
SyncVspCommand that = (SyncVspCommand) o;
GetApiDefaultsAnswer that = (GetApiDefaultsAnswer) o;
if (_nuageVspEntity != null ? !_nuageVspEntity.equals(that._nuageVspEntity) : that._nuageVspEntity != null)
return false;
if (_apiDefaults != null ? !_apiDefaults.equals(that._apiDefaults) : that._apiDefaults != null) return false;
return true;
}
@ -56,7 +55,7 @@ public class SyncVspCommand extends Command {
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_nuageVspEntity != null ? _nuageVspEntity.hashCode() : 0);
result = 31 * result + (_apiDefaults != null ? _apiDefaults.hashCode() : 0);
return result;
}
}

View File

@ -25,9 +25,9 @@ import com.cloud.agent.api.Command;
* The super class implementations for equals and hashCode are acceptable because this class does not track any state
* in addition to the super class.
*/
public class GetClientDefaultsCommand extends Command {
public class GetApiDefaultsCommand extends Command {
public GetClientDefaultsCommand() {
public GetApiDefaultsCommand() {
super();
}

View File

@ -1,81 +0,0 @@
//
// 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 com.cloud.agent.api.manager;
import com.cloud.agent.api.Answer;
import java.util.Map;
public class GetClientDefaultsAnswer extends Answer {
private String _currentApiVersion;
private Integer _apiRetryCount;
private Long _apiRetryInterval;
public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Map<String, Object> defaults) {
super(cmd);
this._currentApiVersion = (String) defaults.get("CURRENT_API_VERSION");
this._apiRetryCount = (Integer) defaults.get("DEFAULT_API_RETRY_COUNT");
this._apiRetryInterval = (Long) defaults.get("DEFAULT_API_RETRY_INTERVAL");
}
public GetClientDefaultsAnswer(GetClientDefaultsCommand cmd, Exception e) {
super(cmd, e);
}
public String getCurrentApiVersion() {
return _currentApiVersion;
}
public Integer getApiRetryCount() {
return _apiRetryCount;
}
public Long getApiRetryInterval() {
return _apiRetryInterval;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof GetClientDefaultsAnswer)) return false;
if (!super.equals(o)) return false;
GetClientDefaultsAnswer that = (GetClientDefaultsAnswer) o;
if (_apiRetryCount != null ? !_apiRetryCount.equals(that._apiRetryCount) : that._apiRetryCount != null)
return false;
if (_apiRetryInterval != null ? !_apiRetryInterval.equals(that._apiRetryInterval) : that._apiRetryInterval != null)
return false;
if (_currentApiVersion != null ? !_currentApiVersion.equals(that._currentApiVersion) : that._currentApiVersion != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_currentApiVersion != null ? _currentApiVersion.hashCode() : 0);
result = 31 * result + (_apiRetryCount != null ? _apiRetryCount.hashCode() : 0);
result = 31 * result + (_apiRetryInterval != null ? _apiRetryInterval.hashCode() : 0);
return result;
}
}

View File

@ -20,34 +20,23 @@
package com.cloud.agent.api.sync;
import com.cloud.agent.api.Command;
import net.nuage.vsp.acs.client.api.model.VspDomain;
public class SyncDomainCommand extends Command {
private final String _domainUuid;
private final String _domainName;
private final String _domainPath;
private final VspDomain _domain;
private final boolean _toAdd;
private final boolean _toRemove;
public SyncDomainCommand(String domainUuid, String domainName, String domainPath, boolean toAdd, boolean toRemove) {
public SyncDomainCommand(VspDomain domain, boolean toAdd, boolean toRemove) {
super();
this._domainUuid = domainUuid;
this._domainName = domainName;
this._domainPath = domainPath;
this._domain = domain;
this._toAdd = toAdd;
this._toRemove = toRemove;
}
public String getDomainUuid() {
return _domainUuid;
}
public String getDomainName() {
return _domainName;
}
public String getDomainPath() {
return _domainPath;
public VspDomain getDomain() {
return _domain;
}
public boolean isToAdd() {
@ -73,9 +62,7 @@ public class SyncDomainCommand extends Command {
if (_toAdd != that._toAdd) return false;
if (_toRemove != that._toRemove) return false;
if (_domainName != null ? !_domainName.equals(that._domainName) : that._domainName != null) return false;
if (_domainPath != null ? !_domainPath.equals(that._domainPath) : that._domainPath != null) return false;
if (_domainUuid != null ? !_domainUuid.equals(that._domainUuid) : that._domainUuid != null) return false;
if (_domain != null ? !_domain.equals(that._domain) : that._domain != null) return false;
return true;
}
@ -83,9 +70,7 @@ public class SyncDomainCommand extends Command {
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_domainUuid != null ? _domainUuid.hashCode() : 0);
result = 31 * result + (_domainName != null ? _domainName.hashCode() : 0);
result = 31 * result + (_domainPath != null ? _domainPath.hashCode() : 0);
result = 31 * result + (_domain != null ? _domain.hashCode() : 0);
result = 31 * result + (_toAdd ? 1 : 0);
result = 31 * result + (_toRemove ? 1 : 0);
return result;

View File

@ -29,6 +29,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.NuageVspDeviceVO;
import com.cloud.network.manager.NuageVspManager;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
@ -41,9 +42,12 @@ import org.apache.cloudstack.context.CallContext;
import javax.inject.Inject;
@APICommand(name = "addNuageVspDevice", responseObject = NuageVspDeviceResponse.class, description = "Adds a Nuage VSP device", since = "4.5")
@APICommand(name = AddNuageVspDeviceCmd.APINAME, description = "Adds a Nuage VSP device", responseObject = NuageVspDeviceResponse.class,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
since = "4.5",
authorized = {RoleType.Admin})
public class AddNuageVspDeviceCmd extends BaseAsyncCmd {
private static final String s_name = "addnuagevspdeviceresponse";
public static final String APINAME = "addNuageVspDevice";
@Inject
NuageVspManager _nuageVspManager;
@ -68,14 +72,14 @@ public class AddNuageVspDeviceCmd extends BaseAsyncCmd {
@Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, required = true, description = "the password of CMS user in Nuage VSD")
private String password;
@Parameter(name = VspConstants.NUAGE_VSP_API_VERSION, type = CommandType.STRING, required = true, description = "the version of the API to use to communicate to Nuage VSD")
@Parameter(name = VspConstants.NUAGE_VSP_API_VERSION, type = CommandType.STRING, description = "the version of the API to use to communicate to Nuage VSD")
private String apiVersion;
@Parameter(name = VspConstants.NUAGE_VSP_API_RETRY_COUNT, type = CommandType.INTEGER, required = true, description = "the number of retries on failure to communicate to Nuage VSD")
private int apiRetryCount;
@Parameter(name = VspConstants.NUAGE_VSP_API_RETRY_COUNT, type = CommandType.INTEGER, description = "the number of retries on failure to communicate to Nuage VSD")
private Integer apiRetryCount;
@Parameter(name = VspConstants.NUAGE_VSP_API_RETRY_INTERVAL, type = CommandType.LONG, required = true, description = "the time to wait after failure before retrying to communicate to Nuage VSD")
private long apiRetryInterval;
@Parameter(name = VspConstants.NUAGE_VSP_API_RETRY_INTERVAL, type = CommandType.LONG, description = "the time to wait after failure before retrying to communicate to Nuage VSD")
private Long apiRetryInterval;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -117,7 +121,7 @@ public class AddNuageVspDeviceCmd extends BaseAsyncCmd {
this.apiVersion = apiVersion;
}
public int getApiRetryCount() {
public Integer getApiRetryCount() {
return apiRetryCount;
}
@ -125,7 +129,7 @@ public class AddNuageVspDeviceCmd extends BaseAsyncCmd {
this.apiRetryCount = apiRetryCount;
}
public long getApiRetryInterval() {
public Long getApiRetryInterval() {
return apiRetryInterval;
}
@ -158,7 +162,7 @@ public class AddNuageVspDeviceCmd extends BaseAsyncCmd {
@Override
public String getCommandName() {
return s_name;
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
}
@Override

View File

@ -28,9 +28,11 @@ import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.manager.NuageVspManager;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse;
@ -38,9 +40,13 @@ import org.apache.cloudstack.context.CallContext;
import javax.inject.Inject;
@APICommand(name = "deleteNuageVspDevice", responseObject = SuccessResponse.class, description = "delete a nuage vsp device", since = "4.5")
@APICommand(name = DeleteNuageVspDeviceCmd.APINAME, description = "delete a nuage vsp device", responseObject = SuccessResponse.class,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
since = "4.5",
authorized = {RoleType.Admin})
public class DeleteNuageVspDeviceCmd extends BaseAsyncCmd {
private static final String s_name = "deletenuagevspdeviceresponse";
public static final String APINAME = "deleteNuageVspDevice";
@Inject
NuageVspManager _nuageVspManager;
@ -83,7 +89,7 @@ public class DeleteNuageVspDeviceCmd extends BaseAsyncCmd {
@Override
public String getCommandName() {
return s_name;
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
}
@Override

View File

@ -1,213 +0,0 @@
//
// 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 com.cloud.api.commands;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.VspResourceAnswer;
import com.cloud.agent.api.VspResourceCommand;
import com.cloud.api.response.NuageVspResourceResponse;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.network.NuageVspDeviceVO;
import com.cloud.network.dao.NuageVspDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.NetworkOfferingResponse;
import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import javax.inject.Inject;
import java.util.List;
@APICommand(name = "issueNuageVspResourceRequest", responseObject = NuageVspResourceResponse.class, description = "Issues a Nuage VSP REST API resource request", since = "4.5")
public class IssueNuageVspResourceRequestCmd extends BaseCmd {
private static final Logger s_logger = Logger.getLogger(IssueNuageVspResourceRequestCmd.class.getName());
private static final String s_name = "nuagevspresourceresponse";
@Inject
protected AccountManager _accountMgr;
@Inject
protected DomainDao _domainDao;
@Inject
protected NuageVspDao _nuageConfigDao;
@Inject
HostDao _hostDao;
@Inject
AgentManager _agentMgr;
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name = ApiConstants.NETWORK_OFFERING_ID, type = CommandType.UUID, entityType = NetworkOfferingResponse.class, required = true, description = "the network offering id")
private Long networkOfferingId;
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "the Zone ID for the network")
private Long zoneId;
@Parameter(name = ApiConstants.PHYSICAL_NETWORK_ID, type = CommandType.UUID, entityType = PhysicalNetworkResponse.class, description = "the ID of the physical network in to which Nuage VSP Controller is added")
private Long physicalNetworkId;
@Parameter(name = VspConstants.NUAGE_VSP_API_METHOD, type = CommandType.STRING, required = true, description = "the Nuage VSP REST API method type")
private String method;
@Parameter(name = VspConstants.NUAGE_VSP_API_RESOURCE, type = CommandType.STRING, required = true, description = "the resource in Nuage VSP")
private String resource;
@Parameter(name = VspConstants.NUAGE_VSP_API_RESOURCE_ID, type = CommandType.STRING, description = "the ID of the resource in Nuage VSP")
private String resourceId;
@Parameter(name = VspConstants.NUAGE_VSP_API_CHILD_RESOURCE, type = CommandType.STRING, description = "the child resource in Nuage VSP")
private String childResource;
@Parameter(name = VspConstants.NUAGE_VSP_API_RESOURCE_FILTER, type = CommandType.STRING, description = "the resource filter in Nuage VSP")
private String resourceFilter;
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
public Long getNetworkOfferingId() {
return networkOfferingId;
}
public Long getZoneId() {
Long physicalNetworkId = getPhysicalNetworkId();
if (physicalNetworkId == null && zoneId == null) {
throw new InvalidParameterValueException("Zone id is required");
}
return zoneId;
}
public Long getPhysicalNetworkId() {
if (physicalNetworkId != null) {
return physicalNetworkId;
}
NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, networkOfferingId);
if (offering == null) {
throw new InvalidParameterValueException("Unable to find network offering by id " + networkOfferingId);
}
if (zoneId == null) {
throw new InvalidParameterValueException("ZoneId is required as physicalNetworkId is null");
}
return _networkService.findPhysicalNetworkId(zoneId, offering.getTags(), offering.getTrafficType());
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public String getResource() {
return resource;
}
public void setResource(String resource) {
this.resource = resource;
}
public String getResourceId() {
return resourceId;
}
public void setResourceId(String resourceId) {
this.resourceId = resourceId;
}
public String getChildResource() {
return childResource;
}
public void setChildResource(String childResource) {
this.childResource = childResource;
}
public String getResourceFilter() {
return resourceFilter;
}
public void setResourceFilter(String resourceFilter) {
this.resourceFilter = resourceFilter;
}
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
long accountId = CallContext.current().getCallingAccount().getAccountId();
Account account = _accountMgr.getAccount(accountId);
List<NuageVspDeviceVO> nuageVspDevices = _nuageConfigDao.listByPhysicalNetwork(getPhysicalNetworkId());
if (nuageVspDevices != null && (!nuageVspDevices.isEmpty())) {
NuageVspDeviceVO config = nuageVspDevices.iterator().next();
HostVO nuageVspHost = _hostDao.findById(config.getHostId());
VspResourceCommand cmd = new VspResourceCommand(method, resource, resourceId, childResource, null, resourceFilter, null, null);
VspResourceAnswer answer = (VspResourceAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("VspResourceCommand failed");
if ((null != answer) && (null != answer.getDetails())) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, answer.getDetails());
}
} else {
NuageVspResourceResponse response = new NuageVspResourceResponse();
response.setResourceInfo(StringUtils.isBlank(answer.getResourceInfo()) ? "" : answer.getResourceInfo());
response.setObjectName("nuagevspresource");
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
} else {
String errorMessage = "No Nuage VSP Controller configured on physical network " + getPhysicalNetworkId();
s_logger.error(errorMessage);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage);
}
}
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}
}

View File

@ -28,9 +28,11 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.NuageVspDeviceVO;
import com.cloud.network.manager.NuageVspManager;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
@ -41,9 +43,13 @@ import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
@APICommand(name = "listNuageVspDevices", responseObject = NuageVspDeviceResponse.class, description = "Lists Nuage VSP devices", since = "4.5")
@APICommand(name = ListNuageVspDevicesCmd.APINAME, description = "Lists Nuage VSP devices", responseObject = NuageVspDeviceResponse.class,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
since = "4.5",
authorized = {RoleType.Admin})
public class ListNuageVspDevicesCmd extends BaseListCmd {
private static final String s_name = "listnuagevspdeviceresponse";
public static final String APINAME = "listNuageVspDevices";
@Inject
NuageVspManager _nuageVspManager;
@ -99,7 +105,7 @@ public class ListNuageVspDevicesCmd extends BaseListCmd {
@Override
public String getCommandName() {
return s_name;
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
}
}

View File

@ -29,6 +29,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.NuageVspDeviceVO;
import com.cloud.network.manager.NuageVspManager;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
@ -38,14 +39,15 @@ import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.log4j.Logger;
import javax.inject.Inject;
@APICommand(name = "updateNuageVspDevice", responseObject = NuageVspDeviceResponse.class, description = "Update a Nuage VSP device", since = "4.6")
@APICommand(name = UpdateNuageVspDeviceCmd.APINAME, description = "Update a Nuage VSP device", responseObject = NuageVspDeviceResponse.class,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false,
since = "4.6",
authorized = {RoleType.Admin})
public class UpdateNuageVspDeviceCmd extends BaseAsyncCmd {
private static final Logger s_logger = Logger.getLogger(UpdateNuageVspDeviceCmd.class);
private static final String s_name = "updatenuagevspdeviceresponse";
public static final String APINAME = "updateNuageVspDevice";
@Inject
NuageVspManager _nuageVspManager;
@ -160,7 +162,7 @@ public class UpdateNuageVspDeviceCmd extends BaseAsyncCmd {
@Override
public String getCommandName() {
return s_name;
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
}
@Override

View File

@ -74,28 +74,36 @@ import com.cloud.network.vpc.VpcOfferingServiceMapVO;
import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.network.vpc.dao.VpcOfferingServiceMapDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.resource.ResourceManager;
import com.cloud.resource.ResourceStateAdapter;
import com.cloud.resource.ServerResource;
import com.cloud.resource.UnableDeleteHostException;
import com.cloud.util.NuageVspUtil;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.NicDao;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.cloud.util.NuageVspEntityBuilder;
import net.nuage.vsp.acs.client.api.model.VspAclRule;
import net.nuage.vsp.acs.client.api.model.VspNetwork;
import net.nuage.vsp.acs.client.api.model.VspStaticNat;
import org.apache.cloudstack.api.InternalIdentity;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager;
import org.apache.cloudstack.resourcedetail.VpcDetailVO;
import org.apache.cloudstack.resourcedetail.dao.VpcDetailsDao;
import org.apache.commons.collections.CollectionUtils;
import org.apache.log4j.Logger;
import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import java.util.ArrayList;
@ -126,9 +134,9 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
@Inject
NetworkDao _networkDao;
@Inject
protected DomainDao _domainDao;
DomainDao _domainDao;
@Inject
protected DataCenterDao _dcDao;
DataCenterDao _dcDao;
@Inject
IPAddressDao _ipAddressDao;
@Inject
@ -157,6 +165,12 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
PhysicalNetworkDao _physicalNetworkDao;
@Inject
NetworkACLItemDao _networkACLItemDao;
@Inject
NuageVspEntityBuilder _nuageVspEntityBuilder;
@Inject
VpcDetailsDao _vpcDetailsDao;
@Inject
DomainRouterDao _routerDao;
@Override
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> service) throws ResourceUnavailableException {
@ -242,53 +256,21 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
return false;
}
boolean egressDefaultPolicy = offering.getEgressDefaultPolicy();
Domain networkDomain = _domainDao.findById(network.getDomainId());
boolean isFirewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Service.Firewall);
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network, false);
List<String> dnsServers = _nuageVspManager.getDnsDetails(network);
boolean isL2Network = false, isL3Network = false, isShared = false;
String subnetUuid = network.getUuid();
if (offering.getGuestType() == Network.GuestType.Shared) {
isShared = true;
subnetUuid = networkDomain.getUuid();
} else if (_ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.SourceNat)
|| _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.StaticNat)
|| _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Connectivity)) {
isL3Network = true;
} else {
isL2Network = true;
}
String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configDao, network, offering);
List<Map<String, Object>> ingressFirewallRules = getFirewallRulesToApply(network.getId(), FirewallRule.TrafficType.Ingress, egressDefaultPolicy);
List<Map<String, Object>> egressFirewallRules = getFirewallRulesToApply(network.getId(), FirewallRule.TrafficType.Egress, egressDefaultPolicy);
List<VspAclRule> ingressFirewallRules = getFirewallRulesToApply(network, FirewallRule.TrafficType.Ingress);
List<VspAclRule> egressFirewallRules = getFirewallRulesToApply(network, FirewallRule.TrafficType.Egress);
List<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(network.getId());
List<String> acsFipUuid = new ArrayList<String>();
List<String> floatingIpUuids = new ArrayList<String>();
for (IPAddressVO ip : ips) {
acsFipUuid.add(ip.getUuid());
floatingIpUuids.add(ip.getUuid());
}
HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
ImplementVspCommand.Builder cmdBuilder = new ImplementVspCommand.Builder()
.networkId(network.getId())
.networkDomainUuid(networkDomain.getUuid())
.networkUuid(network.getUuid())
.networkName(network.getName())
.vpcOrSubnetUuid(subnetUuid)
.isL2Network(isL2Network)
.isL3Network(isL3Network)
.isVpc(false)
.isShared(isShared)
.domainTemplateName(preConfiguredDomainTemplateName)
.isFirewallServiceSupported(isFirewallServiceSupported)
.dnsServers(dnsServers)
.ingressFirewallRules(ingressFirewallRules)
.egressFirewallRules(egressFirewallRules)
.acsFipUuid(acsFipUuid)
.egressDefaultPolicy(egressDefaultPolicy);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
ImplementVspCommand cmd = new ImplementVspCommand(vspNetwork, dnsServers, ingressFirewallRules, egressFirewallRules, floatingIpUuids);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ImplementVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
@ -302,23 +284,21 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
private boolean applyACLRulesForVpc(Network network, NetworkOffering offering) throws ResourceUnavailableException {
List<NetworkACLItemVO> rules = _networkACLItemDao.listByACL(network.getNetworkACLId());
if (_networkModel.areServicesSupportedByNetworkOffering(offering.getId(), Network.Service.NetworkACL)) {
applyACLRules(network, rules, true, null, false);
applyACLRules(network, rules, true, false);
}
return true;
}
private List<Map<String, Object>> getFirewallRulesToApply(long networkId, FirewallRule.TrafficType trafficType, final boolean egressDefaultPolicy) {
List<FirewallRuleVO> firewallRulesToApply = _firewallRulesDao.listByNetworkPurposeTrafficType(networkId, FirewallRule.Purpose.Firewall, trafficType);
private List<VspAclRule> getFirewallRulesToApply(final Network network, FirewallRule.TrafficType trafficType) {
List<FirewallRuleVO> firewallRulesToApply = _firewallRulesDao.listByNetworkPurposeTrafficType(network.getId(), FirewallRule.Purpose.Firewall, trafficType);
List<VspAclRule> vspAclRulesToApply = Lists.newArrayListWithExpectedSize(firewallRulesToApply.size());
for (FirewallRuleVO rule : firewallRulesToApply) {
// load cidrs if any
rule.setSourceCidrList(_firewallRulesCidrsDao.getSourceCidrs(rule.getId()));
VspAclRule vspAclRule = _nuageVspEntityBuilder.buildVspAclRule(rule, network);
vspAclRulesToApply.add(vspAclRule);
}
return Lists.transform(firewallRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
@Override
public Map<String, Object> apply(FirewallRuleVO firewallRuleVO) {
return getACLRuleDetails(firewallRuleVO, egressDefaultPolicy);
}
});
return vspAclRulesToApply;
}
@Override
@ -463,48 +443,19 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
@Override
public boolean applyStaticNats(Network config, List<? extends StaticNat> rules) throws ResourceUnavailableException {
//Check if the network is associated to a VPC
Long vpcId = config.getVpcId();
String vpcOrSubnetUuid = null;
if (vpcId != null) {
Vpc vpcObj = _vpcDao.findById(vpcId);
vpcOrSubnetUuid = vpcObj.getUuid();
} else {
vpcOrSubnetUuid = config.getUuid();
}
Domain networkDomain = _domainDao.findById(config.getDomainId());
long networkOfferingId = _ntwkOfferingDao.findById(config.getNetworkOfferingId()).getId();
boolean isL3Network = isL3Network(networkOfferingId);
List<Map<String, Object>> sourceNatDetails = new ArrayList<Map<String, Object>>();
List<VspStaticNat> vspStaticNatDetails = new ArrayList<VspStaticNat>();
for (StaticNat staticNat : rules) {
Map<String, Object> sourceNatDetail = new HashMap<String, Object>();
IPAddressVO sourceNatIp = _ipAddressDao.findById(staticNat.getSourceIpAddressId());
VlanVO sourceNatVan = _vlanDao.findById(sourceNatIp.getVlanId());
VlanVO sourceNatVlan = _vlanDao.findById(sourceNatIp.getVlanId());
NicVO nicVO = _nicDao.findByIp4AddressAndNetworkId(staticNat.getDestIpAddress(), staticNat.getNetworkId());
//Just get all the information about the sourceNat which will be used by NuageVsp
//client to process the request
sourceNatDetail.put("sourceNatIpUuid", sourceNatIp.getUuid());
sourceNatDetail.put("sourceNatIpAddress", sourceNatIp.getAddress().addr());
sourceNatDetail.put("nicUuid", nicVO == null ? null : nicVO.getUuid());
sourceNatDetail.put("nicMacAddress", nicVO == null ? null : nicVO.getMacAddress());
sourceNatDetail.put("isRevoke", staticNat.isForRevoke());
sourceNatDetail.put("sourceNatVlanUuid", sourceNatVan.getUuid());
sourceNatDetail.put("sourceNatVlanGateway", sourceNatVan.getVlanGateway());
sourceNatDetail.put("sourceNatVlanNetmask", sourceNatVan.getVlanNetmask());
sourceNatDetails.add(sourceNatDetail);
VspStaticNat vspStaticNat = _nuageVspEntityBuilder.buildVspStaticNat(staticNat.isForRevoke(), sourceNatIp, sourceNatVlan, nicVO);
vspStaticNatDetails.add(vspStaticNat);
}
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(config, false);
HostVO nuageVspHost = getNuageVspHost(config.getPhysicalNetworkId());
ApplyStaticNatVspCommand.Builder cmdBuilder = new ApplyStaticNatVspCommand.Builder()
.networkDomainUuid(networkDomain.getUuid())
.networkUuid(config.getUuid())
.vpcOrSubnetUuid(vpcOrSubnetUuid)
.isL3Network(isL3Network)
.isVpc(vpcId != null)
.staticNatDetails(sourceNatDetails);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
ApplyStaticNatVspCommand cmd = new ApplyStaticNatVspCommand(vspNetwork, vspStaticNatDetails);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ApplyStaticNatNuageVspCommand for network " + config.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
@ -534,44 +485,27 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
}
s_logger.info("Applying " + rules.size() + " Firewall Rules for network " + network.getName());
return applyACLRules(network, rules, false, rules.iterator().next().getTrafficType().equals(FirewallRule.TrafficType.Ingress), false);
return applyACLRules(network, rules, false, false);
}
protected boolean applyACLRules(Network network, List<? extends InternalIdentity> rules, boolean isNetworkAcl, Boolean isAcsIngressAcl, boolean networkReset)
protected boolean applyACLRules(final Network network, List<? extends InternalIdentity> rules, boolean isNetworkAcl, boolean networkReset)
throws ResourceUnavailableException {
Domain networksDomain = _domainDao.findById(network.getDomainId());
NetworkOfferingVO networkOfferingVO = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
Long vpcId = network.getVpcId();
String vpcOrSubnetUuid = null;
if (vpcId != null) {
Vpc vpcObj = _vpcDao.findById(vpcId);
vpcOrSubnetUuid = vpcObj.getUuid();
} else {
vpcOrSubnetUuid = network.getUuid();
}
boolean egressDefaultPolicy = networkOfferingVO.getEgressDefaultPolicy();
List<Map<String, Object>> aclRules = new ArrayList<Map<String, Object>>();
for (InternalIdentity acl : rules) {
aclRules.add(getACLRuleDetails(acl, egressDefaultPolicy));
}
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network, false);
List<VspAclRule> vspAclRules = Lists.transform(rules, new Function<InternalIdentity, VspAclRule>() {
@Nullable
@Override
public VspAclRule apply(@Nullable InternalIdentity input) {
if (input instanceof FirewallRule) {
return _nuageVspEntityBuilder.buildVspAclRule((FirewallRule) input, network);
}
return _nuageVspEntityBuilder.buildVspAclRule((NetworkACLItem) input);
}
});
boolean isL3Network = isL3Network(network.getNetworkOfferingId());
HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configDao, network, networkOfferingVO);
ApplyAclRuleVspCommand.Builder cmdBuilder = new ApplyAclRuleVspCommand.Builder()
.networkAcl(isNetworkAcl)
.networkUuid(network.getUuid())
.networkDomainUuid(networksDomain.getUuid())
.vpcOrSubnetUuid(vpcOrSubnetUuid)
.networkName(network.getName())
.isL2Network(!isL3Network)
.aclRules(aclRules)
.networkId(network.getId())
.egressDefaultPolicy(networkOfferingVO.getEgressDefaultPolicy())
.acsIngressAcl(isAcsIngressAcl)
.networkReset(networkReset)
.domainTemplateName(preConfiguredDomainTemplateName);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
VspAclRule.ACLType vspAclType = isNetworkAcl ? VspAclRule.ACLType.NetworkACL : VspAclRule.ACLType.Firewall;
ApplyAclRuleVspCommand cmd = new ApplyAclRuleVspCommand(vspAclType, vspNetwork, vspAclRules, networkReset);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ApplyAclRuleNuageVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
@ -594,7 +528,7 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
}
if (rules != null) {
s_logger.info("Applying " + rules.size() + " Network ACLs for network " + config.getName());
applyACLRules(config, rules, true, null, rules.isEmpty());
applyACLRules(config, rules, true, rules.isEmpty());
}
return true;
}
@ -623,14 +557,32 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
@Override
public boolean shutdownVpc(Vpc vpc, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
if (vpc.getState().equals(Vpc.State.Inactive)) {
List<DomainRouterVO> routers = _routerDao.listByVpcId(vpc.getId());
if (CollectionUtils.isEmpty(routers)) {
routers = _routerDao.listIncludingRemovedByVpcId(vpc.getId());
}
List<String> domainRouterUuids = Lists.transform(routers, new Function<DomainRouterVO, String>() {
@Nullable
@Override
public String apply(@Nullable DomainRouterVO input) {
return input != null ? input.getUuid() : null;
}
});
Domain vpcDomain = _domainDao.findById(vpc.getDomainId());
HostVO nuageVspHost = getNuageVspHost(getPhysicalNetworkId(vpc.getZoneId()));
String preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspVpcDomainTemplateName.key());
ShutDownVpcVspCommand.Builder cmdBuilder = new ShutDownVpcVspCommand.Builder()
.domainUuid(vpcDomain.getUuid())
.vpcUuid(vpc.getUuid())
.domainTemplateName(preConfiguredDomainTemplateName);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
String preConfiguredDomainTemplateName;
VpcDetailVO domainTemplateNameDetail = _vpcDetailsDao.findDetail(vpc.getId(), NuageVspManager.nuageDomainTemplateDetailName);
if (domainTemplateNameDetail != null) {
preConfiguredDomainTemplateName = domainTemplateNameDetail.getValue();
} else {
preConfiguredDomainTemplateName = _configDao.getValue(NuageVspManager.NuageVspVpcDomainTemplateName.key());
}
ShutDownVpcVspCommand cmd = new ShutDownVpcVspCommand(vpcDomain.getUuid(), vpc.getUuid(), preConfiguredDomainTemplateName, domainRouterUuids);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ShutDownVpcVspCommand for VPC " + vpc.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
@ -707,50 +659,4 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
}
return nuageVspHost;
}
protected boolean isL3Network(Long offeringId) {
return _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offeringId, Service.SourceNat)
|| _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offeringId, Service.StaticNat);
}
private Map<String, Object> getACLRuleDetails(Object aclRule, boolean egressDefaultPolicy) {
Map<String, Object> aclDetails = new HashMap<String, Object>();
if (aclRule instanceof FirewallRule) {
FirewallRule firewallRule = (FirewallRule)aclRule;
aclDetails.put("sourceCidrList", firewallRule.getSourceCidrList());
aclDetails.put("uuid", firewallRule.getUuid());
aclDetails.put("protocol", firewallRule.getProtocol());
aclDetails.put("startPort", firewallRule.getSourcePortStart());
aclDetails.put("endPort", firewallRule.getSourcePortEnd());
aclDetails.put("state", firewallRule.getState().name());
aclDetails.put("trafficType", firewallRule.getTrafficType().name());
if (firewallRule.getSourceIpAddressId() != null) {
//add the source IP
IPAddressVO ipaddress = _ipAddressDao.findById(((FirewallRule)aclRule).getSourceIpAddressId());
aclDetails.put("sourceIpAddress", ipaddress != null ? ipaddress.getVmIp() + "/32" : null);
}
if (firewallRule.getTrafficType().equals(FirewallRule.TrafficType.Egress) && egressDefaultPolicy) {
aclDetails.put("action", "Deny");
} else {
aclDetails.put("action", "Allow");
}
aclDetails.put("priority", -1);
aclDetails.put("type", "Firewall");
} else {
NetworkACLItem networkAcl = (NetworkACLItem)aclRule;
aclDetails.put("sourceCidrList", networkAcl.getSourceCidrList());
aclDetails.put("uuid", networkAcl.getUuid());
aclDetails.put("protocol", networkAcl.getProtocol());
aclDetails.put("startPort", networkAcl.getSourcePortStart());
aclDetails.put("endPort", networkAcl.getSourcePortEnd());
aclDetails.put("state", networkAcl.getState().name());
aclDetails.put("trafficType", networkAcl.getTrafficType().name());
//Set sourceIP to null as it is not applicable
aclDetails.put("sourceIpAddress", null);
aclDetails.put("action", networkAcl.getAction().name());
aclDetails.put("priority", networkAcl.getNumber());
aclDetails.put("type", "NetworkACL");
}
return aclDetails;
}
}

View File

@ -31,18 +31,14 @@ import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.VlanVO;
import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapacityException;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.network.IpAddress;
import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.Service;
import com.cloud.network.Network.State;
import com.cloud.network.NetworkProfile;
import com.cloud.network.Networks;
@ -50,11 +46,12 @@ import com.cloud.network.NuageVspDeviceVO;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.PhysicalNetwork.IsolationMethod;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.network.dao.NetworkDetailVO;
import com.cloud.network.dao.NetworkDetailsDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.NuageVspDao;
import com.cloud.network.dao.PhysicalNetworkVO;
import com.cloud.network.manager.NuageVspManager;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingDao;
@ -62,28 +59,25 @@ import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.user.Account;
import com.cloud.user.AccountVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.util.NuageVspUtil;
import com.cloud.utils.StringUtils;
import com.cloud.utils.db.DB;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.google.common.base.Strings;
import org.apache.commons.lang.StringUtils;
import com.cloud.util.NuageVspEntityBuilder;
import net.nuage.vsp.acs.client.api.model.VspNetwork;
import net.nuage.vsp.acs.client.api.model.VspNic;
import net.nuage.vsp.acs.client.api.model.VspStaticNat;
import net.nuage.vsp.acs.client.api.model.VspVm;
import org.apache.cloudstack.resourcedetail.VpcDetailVO;
import org.apache.cloudstack.resourcedetail.dao.VpcDetailsDao;
import org.apache.log4j.Logger;
import javax.inject.Inject;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
public static final Logger s_logger = Logger.getLogger(NuageVspGuestNetworkGuru.class);
@ -108,6 +102,12 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
NuageVspManager _nuageVspManager;
@Inject
ConfigurationManager _configMgr;
@Inject
NuageVspEntityBuilder _nuageVspEntityBuilder;
@Inject
NetworkDetailsDao _networkDetailsDao;
@Inject
VpcDetailsDao _vpcDetailsDao;
public NuageVspGuestNetworkGuru() {
super();
@ -148,33 +148,6 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
throw new IllegalStateException("Network " + networkId + " is not in expected state Implementing, but is in state " + network.getState());
}
long dcId = dest.getDataCenter().getId();
//Get physical network id
Long physicalNetworkId = network.getPhysicalNetworkId();
//Physical network id can be null in Guest Network in Basic zone, so locate the physical network
if (physicalNetworkId == null) {
physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
}
implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
if (network.getGateway() != null) {
implemented.setGateway(network.getGateway());
}
if (network.getCidr() != null) {
implemented.setCidr(network.getCidr());
}
List<String[]> ipAddressRanges = new ArrayList<String[]>();
String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
String networkUuid = implemented.getUuid();
String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
String broadcastUriStr = networkUuid + "/" + virtualRouterIp;
implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
//Check if the network is associated to a VPC
Long vpcId = network.getVpcId();
boolean isVpc = (vpcId != null);
//Check owner of the Network
Domain networksDomain = _domainDao.findById(network.getDomainId());
//Get the Account details and find the type
AccountVO networksAccount = _accountDao.findById(network.getAccountId());
if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
@ -183,52 +156,37 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
s_logger.error(errorMessage);
throw new InsufficientVirtualNetworkCapacityException(errorMessage, Account.class, network.getAccountId());
}
String vpcName = null;
String vpcUuid = null;
String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configDao, network, offering);
boolean isSharedNetwork = offering.getGuestType() == GuestType.Shared;
boolean isL3Network = !isVpc && (isSharedNetwork || isL3Network(network));
if (isVpc) {
Vpc vpcObj = _vpcDao.findById(vpcId);
vpcName = vpcObj.getName();
vpcUuid = vpcObj.getUuid();
long dcId = dest.getDataCenter().getId();
//Get physical network id
Long physicalNetworkId = network.getPhysicalNetworkId();
//Physical network id can be null in Guest Network in Basic zone, so locate the physical network
if (physicalNetworkId == null) {
physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
}
if (isSharedNetwork) {
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
for (VlanVO vlan : vlans) {
boolean isIpv4 = StringUtils.isNotBlank(vlan.getIpRange());
String[] range = isIpv4 ? vlan.getIpRange().split("-") : vlan.getIp6Range().split("-");
ipAddressRanges.add(range);
}
implemented = new NetworkVO(network.getId(), network, network.getNetworkOfferingId(), network.getGuruName(), network.getDomainId(), network.getAccountId(),
network.getRelated(), network.getName(), network.getDisplayText(), network.getNetworkDomain(), network.getGuestType(), network.getDataCenterId(),
physicalNetworkId, network.getAclType(), network.getSpecifyIpRanges(), network.getVpcId(), offering.getRedundantRouter());
implemented.setUuid(network.getUuid());
implemented.setState(State.Allocated);
if (network.getGateway() != null) {
implemented.setGateway(network.getGateway());
}
if (network.getCidr() != null) {
implemented.setCidr(network.getCidr());
}
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(implemented, true);
String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
String broadcastUriStr = implemented.getUuid() + "/" + vspNetwork.getVirtualRouterIp();
implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
HostVO nuageVspHost = getNuageVspHost(physicalNetworkId);
List<String> dnsServers = _nuageVspManager.getDnsDetails(network);
List<String> gatewaySystemIds = _nuageVspManager.getGatewaySystemIds();
ImplementNetworkVspCommand.Builder cmdBuilder = new ImplementNetworkVspCommand.Builder()
.networkDomainName(networksDomain.getName())
.networkDomainPath(networksDomain.getPath())
.networkDomainUuid(networksDomain.getUuid())
.networkAccountName(networksAccount.getAccountName())
.networkAccountUuid(networksAccount.getUuid())
.networkName(network.getName())
.networkCidr(network.getCidr())
.networkGateway(network.getGateway())
.networkAclId(network.getNetworkACLId())
.dnsServers(dnsServers)
.gatewaySystemIds(gatewaySystemIds)
.networkUuid(network.getUuid())
.isL3Network(isL3Network)
.isVpc(isVpc)
.isSharedNetwork(isSharedNetwork)
.vpcName(vpcName)
.vpcUuid(vpcUuid)
.defaultEgressPolicy(offering.getEgressDefaultPolicy())
.ipAddressRange(ipAddressRanges)
.domainTemplateName(preConfiguredDomainTemplateName);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
ImplementNetworkVspCommand cmd = new ImplementNetworkVspCommand(vspNetwork, dnsServers);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ImplementNetworkVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
@ -237,7 +195,18 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
}
return null;
}
s_logger.info("Implemented OK, network " + networkUuid + " in tenant " + tenantId + " linked to " + implemented.getBroadcastUri());
if (StringUtils.isNotBlank(vspNetwork.getDomainTemplateName())) {
if (network.getVpcId() != null) {
VpcDetailVO vpcDetail = new VpcDetailVO(network.getVpcId(), NuageVspManager.nuageDomainTemplateDetailName, vspNetwork.getDomainTemplateName(), false);
_vpcDetailsDao.persist(vpcDetail);
} else {
NetworkDetailVO networkDetail = new NetworkDetailVO(implemented.getId(), NuageVspManager.nuageDomainTemplateDetailName, vspNetwork.getDomainTemplateName(), false);
_networkDetailsDao.persist(networkDetail);
}
}
s_logger.info("Implemented OK, network " + implemented.getUuid() + " in tenant " + tenantId + " linked to " + implemented.getBroadcastUri());
} finally {
_networkDao.releaseFromLockTable(network.getId());
}
@ -262,68 +231,38 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
}
nic.setBroadcastUri(network.getBroadcastUri());
nic.setIsolationUri(network.getBroadcastUri());
DataCenter dc = _dcDao.findById(network.getDataCenterId());
Account networksAccount = _accountDao.findById(network.getAccountId());
DomainVO networksDomain = _domainDao.findById(network.getDomainId());
//Get the Account details and find the type
long networkOwnedBy = network.getAccountId();
AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
AccountVO neworkAccountDetails = _accountDao.findById(network.getAccountId());
if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
throw new InsufficientVirtualNetworkCapacityException("CS project support is not yet implemented in NuageVsp", DataCenter.class, dc.getId());
}
//NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
//that we create in VSP
NicVO nicFrmDB = _nicDao.findById(nic.getId());
NetworkOffering networkOffering = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
boolean isDomainRouter = vm.getType().equals(VirtualMachine.Type.DomainRouter);
URI broadcastUri = network.getBroadcastUri();
if (Strings.isNullOrEmpty(broadcastUri.getPath()) || !broadcastUri.getPath().startsWith("/")) {
if (Strings.isNullOrEmpty(network.getBroadcastUri().getPath()) || !network.getBroadcastUri().getPath().startsWith("/")) {
throw new IllegalStateException("The broadcast URI path " + network.getBroadcastUri() + " is empty or in an incorrect format.");
}
String domainRouterIp = network.getBroadcastUri().getPath().substring(1);
boolean isL3Network = isL3Network(network);
boolean isSharedNetwork = networkOffering.getGuestType() == GuestType.Shared;
Long vpcId = network.getVpcId();
String vpcUuid = null;
if (vpcId != null) {
Vpc vpcObj = _vpcDao.findById(vpcId);
vpcUuid = vpcObj.getUuid();
}
HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
nic.setBroadcastUri(network.getBroadcastUri());
nic.setIsolationUri(network.getBroadcastUri());
//NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
//that we create in VSP
NicVO nicFromDb = _nicDao.findById(nic.getId());
IPAddressVO staticNatIp = _ipAddressDao.findByVmIdAndNetworkId(network.getId(), vm.getId());
ReserveVmInterfaceVspCommand.Builder cmdBuilder = new ReserveVmInterfaceVspCommand.Builder()
.nicUuid(nicFrmDB.getUuid())
.nicMacAddress(nic.getMacAddress())
.networkUuid(network.getUuid())
.isL3Network(isL3Network)
.isSharedNetwork(isSharedNetwork)
.vpcUuid(vpcUuid)
.networkDomainUuid(networksDomain.getUuid())
.networksAccountUuid(networksAccount.getUuid())
.isDomainRouter(isDomainRouter)
.domainRouterIp(domainRouterIp)
.vmInstanceName(vm.getInstanceName())
.vmUuid(vm.getUuid())
.vmUserName(networksDomain.getUuid())
.vmUserDomainName(networksAccount.getUuid())
.useStaticIp(true)
.staticIp(nic.getIPv4Address());
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network, false);
VspVm vspVm = _nuageVspEntityBuilder.buildVspVm(vm.getVirtualMachine(), network);
VspNic vspNic = _nuageVspEntityBuilder.buildVspNic(nicFromDb.getUuid(), nic);
VspStaticNat vspStaticNat = null;
if (staticNatIp != null) {
VlanVO staticNatVlan = _vlanDao.findById(staticNatIp.getVlanId());
cmdBuilder = cmdBuilder.staticNatIpUuid(staticNatIp.getUuid())
.staticNatIpAddress(staticNatIp.getAddress().addr())
.isStaticNatIpAllocated(staticNatIp.getState().equals(IpAddress.State.Allocated))
.isOneToOneNat(staticNatIp.isOneToOneNat())
.staticNatVlanUuid(staticNatVlan.getUuid())
.staticNatVlanGateway(staticNatVlan.getVlanGateway())
.staticNatVlanNetmask(staticNatVlan.getVlanNetmask());
vspStaticNat = _nuageVspEntityBuilder.buildVspStaticNat(null, staticNatIp, staticNatVlan, null);
}
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(vspNetwork, vspVm, vspNic, vspStaticNat);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ReserveVmInterfaceNuageVspCommand failed for NIC " + nic.getId() + " attached to VM " + vm.getId() + " in network " + network.getId());
if ((null != answer) && (null != answer.getDetails())) {
@ -332,8 +271,8 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
throw new InsufficientVirtualNetworkCapacityException("Failed to reserve VM in Nuage VSP.", Network.class, network.getId());
}
if (isDomainRouter) {
nic.setIPv4Address(domainRouterIp);
if (vspVm.getDomainRouter() == Boolean.TRUE) {
nic.setIPv4Address(vspVm.getDomainRouterIp());
}
} finally {
@ -378,32 +317,16 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
s_logger.debug("Handling deallocate() call back, which is called when a VM is destroyed or interface is removed, " + "to delete VM Interface with IP "
+ nic.getIPv4Address() + " from a VM " + vm.getInstanceName() + " with state " + vm.getVirtualMachine().getState());
}
DomainVO networksDomain = _domainDao.findById(network.getDomainId());
NicVO nicFrmDd = _nicDao.findById(nic.getId());
NetworkOffering networkOffering = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
boolean isL3Network = isL3Network(network);
boolean isSharedNetwork = networkOffering.getGuestType() == GuestType.Shared;
boolean isExpunging = vm.getVirtualMachine().getState() == VirtualMachine.State.Expunging;
Long vpcId = network.getVpcId();
String vpcUuid = null;
if (vpcId != null) {
Vpc vpcObj = _vpcDao.findById(vpcId);
vpcUuid = vpcObj.getUuid();
}
NicVO nicFromDb = _nicDao.findById(nic.getId());
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network, false);
VspVm vspVm = _nuageVspEntityBuilder.buildVspVm(vm.getVirtualMachine(), network);
VspNic vspNic = _nuageVspEntityBuilder.buildVspNic(nicFromDb.getUuid(), nic);
HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
DeallocateVmVspCommand.Builder cmdBuilder = new DeallocateVmVspCommand.Builder()
.networkUuid(network.getUuid())
.nicFromDbUuid(nicFrmDd.getUuid())
.nicMacAddress(nic.getMacAddress())
.nicIp4Address(nic.getIPv4Address())
.isL3Network(isL3Network)
.isSharedNetwork(isSharedNetwork)
.vpcUuid(vpcUuid)
.networksDomainUuid(networksDomain.getUuid())
.vmInstanceName(vm.getInstanceName())
.vmUuid(vm.getUuid())
.isExpungingState(isExpunging);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
DeallocateVmVspCommand cmd = new DeallocateVmVspCommand(vspNetwork, vspVm, vspNic);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("DeallocateVmNuageVspCommand for VM " + vm.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
@ -451,27 +374,10 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Handling trash() call back to delete the network " + network.getName() + " with uuid " + network.getUuid() + " from VSP");
}
long domainId = network.getDomainId();
Domain domain = _domainDao.findById(domainId);
boolean isL3Network = isL3Network(network);
boolean isSharedNetwork = offering.getGuestType() == GuestType.Shared;
Long vpcId = network.getVpcId();
String vpcUuid = null;
if (vpcId != null) {
Vpc vpcObj = _vpcDao.findById(vpcId);
vpcUuid = vpcObj.getUuid();
}
String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configDao, network, offering);
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network, false);
HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
TrashNetworkVspCommand.Builder cmdBuilder = new TrashNetworkVspCommand.Builder()
.domainUuid(domain.getUuid())
.networkUuid(network.getUuid())
.isL3Network(isL3Network)
.isSharedNetwork(isSharedNetwork)
.vpcUuid(vpcUuid)
.domainTemplateName(preConfiguredDomainTemplateName);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
TrashNetworkVspCommand cmd = new TrashNetworkVspCommand(vspNetwork);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("TrashNetworkNuageVspCommand for network " + network.getUuid() + " failed");
if ((null != answer) && (null != answer.getDetails())) {
@ -485,51 +391,6 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
return super.trash(network, offering);
}
private String getVirtualRouterIP(Network network, Collection<String[]> ipAddressRanges) throws InsufficientVirtualNetworkCapacityException {
String virtualRouterIp;
//Check if the subnet has minimum 5 host in it.
String subnet = NetUtils.getCidrSubNet(network.getCidr());
String netmask = NetUtils.getCidrNetmask(network.getCidr());
long cidrSize = NetUtils.getCidrSize(netmask);
Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>());
if (allIPsInCidr == null || !(allIPsInCidr instanceof TreeSet)) {
throw new IllegalStateException("The IPs in CIDR for subnet " + subnet + " where null or returned in a non-ordered set.");
}
if (allIPsInCidr.size() > 3) {
//get the second IP and see if it the networks GatewayIP
Iterator<Long> ipIterator = allIPsInCidr.iterator();
long vip = ipIterator.next();
if (NetUtils.ip2Long(network.getGateway()) == vip) {
vip = ipIterator.next();
virtualRouterIp = NetUtils.long2Ip(vip);
if (s_logger.isDebugEnabled()) {
s_logger.debug("1st IP is used as gateway IP. Reserving " + virtualRouterIp + " for the Virtual Router IP for Network(" + network.getName() + ")");
}
} else {
virtualRouterIp = NetUtils.long2Ip(vip);
if (s_logger.isDebugEnabled()) {
s_logger.debug("1st IP is not used as the gateway IP. Reserving" + virtualRouterIp + " for the Virtual Router IP for Network(" + network.getName() + ")");
}
}
ipAddressRanges.add(new String[] {
NetUtils.long2Ip(ipIterator.next()),
NetUtils.getIpRangeEndIpFromCidr(subnet, cidrSize)
});
return virtualRouterIp;
}
throw new InsufficientVirtualNetworkCapacityException("VSP allocates an IP for VirtualRouter." + " So, subnet should have atleast minimum 4 hosts ", Network.class,
network.getId());
}
private boolean isL3Network(Network network) {
return _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Service.SourceNat)
|| _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Service.StaticNat)
|| network.getGuestType() == GuestType.Shared;
}
private HostVO getNuageVspHost(long physicalNetworkId) {
HostVO nuageVspHost;
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);

View File

@ -40,6 +40,8 @@ public interface NuageVspManager extends PluggableService {
static final String nuageVPCOfferingDisplayText = "Nuage VSP VPC Offering";
static final String nuageDomainTemplateDetailName = "domainTemplateName";
static final ConfigKey<Boolean> NuageVspConfigDns = new ConfigKey<Boolean>(Boolean.class, "nuagevsp.configure.dns", "Advanced", "true",
"Defines if NuageVsp plugin needs to configure DNS setting for a VM or not. True will configure the DNS and false will not configure the DNS settings", true,
Scope.Global, null);

View File

@ -27,8 +27,8 @@ import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.PingNuageVspCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.manager.GetClientDefaultsAnswer;
import com.cloud.agent.api.manager.GetClientDefaultsCommand;
import com.cloud.agent.api.manager.GetApiDefaultsAnswer;
import com.cloud.agent.api.manager.GetApiDefaultsCommand;
import com.cloud.agent.api.manager.SupportedApiVersionCommand;
import com.cloud.agent.api.sync.SyncDomainAnswer;
import com.cloud.agent.api.sync.SyncDomainCommand;
@ -37,7 +37,6 @@ import com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand;
import com.cloud.api.ApiDBUtils;
import com.cloud.api.commands.AddNuageVspDeviceCmd;
import com.cloud.api.commands.DeleteNuageVspDeviceCmd;
import com.cloud.api.commands.IssueNuageVspResourceRequestCmd;
import com.cloud.api.commands.ListNuageVspDevicesCmd;
import com.cloud.api.commands.UpdateNuageVspDeviceCmd;
import com.cloud.api.response.NuageVspDeviceResponse;
@ -70,7 +69,6 @@ import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
import com.cloud.network.dao.PhysicalNetworkVO;
import com.cloud.network.resource.NuageVspResource;
import com.cloud.network.sync.NuageVspSync;
import com.cloud.network.vpc.VpcManager;
import com.cloud.network.vpc.VpcOffering;
import com.cloud.network.vpc.VpcOfferingServiceMapVO;
@ -106,7 +104,10 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.cloud.util.NuageVspEntityBuilder;
import net.nuage.vsp.acs.NuageVspPluginClientLoader;
import net.nuage.vsp.acs.client.api.model.VspApiDefaults;
import net.nuage.vsp.acs.client.api.model.VspDomain;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
@ -127,7 +128,6 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ScheduledExecutorService;
import static com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand.SyncType;
@ -135,8 +135,6 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
private static final Logger s_logger = Logger.getLogger(NuageVspManagerImpl.class);
private static final int ONE_MINUTE_MULTIPLIER = 60 * 1000;
public static final Map<Network.Service, Set<Network.Provider>> NUAGE_VSP_VPC_SERVICE_MAP;
private static final ConfigKey[] NUAGE_VSP_CONFIG_KEYS = new ConfigKey<?>[] { NuageVspConfigDns, NuageVspDnsExternal, NuageVspConfigGateway,
NuageVspSharedNetworkDomainTemplateName, NuageVspVpcDomainTemplateName, NuageVspIsolatedNetworkDomainTemplateName };
@ -164,8 +162,6 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
@Inject
NuageVspDao _nuageVspDao;
@Inject
NuageVspSync _nuageVspSync;
@Inject
DataCenterDao _dataCenterDao;
@Inject
ConfigurationDao _configDao;
@ -187,8 +183,8 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
NetworkOfferingDao _networkOfferingDao;
@Inject
NetworkOfferingServiceMapDao _networkOfferingServiceMapDao;
private ScheduledExecutorService scheduler;
@Inject
NuageVspEntityBuilder _nuageVspEntityBuilder;
@Inject
MessageBus _messageBus;
@ -212,7 +208,7 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
@Override
public List<Class<?>> getCommands() {
return Lists.<Class<?>>newArrayList(AddNuageVspDeviceCmd.class, DeleteNuageVspDeviceCmd.class, ListNuageVspDevicesCmd.class,
IssueNuageVspResourceRequestCmd.class, UpdateNuageVspDeviceCmd.class);
UpdateNuageVspDeviceCmd.class);
}
@Override
@ -242,21 +238,21 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
}
try {
NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(null, null, 1, 1, null);
NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(null, null, null, null, 1, 1, null);
Map<String, Object> clientDefaults = clientLoader.getNuageVspManagerClient().getClientDefaults();
String apiVersion = MoreObjects.firstNonNull(cmd.getApiVersion(), (String) clientDefaults.get("CURRENT_API_VERSION"));
VspApiDefaults apiDefaults = clientLoader.getNuageVspManagerClient().getApiDefaults();
String apiVersion = MoreObjects.firstNonNull(cmd.getApiVersion(), apiDefaults.getVersion());
if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(apiVersion)) {
throw new CloudRuntimeException("Unsupported API version : " + apiVersion);
}
int port = cmd.getPort();
if (0 == port) {
port = 8443;
port = 443;
}
String cmsUserPasswordBase64 = NuageVspUtil.encodePassword(cmd.getPassword());
String retryCount = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryCount(), clientDefaults.get("DEFAULT_API_RETRY_COUNT")));
String retryInterval = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryInterval(), clientDefaults.get("DEFAULT_API_RETRY_INTERVAL")));
String retryCount = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryCount(), apiDefaults.getRetryCount()));
String retryInterval = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryInterval(), apiDefaults.getRetryInterval()));
NuageVspResource.Configuration resourceConfiguration = new NuageVspResource.Configuration()
.name("Nuage VSD - " + cmd.getHostName())
.guid(UUID.randomUUID().toString())
@ -284,22 +280,33 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
_hostDetailsDao.persist(detail);
ConfigurationVO cmsIdConfig = _configDao.findByName("nuagevsp.cms.id");
host = findNuageVspHost(nuageVspDevice.getHostId());
SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.REGISTER, null);
SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
if (answer != null && answer.getSuccess()) {
registerNewNuageVspDevice(cmsIdConfig, nuageVspDevice.getId() + ":" + answer.getNuageVspCmsId());
detail = new DetailVO(host.getId(), "nuagevspcmsid", answer.getNuageVspCmsId());
_hostDetailsDao.persist(detail);
resourceConfiguration.nuageVspCmsId(answer.getNuageVspCmsId());
resource.configure(cmd.getHostName(), Maps.<String, Object>newHashMap(resourceConfiguration.build()));
auditDomainsOnVsp((HostVO) host, true, false);
NuageVspDeviceVO matchingNuageVspDevice = findMatchingNuageVspDevice(nuageVspDevice);
String cmsId;
if (matchingNuageVspDevice != null) {
cmsId = findNuageVspCmsIdForDevice(matchingNuageVspDevice.getId(), cmsIdConfig);
} else {
throw new CloudRuntimeException("Failed to register CMS ID");
SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.REGISTER, null);
SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
if (answer != null && answer.getSuccess()) {
cmsId = answer.getNuageVspCmsId();
} else {
throw new CloudRuntimeException("Failed to register CMS ID");
}
}
host = findNuageVspHost(nuageVspDevice.getHostId());
registerNewNuageVspDevice(cmsIdConfig, nuageVspDevice.getId() + ":" + cmsId);
detail = new DetailVO(host.getId(), "nuagevspcmsid", cmsId);
_hostDetailsDao.persist(detail);
resourceConfiguration.nuageVspCmsId(cmsId);
resource.configure(cmd.getHostName(), Maps.<String, Object>newHashMap(resourceConfiguration.build()));
if (matchingNuageVspDevice == null) {
auditDomainsOnVsp((HostVO) host, true, false);
}
return nuageVspDevice;
} catch (ConfigurationException e) {
s_logger.error("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
@ -372,13 +379,13 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
updateRequired = true;
}
GetClientDefaultsCommand getClientDefaultsCmd = new GetClientDefaultsCommand();
GetClientDefaultsAnswer getClientDefaultsAnswer = (GetClientDefaultsAnswer) _agentMgr.easySend(nuageVspHost.getId(), getClientDefaultsCmd);
GetApiDefaultsCommand apiDefaultsCmd = new GetApiDefaultsCommand();
GetApiDefaultsAnswer apiDefaultsAnswer = (GetApiDefaultsAnswer) _agentMgr.easySend(nuageVspHost.getId(), apiDefaultsCmd);
String apiVersion = MoreObjects.firstNonNull(command.getApiVersion(), resourceConfiguration.apiVersion());
SupportedApiVersionCommand supportedApiVersionCmd = new SupportedApiVersionCommand(apiVersion);
Answer supportedApiVersionAnswer = _agentMgr.easySend(nuageVspHost.getId(), supportedApiVersionCmd);
if (!supportedApiVersionAnswer.getResult()) {
throw new CloudRuntimeException("Incorrect API version: Nuage plugin only supports " + getClientDefaultsAnswer.getCurrentApiVersion());
throw new CloudRuntimeException("Incorrect API version: Nuage plugin only supports " + apiDefaultsAnswer.getApiDefaults().getVersion());
}
String apiRelativePath = "/nuage/api/" + apiVersion;
@ -474,25 +481,31 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
}
}
NuageVspDeviceVO matchingNuageVspDevice = findMatchingNuageVspDevice(nuageVspDevice);
ConfigurationVO cmsIdConfig = _configDao.findByName("nuagevsp.cms.id");
HostVO host = findNuageVspHost(nuageVspDevice.getHostId());
if (!auditDomainsOnVsp(host, false, true)) {
return false;
String nuageVspCmsId = findNuageVspCmsIdForDevice(nuageVspDevice.getId(), cmsIdConfig);
if (matchingNuageVspDevice == null) {
if (!auditDomainsOnVsp(host, false, true)) {
return false;
}
SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.UNREGISTER, nuageVspCmsId);
SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
if (answer == null || !answer.getSuccess()) {
return false;
}
}
String nuageVspCmsId = findNuageVspCmsIdForDevice(nuageVspDevice.getId(), cmsIdConfig);
SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.UNREGISTER, nuageVspCmsId);
SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
if (answer != null && answer.getSuccess()) {
String currentValue = cmsIdConfig.getValue();
String newValue = currentValue.replace(nuageVspDevice.getId() + ":" + answer.getNuageVspCmsId(), "");
if (!Strings.isNullOrEmpty(newValue) && newValue.startsWith(";")) {
newValue = newValue.substring(1);
}
_configDao.update("nuagevsp.cms.id", newValue);
} else {
return false;
String newValue = cmsIdConfig.getValue().replace(nuageVspDevice.getId() + ":" + nuageVspCmsId, "");
if (newValue.startsWith(";")) {
newValue = newValue.substring(1);
}
if (newValue.endsWith(";")) {
newValue = newValue.substring(0, newValue.length() - 1);
}
newValue = newValue.replaceAll(";+", ";");
_configDao.update("nuagevsp.cms.id", newValue);
HostVO nuageHost = _hostDao.findById(nuageVspDevice.getHostId());
Long hostId = nuageHost.getId();
@ -505,6 +518,22 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
return true;
}
private NuageVspDeviceVO findMatchingNuageVspDevice(NuageVspDeviceVO nuageVspDevice) {
List<NuageVspDeviceVO> otherNuageVspDevices = _nuageVspDao.listAll();
for (NuageVspDeviceVO otherNuageVspDevice : otherNuageVspDevices) {
if (otherNuageVspDevice.getId() == nuageVspDevice.getId()) continue;
HostVO nuageVspDeviceHost = findNuageVspHost(nuageVspDevice.getHostId());
HostVO otherNuageVspDeviceHost = findNuageVspHost(otherNuageVspDevice.getHostId());
String nuageVspDeviceHostName = nuageVspDeviceHost.getDetail("hostname");
String otherNuageVspDeviceHostName = otherNuageVspDeviceHost.getDetail("hostname");
if (otherNuageVspDeviceHostName != null && otherNuageVspDeviceHostName.equals(nuageVspDeviceHostName)) {
return otherNuageVspDevice;
}
}
return null;
}
@Override
public List<NuageVspDeviceVO> listNuageVspDevices(ListNuageVspDevicesCmd cmd) {
Long physicalNetworkId = cmd.getPhysicalNetworkId();
@ -551,6 +580,8 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
}
private void auditHost(HostVO host) {
if (host == null) return;
_hostDao.loadDetails(host);
boolean validateDomains = true;
@ -585,7 +616,8 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
_hostDao.loadDetails(host);
List<DomainVO> allDomains = _domainDao.listAll();
for (DomainVO domain : allDomains) {
SyncDomainCommand cmd = new SyncDomainCommand(domain.getUuid(), domain.getName(), domain.getPath(), add, remove);
VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, add, remove);
SyncDomainAnswer answer = (SyncDomainAnswer) _agentMgr.easySend(host.getId(), cmd);
return answer.getSuccess();
}
@ -683,7 +715,8 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
HostVO host = findNuageVspHost(nuageVspDevice.getHostId());
SyncDomainCommand cmd = new SyncDomainCommand(domain.getUuid(), domain.getName(), domain.getPath(), true, false);
VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, true, false);
_agentMgr.easySend(host.getId(), cmd);
}
} finally {
@ -700,7 +733,8 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
HostVO host = findNuageVspHost(nuageVspDevice.getHostId());
SyncDomainCommand cmd = new SyncDomainCommand(domain.getUuid(), domain.getName(), domain.getPath(), false, true);
VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, false, true);
_agentMgr.easySend(host.getId(), cmd);
}
}

View File

@ -30,8 +30,6 @@ import com.cloud.agent.api.ReadyAnswer;
import com.cloud.agent.api.ReadyCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupVspCommand;
import com.cloud.agent.api.VspResourceAnswer;
import com.cloud.agent.api.VspResourceCommand;
import com.cloud.agent.api.element.ApplyAclRuleVspCommand;
import com.cloud.agent.api.element.ApplyStaticNatVspCommand;
import com.cloud.agent.api.element.ImplementVspCommand;
@ -40,14 +38,13 @@ import com.cloud.agent.api.guru.DeallocateVmVspCommand;
import com.cloud.agent.api.guru.ImplementNetworkVspCommand;
import com.cloud.agent.api.guru.ReserveVmInterfaceVspCommand;
import com.cloud.agent.api.guru.TrashNetworkVspCommand;
import com.cloud.agent.api.manager.GetClientDefaultsAnswer;
import com.cloud.agent.api.manager.GetClientDefaultsCommand;
import com.cloud.agent.api.manager.GetApiDefaultsAnswer;
import com.cloud.agent.api.manager.GetApiDefaultsCommand;
import com.cloud.agent.api.manager.SupportedApiVersionCommand;
import com.cloud.agent.api.sync.SyncDomainAnswer;
import com.cloud.agent.api.sync.SyncDomainCommand;
import com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer;
import com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand;
import com.cloud.agent.api.sync.SyncVspCommand;
import com.cloud.host.Host;
import com.cloud.resource.ServerResource;
import com.cloud.util.NuageVspUtil;
@ -56,12 +53,11 @@ import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.exception.CloudRuntimeException;
import com.google.common.base.Strings;
import net.nuage.vsp.acs.NuageVspPluginClientLoader;
import net.nuage.vsp.acs.client.NuageVspApiClient;
import net.nuage.vsp.acs.client.NuageVspElementClient;
import net.nuage.vsp.acs.client.NuageVspGuruClient;
import net.nuage.vsp.acs.client.NuageVspManagerClient;
import net.nuage.vsp.acs.client.NuageVspSyncClient;
import org.apache.commons.lang3.tuple.Pair;
import net.nuage.vsp.acs.client.api.NuageVspApiClient;
import net.nuage.vsp.acs.client.api.NuageVspElementClient;
import net.nuage.vsp.acs.client.api.NuageVspGuruClient;
import net.nuage.vsp.acs.client.api.NuageVspManagerClient;
import net.nuage.vsp.acs.client.common.model.Pair;
import org.apache.log4j.Logger;
import javax.naming.ConfigurationException;
@ -91,7 +87,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
private String _name;
private String _guid;
private String _zoneId;
private String[] _cmsUserInfo;
private String _cmsUserLogin;
private String _cmsUserPassword;
private String _hostName;
private String _relativePath;
private int _numRetries;
@ -102,7 +99,6 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
protected NuageVspApiClient _nuageVspApiClient;
protected NuageVspGuruClient _nuageVspGuruClient;
protected NuageVspElementClient _nuageVspElementClient;
protected NuageVspSyncClient _nuageVspSyncClient;
protected NuageVspManagerClient _nuageVspManagerClient;
protected boolean _isNuageVspClientLoaded;
@ -190,7 +186,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
_relativePath = new StringBuffer().append("https://").append(_hostName).append(":").append(port).append(apiRelativePath).toString();
String cmsUserPass = NuageVspUtil.decodePassword(cmsUserPassBase64);
_cmsUserInfo = new String[] {CMS_USER_ENTEPRISE_NAME, cmsUser, cmsUserPass};
_cmsUserLogin = cmsUser;
_cmsUserPassword = cmsUserPass;
_nuageVspCmsId = (String)params.get(NUAGE_VSP_CMS_ID);
@ -199,8 +196,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
try {
login();
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failed to login to Nuage VSD on " + name + " as user " + cmsUser, e);
throw new CloudRuntimeException("Failed to login to Nuage VSD on " + name + " as user " + cmsUser, e);
s_logger.error(e.getMessage(), e);
throw new CloudRuntimeException(e.getMessage(), e);
}
return true;
@ -211,23 +208,14 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
_nuageVspApiClient.login();
}
protected <A extends NuageVspApiClient, B extends NuageVspElementClient, C extends NuageVspSyncClient, D extends NuageVspGuruClient> void loadNuageClient() {
try {
NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(_relativePath, _cmsUserInfo, _numRetries, _retryInterval, _nuageVspCmsId);
_nuageVspApiClient = clientLoader.getNuageVspApiClient();
_nuageVspSyncClient = clientLoader.getNuageVspSyncClient();
_nuageVspGuruClient = clientLoader.getNuageVspGuruClient();
_nuageVspElementClient = clientLoader.getNuageVspElementClient();
_nuageVspManagerClient = clientLoader.getNuageVspManagerClient();
_isNuageVspClientLoaded = true;
} catch (ConfigurationException e) {
_isNuageVspClientLoaded = false;
String errorMessage = "Nuage Vsp Plugin client is not yet installed. Please install NuageVsp plugin client to use NuageVsp plugin in Cloudstack. ";
s_logger.error(errorMessage, e);
throw new CloudRuntimeException(errorMessage, e);
}
protected <A extends NuageVspApiClient, B extends NuageVspElementClient, C extends NuageVspGuruClient> void loadNuageClient() {
NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(_relativePath, CMS_USER_ENTEPRISE_NAME,
_cmsUserLogin, _cmsUserPassword, _numRetries, _retryInterval, _nuageVspCmsId);
_nuageVspApiClient = clientLoader.getNuageVspApiClient();
_nuageVspGuruClient = clientLoader.getNuageVspGuruClient();
_nuageVspElementClient = clientLoader.getNuageVspElementClient();
_nuageVspManagerClient = clientLoader.getNuageVspManagerClient();
_isNuageVspClientLoaded = true;
}
@Override
@ -265,12 +253,12 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
@Override
public PingCommand getCurrentStatus(long id) {
if (_relativePath == null || _relativePath.isEmpty()) {
if (Strings.isNullOrEmpty(_relativePath)) {
s_logger.error("Refusing to ping Nuage VSD because the resource configuration is missing the relative path information");
_shouldAudit = true;
return null;
}
if (_cmsUserInfo == null || _cmsUserInfo.length < 2) {
if (Strings.isNullOrEmpty(_cmsUserLogin) || Strings.isNullOrEmpty(_cmsUserPassword)) {
s_logger.error("Refusing to ping Nuage VSD because the resource configuration is missing the CMS user information");
_shouldAudit = true;
return null;
@ -278,7 +266,7 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
try {
login();
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failed to ping to Nuage VSD on " + _name + " as user " + _cmsUserInfo[1], e);
s_logger.error("Failed to ping to Nuage VSD on " + _name + " as user " + _cmsUserLogin, e);
_shouldAudit = true;
return null;
}
@ -293,8 +281,6 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
return executeRequest((ReadyCommand)cmd);
} else if (cmd instanceof MaintainCommand) {
return executeRequest((MaintainCommand)cmd);
} else if (cmd instanceof VspResourceCommand) {
return executeRequest((VspResourceCommand)cmd);
}
//Guru commands
else if (cmd instanceof ImplementNetworkVspCommand) {
@ -317,16 +303,14 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
return executeRequest((ShutDownVpcVspCommand)cmd);
}
//Sync Commands
else if (cmd instanceof SyncVspCommand) {
return executeRequest((SyncVspCommand)cmd);
} else if (cmd instanceof SyncNuageVspCmsIdCommand) {
else if (cmd instanceof SyncNuageVspCmsIdCommand) {
return executeRequest((SyncNuageVspCmsIdCommand)cmd);
} else if (cmd instanceof SyncDomainCommand) {
return executeRequest((SyncDomainCommand)cmd);
}
//Other commands
else if (cmd instanceof GetClientDefaultsCommand) {
return executeRequest((GetClientDefaultsCommand)cmd);
else if (cmd instanceof GetApiDefaultsCommand) {
return executeRequest((GetApiDefaultsCommand)cmd);
} else if (cmd instanceof SupportedApiVersionCommand) {
return executeRequest((SupportedApiVersionCommand)cmd);
}
@ -357,29 +341,11 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
return new MaintainAnswer(cmd);
}
private Answer executeRequest(VspResourceCommand cmd) {
try {
isNuageVspApiLoaded();
if (cmd.getRequestType().equalsIgnoreCase("GETALL") || cmd.getRequestType().equalsIgnoreCase("GET") || cmd.getRequestType().equalsIgnoreCase("GETRELATED")) {
String resourceInfo = _nuageVspApiClient.executeRestApi(cmd.getRequestType(), cmd.getResource(), cmd.getResourceId(), cmd.getChildResource(),
cmd.getEntityDetails(), cmd.getResourceFilter(), cmd.getProxyUserUuid(), cmd.getProxyUserDomainuuid());
return new VspResourceAnswer(cmd, resourceInfo, "Executed Issue Resource command");
}
return new VspResourceAnswer(cmd, false, cmd.getRequestType() + " is not yet supported");
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new VspResourceAnswer(cmd, e);
}
}
private Answer executeRequest(ImplementNetworkVspCommand cmd) {
try {
isNuageVspGuruLoaded();
_nuageVspGuruClient.implement(cmd.getNetworkDomainName(), cmd.getNetworkDomainPath(), cmd.getNetworkDomainUuid(), cmd.getNetworkAccountName(),
cmd.getNetworkAccountUuid(), cmd.getNetworkName(), cmd.getNetworkCidr(), cmd.getNetworkGateway(), cmd.getNetworkAclId(), cmd.getDnsServers(),
cmd.getGatewaySystemIds(), cmd.isL3Network(), cmd.isVpc(), cmd.isSharedNetwork(), cmd.getNetworkUuid(), cmd.getVpcName(), cmd.getVpcUuid(),
cmd.isDefaultEgressPolicy(), cmd.getIpAddressRange(), cmd.getDomainTemplateName());
return new Answer(cmd, true, "Created network mapping to " + cmd.getNetworkName() + " on Nuage VSD " + _hostName);
_nuageVspGuruClient.implement(cmd.getNetwork(), cmd.getDnsServers());
return new Answer(cmd, true, "Created network mapping to " + cmd.getNetwork().getName() + " on Nuage VSD " + _hostName);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
@ -389,11 +355,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
private Answer executeRequest(ReserveVmInterfaceVspCommand cmd) {
try {
isNuageVspGuruLoaded();
_nuageVspGuruClient.reserve(cmd.getNicUuid(), cmd.getNicMacAddress(), cmd.getNetworkUuid(), cmd.isL3Network(),
cmd.isSharedNetwork(), cmd.getVpcUuid(), cmd.getNetworkDomainUuid(), cmd.getNetworksAccountUuid(), cmd.isDomainRouter(), cmd.getDomainRouterIp(),
cmd.getVmInstanceName(), cmd.getVmUuid(), cmd.useStaticIp(), cmd.getStaticIp(), cmd.getStaticNatIpUuid(), cmd.getStaticNatIpAddress(), cmd.isStaticNatIpAllocated(),
cmd.isOneToOneNat(), cmd.getStaticNatVlanUuid(), cmd.getStaticNatVlanGateway(), cmd.getStaticNatVlanNetmask());
return new Answer(cmd, true, "Created NIC that maps to nicUuid" + cmd.getNicUuid() + " on Nuage VSD " + _hostName);
_nuageVspGuruClient.reserve(cmd.getNetwork(), cmd.getVm(), cmd.getNic(), cmd.getStaticNat());
return new Answer(cmd, true, "Created NIC that maps to nicUuid" + cmd.getNic().getUuid() + " on Nuage VSD " + _hostName);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
@ -403,9 +366,9 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
private Answer executeRequest(DeallocateVmVspCommand cmd) {
try {
isNuageVspGuruLoaded();
_nuageVspGuruClient.deallocate(cmd.getNetworkUuid(), cmd.getNicFromDdUuid(), cmd.getNicMacAddress(), cmd.getNicIp4Address(), cmd.isL3Network(), cmd.isSharedNetwork(),
cmd.getVpcUuid(), cmd.getNetworksDomainUuid(), cmd.getVmInstanceName(), cmd.getVmUuid(), cmd.isExpungingState());
return new Answer(cmd, true, "Deallocated VM " + cmd.getVmInstanceName() + " on Nuage VSD " + _hostName);
_nuageVspGuruClient.deallocate(cmd.getNetwork(), cmd.getVm(), cmd.getNic());
return new Answer(cmd, true, "Deallocated VM " + cmd.getVm().getName() + " on Nuage VSD " + _hostName);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
@ -415,8 +378,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
private Answer executeRequest(TrashNetworkVspCommand cmd) {
try {
isNuageVspGuruLoaded();
_nuageVspGuruClient.trash(cmd.getDomainUuid(), cmd.getNetworkUuid(), cmd.isL3Network(), cmd.isSharedNetwork(), cmd.getVpcUuid(), cmd.getDomainTemplateName());
return new Answer(cmd, true, "Deleted network mapping to " + cmd.getNetworkUuid() + " on Nuage VSD " + _hostName);
_nuageVspGuruClient.trash(cmd.getNetwork());
return new Answer(cmd, true, "Deleted network mapping to " + cmd.getNetwork().getUuid() + " on Nuage VSD " + _hostName);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
@ -426,9 +389,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
private Answer executeRequest(ApplyStaticNatVspCommand cmd) {
try {
isNuageVspElementLoaded();
_nuageVspElementClient.applyStaticNats(cmd.getNetworkDomainUuid(), cmd.getNetworkUuid(), cmd.getVpcOrSubnetUuid(), cmd.isL3Network(),
cmd.isVpc(), cmd.getStaticNatDetails());
return new Answer(cmd, true, "Applied Static NAT to network mapping " + cmd.getVpcOrSubnetUuid() + " on Nuage VSD " + _hostName);
_nuageVspElementClient.applyStaticNats(cmd.getNetwork(), cmd.getStaticNatDetails());
return new Answer(cmd, true, "Applied Static NAT to network mapping " + cmd.getNetwork().getUuid() + " on Nuage VSD " + _hostName);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
@ -438,10 +400,9 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
private Answer executeRequest(ImplementVspCommand cmd) {
try {
isNuageVspElementLoaded();
boolean success = _nuageVspElementClient.implement(cmd.getNetworkId(), cmd.getNetworkDomainUuid(), cmd.getNetworkUuid(), cmd.getNetworkName(), cmd.getVpcOrSubnetUuid(), cmd.isL2Network(),
cmd.isL3Network(), cmd.isVpc(), cmd.isShared(), cmd.getDomainTemplateName(), cmd.isFirewallServiceSupported(), cmd.getDnsServers(), cmd.getIngressFirewallRules(),
cmd.getEgressFirewallRules(), cmd.getAcsFipUuid(), cmd.isEgressDefaultPolicy());
return new Answer(cmd, success, "Implemented network " + cmd.getNetworkUuid() + " on Nuage VSD " + _hostName);
boolean success = _nuageVspElementClient.implement(cmd.getNetwork(), cmd.getDnsServers(), cmd.getIngressFirewallRules(),
cmd.getEgressFirewallRules(), cmd.getFloatingIpUuids());
return new Answer(cmd, success, "Implemented network " + cmd.getNetwork().getUuid() + " on Nuage VSD " + _hostName);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
@ -451,9 +412,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
private Answer executeRequest(ApplyAclRuleVspCommand cmd) {
try {
isNuageVspElementLoaded();
_nuageVspElementClient.applyAclRules(cmd.isNetworkAcl(), cmd.getNetworkUuid(), cmd.getNetworkDomainUuid(), cmd.getVpcOrSubnetUuid(), cmd.getNetworkName(),
cmd.isL2Network(), cmd.getAclRules(), cmd.getNetworkId(), cmd.isEgressDefaultPolicy(), cmd.getAcsIngressAcl(), cmd.isNetworkReset(), cmd.getDomainTemplateName());
return new Answer(cmd, true, "Applied ACL Rule to network mapping " + cmd.getVpcOrSubnetUuid() + " on Nuage VSD " + _hostName);
_nuageVspElementClient.applyAclRules(cmd.getAclType(), cmd.getNetwork(), cmd.getAclRules(), cmd.isNetworkReset());
return new Answer(cmd, true, "Applied ACL Rule to network mapping " + cmd.getNetwork().getUuid() + " on Nuage VSD " + _hostName);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
@ -463,7 +423,7 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
private Answer executeRequest(ShutDownVpcVspCommand cmd) {
try {
isNuageVspElementLoaded();
_nuageVspElementClient.shutdownVpc(cmd.getDomainUuid(), cmd.getVpcUuid(), cmd.getDomainTemplateName());
_nuageVspElementClient.shutdownVpc(cmd.getDomainUuid(), cmd.getVpcUuid(), cmd.getDomainTemplateName(), cmd.getDomainRouterUuids());
return new Answer(cmd, true, "Shutdown VPC " + cmd.getVpcUuid() + " on Nuage VSD " + _hostName);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
@ -471,17 +431,6 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
}
}
private Answer executeRequest(SyncVspCommand cmd) {
try {
isNuageVspSyncLoaded();
_nuageVspSyncClient.syncWithNuageVsp(cmd.getNuageVspEntity());
return new Answer(cmd, true, "Synced " + cmd.getNuageVspEntity() + " on Nuage VSD " + _hostName);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
}
}
private Answer executeRequest(SyncNuageVspCmsIdCommand cmd) {
try {
isNuageVspManagerLoaded();
@ -504,7 +453,7 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
private Answer executeRequest(SyncDomainCommand cmd) {
try {
isNuageVspManagerLoaded();
boolean success = _nuageVspManagerClient.syncDomainWithNuageVsp(cmd.getDomainUuid(), cmd.getDomainName(), cmd.getDomainPath(), cmd.isToAdd(), cmd.isToRemove());
boolean success = _nuageVspManagerClient.syncDomainWithNuageVsp(cmd.getDomain(), cmd.isToAdd(), cmd.isToRemove());
return new SyncDomainAnswer(success);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
@ -512,14 +461,13 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
}
}
private Answer executeRequest(GetClientDefaultsCommand cmd) {
private Answer executeRequest(GetApiDefaultsCommand cmd) {
try {
isNuageVspManagerLoaded();
Map<String, Object> clientDefaults = _nuageVspManagerClient.getClientDefaults();
return new GetClientDefaultsAnswer(cmd, clientDefaults);
return new GetApiDefaultsAnswer(cmd, _nuageVspManagerClient.getApiDefaults());
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new GetClientDefaultsAnswer(cmd, e);
return new GetApiDefaultsAnswer(cmd, e);
}
}
@ -552,12 +500,6 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
}
}
protected void isNuageVspSyncLoaded() throws ConfigurationException {
if (!_isNuageVspClientLoaded || _nuageVspSyncClient == null) {
throw new ConfigurationException(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
}
}
protected void isNuageVspManagerLoaded() throws ConfigurationException {
if (!_isNuageVspClientLoaded || _nuageVspManagerClient == null) {
throw new ConfigurationException(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);

View File

@ -1,26 +0,0 @@
//
// 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 com.cloud.network.sync;
public interface NuageVspSync {
public void syncWithNuageVsp(String nuageVspEntity);
}

View File

@ -1,65 +0,0 @@
//
// 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 com.cloud.network.sync;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.sync.SyncVspCommand;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.network.NuageVspDeviceVO;
import com.cloud.network.dao.NuageVspDao;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.util.List;
@Component
public class NuageVspSyncImpl implements NuageVspSync {
private static final Logger s_logger = Logger.getLogger(NuageVspSyncImpl.class);
@Inject
NuageVspDao _nuageVspDao;
@Inject
HostDao _hostDao;
@Inject
AgentManager _agentMgr;
public void syncWithNuageVsp(String nuageVspEntity) {
//Get the NuageVspDevice and get the host information.
//This information is used to query VSP and synch the corresponding
//entities
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
HostVO nuageVspHost = _hostDao.findById(nuageVspDevice.getHostId());
_hostDao.loadDetails(nuageVspHost);
SyncVspCommand cmd = new SyncVspCommand(nuageVspEntity);
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("SyncNuageVspCommand for Nuage VSP Host " + nuageVspHost.getUuid() + " failed");
if ((null != answer) && (null != answer.getDetails())) {
s_logger.error(answer.getDetails());
}
}
}
}
}

View File

@ -0,0 +1,370 @@
//
// 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 com.cloud.util;
import com.cloud.dc.VlanVO;
import com.cloud.dc.dao.VlanDao;
import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.InsufficientVirtualNetworkCapacityException;
import com.cloud.network.Network;
import com.cloud.network.NetworkModel;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.network.dao.NetworkDetailsDao;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.vpc.NetworkACLItem;
import com.cloud.network.vpc.VpcVO;
import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.user.AccountVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.VirtualMachine;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import net.nuage.vsp.acs.client.api.model.VspAclRule;
import net.nuage.vsp.acs.client.api.model.VspDomain;
import net.nuage.vsp.acs.client.api.model.VspNetwork;
import net.nuage.vsp.acs.client.api.model.VspNic;
import net.nuage.vsp.acs.client.api.model.VspStaticNat;
import net.nuage.vsp.acs.client.api.model.VspVm;
import net.nuage.vsp.acs.client.common.model.Pair;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import javax.inject.Inject;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
public class NuageVspEntityBuilder {
private static final Logger s_logger = Logger.getLogger(NuageVspEntityBuilder.class);
@Inject
VpcDao _vpcDao;
@Inject
DomainDao _domainDao;
@Inject
AccountDao _accountDao;
@Inject
NetworkOfferingDao _networkOfferingDao;
@Inject
NetworkOfferingServiceMapDao _networkOfferingServiceMapDao;
@Inject
NetworkModel _networkModel;
@Inject
VlanDao _vlanDao;
@Inject
ConfigurationDao _configurationDao;
@Inject
IPAddressDao _ipAddressDao;
@Inject
NetworkDetailsDao _networkDetailsDao;
public VspDomain buildVspDomain(Domain domain) {
return new VspDomain.Builder()
.uuid(domain.getUuid())
.name(domain.getName())
.path(domain.getPath())
.build();
}
public VspNetwork buildVspNetwork(Network network, boolean fillAddressRange) {
VspNetwork.Builder vspNetworkBuilder = new VspNetwork.Builder()
.id(network.getId())
.uuid(network.getUuid())
.name(network.getName())
.cidr(network.getCidr())
.gateway(network.getGateway());
DomainVO domain = _domainDao.findById(network.getDomainId());
VspDomain vspDomain = buildVspDomain(domain);
vspNetworkBuilder.domain(vspDomain);
AccountVO account = _accountDao.findById(network.getAccountId());
if (account != null) {
vspNetworkBuilder.accountUuid(account.getUuid()).accountName(account.getAccountName());
}
NetworkOfferingVO networkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId());
vspNetworkBuilder.egressDefaultPolicy(networkOffering.getEgressDefaultPolicy());
if (network.getVpcId() != null) {
VpcVO vpc = _vpcDao.findById(network.getVpcId());
vspNetworkBuilder.vpcUuid(vpc.getUuid())
.vpcName(vpc.getName())
.networkType(VspNetwork.NetworkType.Vpc);
} else {
if (networkOffering.getGuestType() == Network.GuestType.Shared) {
vspNetworkBuilder.networkType(VspNetwork.NetworkType.Shared);
} else if (_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.SourceNat)
|| _networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.StaticNat)) {
vspNetworkBuilder.networkType(VspNetwork.NetworkType.L3);
} else {
vspNetworkBuilder.networkType(VspNetwork.NetworkType.L2);
}
}
boolean firewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.Firewall);
vspNetworkBuilder.firewallServiceSupported(firewallServiceSupported);
String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configurationDao, _networkDetailsDao, network, networkOffering);
vspNetworkBuilder.domainTemplateName(preConfiguredDomainTemplateName);
if (fillAddressRange) {
try {
List<Pair<String, String>> ipAddressRanges = getIpAddressRanges(networkOffering, network);
vspNetworkBuilder.ipAddressRanges(ipAddressRanges);
String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
vspNetworkBuilder.virtualRouterIp(virtualRouterIp);
} catch (InsufficientVirtualNetworkCapacityException ex) {
s_logger.error("There is an insufficient network capacity in network " + network.getId(), ex);
throw new CloudRuntimeException("There is an insufficient network capacity in network " + network.getId(), ex);
}
}
return vspNetworkBuilder.build();
}
private List<Pair<String, String>> getIpAddressRanges(NetworkOfferingVO networkOffering, Network network) {
List<Pair<String, String>> ipAddressRanges = Lists.newArrayList();
if (networkOffering.getGuestType() == Network.GuestType.Shared) {
List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
ipAddressRanges = Lists.newArrayList();
for (VlanVO vlan : vlans) {
boolean isIpv4 = StringUtils.isNotBlank(vlan.getIpRange());
String[] range = isIpv4 ? vlan.getIpRange().split("-") : vlan.getIp6Range().split("-");
if (range.length == 2) {
ipAddressRanges.add(Pair.of(range[0], range[1]));
}
}
return ipAddressRanges;
}
String subnet = NetUtils.getCidrSubNet(network.getCidr());
String netmask = NetUtils.getCidrNetmask(network.getCidr());
long cidrSize = NetUtils.getCidrSize(netmask);
Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>());
if (allIPsInCidr == null || !(allIPsInCidr instanceof TreeSet)) {
throw new IllegalStateException("The IPs in CIDR for subnet " + subnet + " where null or returned in a non-ordered set.");
}
Iterator<Long> ipIterator = allIPsInCidr.iterator();
long ip = ipIterator.next();
if (NetUtils.ip2Long(network.getGateway()) == ip) {
ip = ipIterator.next();
}
ipAddressRanges.add(Pair.of(NetUtils.long2Ip(ip), NetUtils.getIpRangeEndIpFromCidr(subnet, cidrSize)));
return ipAddressRanges;
}
private String getVirtualRouterIP(Network network, List<Pair<String, String>> ipAddressRanges) throws InsufficientVirtualNetworkCapacityException {
Pair<String, String> lowestIpAddressRange = null;
if (ipAddressRanges.size() == 1) {
lowestIpAddressRange = Iterables.getOnlyElement(ipAddressRanges);
} else {
for (Pair<String, String> ipAddressRange : ipAddressRanges) {
if (lowestIpAddressRange == null || NetUtils.ip2Long(ipAddressRange.getLeft()) < NetUtils.ip2Long(lowestIpAddressRange.getLeft())) {
lowestIpAddressRange = ipAddressRange;
}
}
}
if (lowestIpAddressRange == null) {
throw new InsufficientVirtualNetworkCapacityException("VSP allocates an IP for VirtualRouter." + " But no ip address ranges are specified", Network.class,
network.getId());
} else if (NetUtils.ip2Long(lowestIpAddressRange.getRight()) - NetUtils.ip2Long(lowestIpAddressRange.getLeft()) < 2) {
throw new InsufficientVirtualNetworkCapacityException("VSP allocates an IP for VirtualRouter." + " So, subnet should have atleast minimum 3 hosts", Network.class,
network.getId());
}
String virtualRouterIp = lowestIpAddressRange.getLeft();
long lowestIp = NetUtils.ip2Long(lowestIpAddressRange.getLeft());
lowestIp = lowestIp + 1;
lowestIpAddressRange.setLeft(NetUtils.long2Ip(lowestIp));
return virtualRouterIp;
}
public VspVm buildVspVm(VirtualMachine vm, Network network) {
VspVm.Builder vspVmBuilder = new VspVm.Builder()
.uuid(vm.getUuid())
.name(vm.getInstanceName());
switch (vm.getState()) {
case Starting:
vspVmBuilder.state(VspVm.State.Starting); break;
case Running:
vspVmBuilder.state(VspVm.State.Running); break;
case Stopping:
vspVmBuilder.state(VspVm.State.Stopping); break;
case Stopped:
vspVmBuilder.state(VspVm.State.Stopped); break;
case Destroyed:
vspVmBuilder.state(VspVm.State.Destroyed); break;
case Expunging:
vspVmBuilder.state(VspVm.State.Expunging); break;
case Migrating:
vspVmBuilder.state(VspVm.State.Migrating); break;
case Error:
vspVmBuilder.state(VspVm.State.Error); break;
case Shutdowned:
vspVmBuilder.state(VspVm.State.Shutdowned); break;
default:
vspVmBuilder.state(VspVm.State.Unknown);
}
boolean isDomainRouter = vm.getType().equals(VirtualMachine.Type.DomainRouter);
vspVmBuilder.domainRouter(isDomainRouter);
if (network.getBroadcastUri() != null) {
String domainRouterIp = network.getBroadcastUri().getPath().substring(1);
vspVmBuilder.domainRouterIp(domainRouterIp);
}
return vspVmBuilder.build();
}
public VspNic buildVspNic(String nicUuid, NicProfile nicProfile) {
VspNic.Builder vspNicBuilder = new VspNic.Builder()
.uuid(nicUuid)
.macAddress(nicProfile.getMacAddress())
.useStaticIp(true)
.ip(nicProfile.getIPv4Address());
return vspNicBuilder.build();
}
public VspNic buildVspNic(NicVO nic) {
VspNic.Builder vspNicBuilder = new VspNic.Builder()
.uuid(nic.getUuid())
.macAddress(nic.getMacAddress())
.useStaticIp(true)
.ip(nic.getIPv4Address());
return vspNicBuilder.build();
}
public VspStaticNat buildVspStaticNat(Boolean forRevoke, IPAddressVO staticNatIp, VlanVO staticNatVlan, NicVO nic) {
VspStaticNat.Builder vspStaticNatBuilder = new VspStaticNat.Builder()
.ipUuid(staticNatIp.getUuid())
.ipAddress(staticNatIp.getAddress().addr())
.revoke(forRevoke)
.oneToOneNat(staticNatIp.isOneToOneNat())
.vlanUuid(staticNatVlan.getUuid())
.vlanGateway(staticNatVlan.getVlanGateway())
.vlanNetmask(staticNatVlan.getVlanNetmask());
if (nic != null) {
VspNic vspNic = buildVspNic(nic);
vspStaticNatBuilder.nic(vspNic);
}
return vspStaticNatBuilder.build();
}
public VspAclRule buildVspAclRule(FirewallRule firewallRule, Network network) {
VspAclRule.Builder vspAclRuleBuilder = new VspAclRule.Builder()
.uuid(firewallRule.getUuid())
.protocol(firewallRule.getProtocol())
.startPort(firewallRule.getSourcePortStart())
.endPort(firewallRule.getSourcePortEnd())
.sourceCidrList(firewallRule.getSourceCidrList())
.priority(-1)
.type(VspAclRule.ACLType.Firewall);
switch (firewallRule.getState()) {
case Active:
vspAclRuleBuilder.state(VspAclRule.ACLState.Active); break;
case Add:
vspAclRuleBuilder.state(VspAclRule.ACLState.Add); break;
case Revoke:
vspAclRuleBuilder.state(VspAclRule.ACLState.Revoke);
}
switch (firewallRule.getTrafficType()) {
case Ingress:
vspAclRuleBuilder.trafficType(VspAclRule.ACLTrafficType.Ingress); break;
case Egress:
vspAclRuleBuilder.trafficType(VspAclRule.ACLTrafficType.Egress);
}
NetworkOfferingVO networkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId());
if (firewallRule.getTrafficType() == FirewallRule.TrafficType.Egress && networkOffering.getEgressDefaultPolicy()) {
vspAclRuleBuilder.action(VspAclRule.ACLAction.Deny);
} else {
vspAclRuleBuilder.action(VspAclRule.ACLAction.Allow);
}
if (firewallRule.getSourceIpAddressId() != null) {
IPAddressVO ipAddress = _ipAddressDao.findById(firewallRule.getSourceIpAddressId());
if (ipAddress != null) {
vspAclRuleBuilder.sourceIpAddress(ipAddress.getVmIp() + "/32");
}
}
return vspAclRuleBuilder.build();
}
public VspAclRule buildVspAclRule(NetworkACLItem networkAcl) {
VspAclRule.Builder vspAclRuleBuilder = new VspAclRule.Builder()
.uuid(networkAcl.getUuid())
.protocol(networkAcl.getProtocol())
.startPort(networkAcl.getSourcePortStart())
.endPort(networkAcl.getSourcePortEnd())
.sourceIpAddress(null)
.sourceCidrList(networkAcl.getSourceCidrList())
.priority(networkAcl.getNumber())
.type(VspAclRule.ACLType.NetworkACL);
switch (networkAcl.getState()) {
case Active:
vspAclRuleBuilder.state(VspAclRule.ACLState.Active); break;
case Add:
vspAclRuleBuilder.state(VspAclRule.ACLState.Add); break;
case Revoke:
vspAclRuleBuilder.state(VspAclRule.ACLState.Revoke);
}
switch (networkAcl.getTrafficType()) {
case Ingress:
vspAclRuleBuilder.trafficType(VspAclRule.ACLTrafficType.Ingress); break;
case Egress:
vspAclRuleBuilder.trafficType(VspAclRule.ACLTrafficType.Egress);
}
switch (networkAcl.getAction()) {
case Allow:
vspAclRuleBuilder.action(VspAclRule.ACLAction.Allow); break;
case Deny:
vspAclRuleBuilder.action(VspAclRule.ACLAction.Deny);
}
return vspAclRuleBuilder.build();
}
}

View File

@ -20,6 +20,8 @@
package com.cloud.util;
import com.cloud.network.Network;
import com.cloud.network.dao.NetworkDetailVO;
import com.cloud.network.dao.NetworkDetailsDao;
import com.cloud.network.manager.NuageVspManager;
import com.cloud.offering.NetworkOffering;
import com.cloud.utils.StringUtils;
@ -28,7 +30,12 @@ import org.apache.commons.codec.binary.Base64;
public class NuageVspUtil {
public static String getPreConfiguredDomainTemplateName(ConfigurationDao configDao, Network network, NetworkOffering networkOffering) {
public static String getPreConfiguredDomainTemplateName(ConfigurationDao configDao, NetworkDetailsDao networkDetailsDao, Network network, NetworkOffering networkOffering) {
NetworkDetailVO domainTemplateNetworkDetail = networkDetailsDao.findDetail(network.getId(), NuageVspManager.nuageDomainTemplateDetailName);
if (domainTemplateNetworkDetail != null) {
return domainTemplateNetworkDetail.getValue();
}
String configKey;
if (network.getVpcId() != null) {
configKey = NuageVspManager.NuageVspVpcDomainTemplateName.key();

View File

@ -19,82 +19,53 @@
package net.nuage.vsp.acs;
import net.nuage.vsp.acs.client.NuageVspApiClient;
import net.nuage.vsp.acs.client.NuageVspElementClient;
import net.nuage.vsp.acs.client.NuageVspGuruClient;
import net.nuage.vsp.acs.client.NuageVspManagerClient;
import net.nuage.vsp.acs.client.NuageVspSyncClient;
import net.nuage.vsp.acs.client.api.NuageVspApiClient;
import net.nuage.vsp.acs.client.api.NuageVspElementClient;
import net.nuage.vsp.acs.client.api.NuageVspGuruClient;
import net.nuage.vsp.acs.client.api.NuageVspManagerClient;
import net.nuage.vsp.acs.client.api.impl.NuageVspApiClientImpl;
import net.nuage.vsp.acs.client.api.impl.NuageVspElementClientImpl;
import net.nuage.vsp.acs.client.api.impl.NuageVspGuruClientImpl;
import net.nuage.vsp.acs.client.api.impl.NuageVspManagerClientImpl;
import net.nuage.vsp.acs.client.api.model.VspHost;
import org.apache.log4j.Logger;
import javax.naming.ConfigurationException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
public class NuageVspPluginClientLoader {
private ClassLoader _loader = null;
private static final Logger s_logger = Logger.getLogger(NuageVspPluginClientLoader.class);
private NuageVspApiClient _nuageVspApiClient;
private NuageVspElementClient _nuageVspElementClient;
private NuageVspGuruClient _nuageVspGuruClient;
private NuageVspManagerClient _nuageVspManagerClient;
private NuageVspSyncClient _nuageVspSyncClient;
private static final String NUAGE_PLUGIN_CLIENT_JAR_FILE = "/usr/share/nuagevsp/lib/nuage-vsp-acs-client.jar";
private static final String NUAGE_VSP_API_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspApiClientImpl";
private static final String NUAGE_VSP_SYNC_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspSyncClientImpl";
private static final String NUAGE_VSP_ELEMENT_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspElementClientImpl";
private static final String NUAGE_VSP_GURU_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspGuruClientImpl";
private static final String NUAGE_VSP_MANAGER_CLIENT_IMPL = "net.nuage.vsp.acs.client.impl.NuageVspManagerClientImpl";
private NuageVspPluginClientLoader() {
private NuageVspPluginClientLoader(String nuagePluginClientJarLocation) {
try {
_loader = URLClassLoader.newInstance(new URL[] {new URL("jar:file:" + nuagePluginClientJarLocation + "!/")},
getClass().getClassLoader());
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e);
}
}
public static NuageVspPluginClientLoader getClientLoader(String relativePath, String[] cmsUserInfo, int numRetries, int retryInterval,
String nuageVspCmsId) throws ConfigurationException {
NuageVspPluginClientLoader nuageVspPluginClientClassloader = new NuageVspPluginClientLoader(NUAGE_PLUGIN_CLIENT_JAR_FILE);
nuageVspPluginClientClassloader.loadClasses(relativePath, cmsUserInfo, numRetries, retryInterval, nuageVspCmsId);
public static NuageVspPluginClientLoader getClientLoader(String relativePath, String cmsUserEnterprise, String cmsUserLogin,
String cmsUserPassword, int numRetries, int retryInterval, String nuageVspCmsId) {
NuageVspPluginClientLoader nuageVspPluginClientClassloader = new NuageVspPluginClientLoader();
nuageVspPluginClientClassloader.loadClasses(relativePath, cmsUserEnterprise, cmsUserLogin, cmsUserPassword, numRetries, retryInterval, nuageVspCmsId);
return nuageVspPluginClientClassloader;
}
private void loadClasses(String relativePath, String[] cmsUserInfo, int numRetries, int retryInterval, String nuageVspCmsId) throws ConfigurationException {
try {
Class<?> nuageVspApiClientClass = Class.forName(NUAGE_VSP_API_CLIENT_IMPL, true, _loader);
Class<?> nuageVspSyncClientClass = Class.forName(NUAGE_VSP_SYNC_CLIENT_IMPL, true, _loader);
Class<?> nuageVspGuruClientClass = Class.forName(NUAGE_VSP_GURU_CLIENT_IMPL, true, _loader);
Class<?> nuageVspElementClientClass = Class.forName(NUAGE_VSP_ELEMENT_CLIENT_IMPL, true, _loader);
Class<?> nuageVspManagerClientClass = Class.forName(NUAGE_VSP_MANAGER_CLIENT_IMPL, true, _loader);
//Instantiate the instances
_nuageVspApiClient = (NuageVspApiClient)nuageVspApiClientClass.newInstance();
_nuageVspApiClient.setNuageVspHost(relativePath, cmsUserInfo, numRetries, retryInterval, nuageVspCmsId);
_nuageVspSyncClient = (NuageVspSyncClient)nuageVspSyncClientClass.newInstance();
_nuageVspSyncClient.setNuageVspApiClient(_nuageVspApiClient);
_nuageVspGuruClient = (NuageVspGuruClient)nuageVspGuruClientClass.newInstance();
_nuageVspGuruClient.setNuageVspApiClient(_nuageVspApiClient);
_nuageVspElementClient = (NuageVspElementClient)nuageVspElementClientClass.newInstance();
_nuageVspElementClient.setNuageVspApiClient(_nuageVspApiClient);
_nuageVspManagerClient = (NuageVspManagerClient)nuageVspManagerClientClass.newInstance();
_nuageVspManagerClient.setNuageVspApiClient(_nuageVspApiClient);
} catch (ClassNotFoundException cnfe) {
s_logger.error("Error while loading classes of Nuage VSP client", cnfe);
throw new ConfigurationException("Error while loading classes of Nuage VSP client");
} catch (InstantiationException ie) {
s_logger.error("Error while initializing classes of Nuage VSP client", ie);
throw new ConfigurationException("Error while initializing classes of Nuage VSP client");
} catch (IllegalAccessException iae) {
s_logger.error("Error while accessing classes of Nuage VSP client", iae);
throw new ConfigurationException("Error while accessing classes of Nuage VSP client");
}
private void loadClasses(String relativePath, String cmsUserEnterprise, String cmsUserLogin, String cmsUserPassword, int numRetries,
int retryInterval, String nuageVspCmsId) {
VspHost vspHost = new VspHost.Builder()
.restRelativePath(relativePath)
.cmsUserEnterprise(cmsUserEnterprise)
.cmsUserLogin(cmsUserLogin)
.cmsUserPassword(cmsUserPassword)
.noofRetry(numRetries)
.retryInterval(retryInterval)
.nuageVspCmsId(nuageVspCmsId)
.build();
_nuageVspApiClient = new NuageVspApiClientImpl(vspHost);
_nuageVspElementClient = new NuageVspElementClientImpl(_nuageVspApiClient);
_nuageVspGuruClient = new NuageVspGuruClientImpl(_nuageVspApiClient);
_nuageVspManagerClient = new NuageVspManagerClientImpl(_nuageVspApiClient);
}
public NuageVspApiClient getNuageVspApiClient() {
@ -112,8 +83,4 @@ public class NuageVspPluginClientLoader {
public NuageVspManagerClient getNuageVspManagerClient() {
return _nuageVspManagerClient;
}
public NuageVspSyncClient getNuageVspSyncClient() {
return _nuageVspSyncClient;
}
}

View File

@ -1,32 +0,0 @@
//
// 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 net.nuage.vsp.acs.client;
import java.util.concurrent.ExecutionException;
public interface NuageVspApiClient {
void login() throws ExecutionException;
void setNuageVspHost(String restRelativePath, String[] cmsUserInfo, int noofRetry, int retryInterval, String nuageVspCmsId);
String executeRestApi(String method, String resource, String resourceId, String childResource, Object entityDetails, String resourceFilter, String proxyUserUuid,
String proxyUserDomainuuid) throws ExecutionException;
}

View File

@ -1,42 +0,0 @@
//
// 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 net.nuage.vsp.acs.client;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
public interface NuageVspElementClient {
boolean implement(long networkId, String networkDomainUuid, String networkUuid, String networkName, String vpcOrSubnetUuid, boolean isL2Network, boolean isL3Network,
boolean isVpc, boolean isShared, String domainTemplateName, boolean isFirewallServiceSupported, List<String> dnsServers, List<Map<String, Object>> ingressFirewallRules,
List<Map<String, Object>> egressFirewallRules, List<String> acsFipUuid, boolean egressDefaultPolicy) throws ExecutionException;
void applyStaticNats(String networkDomainUuid, String networkUuid, String vpcOrSubnetUuid, boolean isL3Network, boolean isVpc,
List<Map<String, Object>> staticNatDetails) throws ExecutionException;
void applyAclRules(boolean isNetworkAcl, String networkUuid, String networkDomainUuid, String vpcOrSubnetUuid, String networkName, boolean isL2Network,
List<Map<String, Object>> rules, long networkId, boolean egressDefaultPolicy, Boolean isAcsIngressAcl, boolean networkReset, String domainTemplateName) throws ExecutionException;
void shutdownVpc(String domainUuid, String vpcUuid, String domainTemplateName) throws ExecutionException;
<C extends NuageVspApiClient> void setNuageVspApiClient(NuageVspApiClient nuageVspApiClient);
}

View File

@ -1,43 +0,0 @@
//
// 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 net.nuage.vsp.acs.client;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ExecutionException;
public interface NuageVspGuruClient {
void implement(String networkDomainName, String networkDomainPath, String networkDomainUuid, String networkAccountName, String networkAccountUuid, String networkName,
String networkCidr, String networkGateway, Long networkAclId, List<String> dnsServers, List<String> gatewaySystemIds, boolean isL3Network, boolean isVpc, boolean isSharedNetwork,
String networkUuid, String vpcName, String vpcUuid, boolean defaultEgressPolicy, Collection<String[]> ipAddressRange, String domainTemplateName) throws ExecutionException;
void reserve(String nicUuid, String nicMacAddress, String networkUuid, boolean isL3Network, boolean isSharedNetwork, String vpcUuid, String networkDomainUuid,
String networksAccountUuid, boolean isDomainRouter, String domainRouterIp, String vmInstanceName, String vmUuid, boolean useStaticIp, String staticIp, String staticNatIpUuid,
String staticNatIpAddress, boolean isStaticNatIpAllocated, boolean isOneToOneNat, String staticNatVlanUuid, String staticNatVlanGateway, String staticNatVlanNetmask) throws ExecutionException;
void deallocate(String networkUuid, String nicFrmDdUuid, String nicMacAddress, String nicIp4Address, boolean isL3Network, boolean isSharedNetwork,
String vpcUuid, String networksDomainUuid, String vmInstanceName, String vmUuid, boolean isExpungingState) throws ExecutionException;
void trash(String domainUuid, String networkUuid, boolean isL3Network, boolean isSharedNetwork, String vpcUuid, String domainTemplateName) throws ExecutionException;
void setNuageVspApiClient(NuageVspApiClient nuageVspApiClient);
}

View File

@ -1,42 +0,0 @@
//
// 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 net.nuage.vsp.acs.client;
import org.apache.commons.lang3.tuple.Pair;
import java.util.Map;
import java.util.concurrent.ExecutionException;
public interface NuageVspManagerClient {
Pair<Boolean, String> auditNuageVspCmsId(String nuageVspCmsId, boolean auditOnly) throws ExecutionException;
String registerNuageVspCmsId() throws ExecutionException;
boolean unregisterNuageVspCmsId(String nuageVspCmsId) throws ExecutionException;
boolean isSupportedApiVersion(String version);
Map<String, Object> getClientDefaults() throws ExecutionException;
boolean syncDomainWithNuageVsp(String domainUuid, String domainName, String domainPath, boolean add, boolean remove) throws ExecutionException;
<C extends NuageVspApiClient> void setNuageVspApiClient(NuageVspApiClient nuageVspApiClient);
}

View File

@ -1,29 +0,0 @@
//
// 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 net.nuage.vsp.acs.client;
import java.util.concurrent.ExecutionException;
public interface NuageVspSyncClient {
void syncWithNuageVsp(String nuageVspEntity) throws ExecutionException;
void setNuageVspApiClient(NuageVspApiClient nuageVspApiClient);
}

View File

@ -0,0 +1,157 @@
//
// 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 com.cloud;
import com.cloud.dc.VlanVO;
import com.cloud.domain.Domain;
import com.cloud.network.Network;
import com.cloud.network.NetworkModel;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.vpc.NetworkACLItem;
import com.cloud.util.NuageVspEntityBuilder;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.VirtualMachine;
import net.nuage.vsp.acs.client.api.model.VspAclRule;
import net.nuage.vsp.acs.client.api.model.VspDomain;
import net.nuage.vsp.acs.client.api.model.VspNetwork;
import net.nuage.vsp.acs.client.api.model.VspNic;
import net.nuage.vsp.acs.client.api.model.VspStaticNat;
import net.nuage.vsp.acs.client.api.model.VspVm;
import net.nuage.vsp.acs.client.common.model.Pair;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.junit.Before;
import java.util.ArrayList;
import static com.cloud.network.manager.NuageVspManager.NuageVspIsolatedNetworkDomainTemplateName;
import static com.cloud.network.manager.NuageVspManager.NuageVspSharedNetworkDomainTemplateName;
import static com.cloud.network.manager.NuageVspManager.NuageVspVpcDomainTemplateName;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class NuageTest {
protected static final long NETWORK_ID = 42L;
protected NetworkModel _networkModel = mock(NetworkModel.class);
protected ConfigurationDao _configurationDao = mock(ConfigurationDao.class);
protected NuageVspEntityBuilder _nuageVspEntityBuilder = mock(NuageVspEntityBuilder.class);
@Before
public void setUp() throws Exception {
// Standard responses
when(_networkModel.isProviderForNetwork(Network.Provider.NuageVsp, NETWORK_ID)).thenReturn(true);
when(_configurationDao.getValue(NuageVspIsolatedNetworkDomainTemplateName.key())).thenReturn("IsolatedDomainTemplate");
when(_configurationDao.getValue(NuageVspVpcDomainTemplateName.key())).thenReturn("VpcDomainTemplate");
when(_configurationDao.getValue(NuageVspSharedNetworkDomainTemplateName.key())).thenReturn("SharedDomainTemplate");
when(_nuageVspEntityBuilder.buildVspDomain(any(Domain.class))).thenReturn(buildVspDomain());
when(_nuageVspEntityBuilder.buildVspNetwork(any(Network.class), anyBoolean())).thenReturn(buildVspNetwork());
when(_nuageVspEntityBuilder.buildVspVm(any(VirtualMachine.class), any(Network.class))).thenReturn(buildVspVm());
when(_nuageVspEntityBuilder.buildVspNic(anyString(), any(NicProfile.class))).thenReturn(buildVspNic());
when(_nuageVspEntityBuilder.buildVspNic(any(NicVO.class))).thenReturn(buildVspNic());
when(_nuageVspEntityBuilder.buildVspStaticNat(anyBoolean(), any(IPAddressVO.class), any(VlanVO.class), any(NicVO.class))).thenReturn(buildVspStaticNat());
when(_nuageVspEntityBuilder.buildVspAclRule(any(FirewallRule.class), any(Network.class))).thenReturn(buildVspAclRule());
when(_nuageVspEntityBuilder.buildVspAclRule(any(NetworkACLItem.class))).thenReturn(buildVspAclRule());
}
protected VspDomain buildVspDomain() {
return new VspDomain.Builder()
.uuid("domainUuid")
.name("domainName")
.path("domainPath")
.build();
}
protected VspNetwork buildVspNetwork() {
return new VspNetwork.Builder()
.id(NETWORK_ID)
.uuid("networkUuid")
.name("networkName")
.domain(buildVspDomain())
.accountUuid("networkAccountUuid")
.accountName("networkAccountName")
.vpcUuid("vpcUuid")
.vpcName("vpcName")
.networkType(VspNetwork.NetworkType.L3)
.firewallServiceSupported(true)
.egressDefaultPolicy(true)
.domainTemplateName("domainTemplateName")
.cidr("networkCidr")
.gateway("networkGateway")
.virtualRouterIp("virtualRouterIp")
.ipAddressRanges(new ArrayList<Pair<String, String>>())
.build();
}
protected VspVm buildVspVm() {
return new VspVm.Builder()
.state(VspVm.State.Running)
.uuid("vmUuid")
.name("vmName")
.domainRouter(true)
.domainRouterIp("domainRouterIp")
.build();
}
protected VspNic buildVspNic() {
return new VspNic.Builder()
.uuid("nicUuid")
.macAddress("macAddress")
.useStaticIp(true)
.ip("ip")
.build();
}
protected VspStaticNat buildVspStaticNat() {
return new VspStaticNat.Builder()
.state(VspStaticNat.State.Allocating)
.ipUuid("ipUuid")
.ipAddress("ipAddress")
.nic(buildVspNic())
.revoke(false)
.oneToOneNat(true)
.vlanUuid("vlanUuid")
.vlanGateway("vlanGateway")
.vlanNetmask("vlanNetmask")
.build();
}
protected VspAclRule buildVspAclRule() {
return new VspAclRule.Builder()
.uuid("aclRuleUuid")
.protocol("protcol")
.startPort(1)
.endPort(9)
.state(VspAclRule.ACLState.Add)
.trafficType(VspAclRule.ACLTrafficType.Ingress)
.action(VspAclRule.ACLAction.Allow)
.sourceIpAddress("sourceIpAddress")
.sourceCidrList(new ArrayList<String>())
.priority(1)
.type(VspAclRule.ACLType.NetworkACL)
.build();
}
}

View File

@ -30,43 +30,41 @@ import com.cloud.agent.api.guru.TrashNetworkVspCommand;
import com.cloud.agent.api.manager.SupportedApiVersionCommand;
import com.cloud.agent.api.sync.SyncDomainCommand;
import com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand;
import com.cloud.agent.api.sync.SyncVspCommand;
import com.google.common.collect.Maps;
import com.google.common.testing.EqualsTester;
import org.junit.Test;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
public class CommandsTest {
@Test
public void testCommandEquals() throws IllegalAccessException, InvocationTargetException, InstantiationException {
ApplyAclRuleVspCommand applyAclRuleVspCommand = fillBuilderObject(new ApplyAclRuleVspCommand.Builder()).build();
ApplyAclRuleVspCommand otherApplyAclRuleVspCommand = fillBuilderObject(new ApplyAclRuleVspCommand.Builder()).build();
ApplyAclRuleVspCommand applyAclRuleVspCommand = fillObject(ApplyAclRuleVspCommand.class);
ApplyAclRuleVspCommand otherApplyAclRuleVspCommand = fillObject(ApplyAclRuleVspCommand.class);
ApplyStaticNatVspCommand applyStaticNatVspCommand = fillBuilderObject(new ApplyStaticNatVspCommand.Builder()).build();
ApplyStaticNatVspCommand otherApplyStaticNatVspCommand = fillBuilderObject(new ApplyStaticNatVspCommand.Builder()).build();
ApplyStaticNatVspCommand applyStaticNatVspCommand = fillObject(ApplyStaticNatVspCommand.class);
ApplyStaticNatVspCommand otherApplyStaticNatVspCommand = fillObject(ApplyStaticNatVspCommand.class);
ImplementVspCommand implementVspCommand = fillBuilderObject(new ImplementVspCommand.Builder()).build();
ImplementVspCommand otherImplementVspCommand = fillBuilderObject(new ImplementVspCommand.Builder()).build();
ImplementVspCommand implementVspCommand = fillObject(ImplementVspCommand.class);
ImplementVspCommand otherImplementVspCommand = fillObject(ImplementVspCommand.class);
ShutDownVpcVspCommand shutDownVpcVspCommand = fillBuilderObject(new ShutDownVpcVspCommand.Builder()).build();
ShutDownVpcVspCommand otherShutDownVpcVspCommand = fillBuilderObject(new ShutDownVpcVspCommand.Builder()).build();
ShutDownVpcVspCommand shutDownVpcVspCommand = fillObject(ShutDownVpcVspCommand.class);
ShutDownVpcVspCommand otherShutDownVpcVspCommand = fillObject(ShutDownVpcVspCommand.class);
DeallocateVmVspCommand deallocateVmVspCommand = fillBuilderObject(new DeallocateVmVspCommand.Builder()).build();
DeallocateVmVspCommand otherDeallocateVmVspCommand = fillBuilderObject(new DeallocateVmVspCommand.Builder()).build();
DeallocateVmVspCommand deallocateVmVspCommand = fillObject(DeallocateVmVspCommand.class);
DeallocateVmVspCommand otherDeallocateVmVspCommand = fillObject(DeallocateVmVspCommand.class);
ImplementNetworkVspCommand implementNetworkVspCommand = fillBuilderObject(new ImplementNetworkVspCommand.Builder()).build();
ImplementNetworkVspCommand otherImplementNetworkVspCommand = fillBuilderObject(new ImplementNetworkVspCommand.Builder()).build();
ImplementNetworkVspCommand implementNetworkVspCommand = fillObject(ImplementNetworkVspCommand.class);
ImplementNetworkVspCommand otherImplementNetworkVspCommand = fillObject(ImplementNetworkVspCommand.class);
ReserveVmInterfaceVspCommand reserveVmInterfaceVspCommand = fillBuilderObject(new ReserveVmInterfaceVspCommand.Builder()).build();
ReserveVmInterfaceVspCommand otherReserveVmInterfaceVspCommand = fillBuilderObject(new ReserveVmInterfaceVspCommand.Builder()).build();
ReserveVmInterfaceVspCommand reserveVmInterfaceVspCommand = fillObject(ReserveVmInterfaceVspCommand.class);
ReserveVmInterfaceVspCommand otherReserveVmInterfaceVspCommand = fillObject(ReserveVmInterfaceVspCommand.class);
TrashNetworkVspCommand trashNetworkVspCommand = fillBuilderObject(new TrashNetworkVspCommand.Builder()).build();
TrashNetworkVspCommand otherTrashNetworkVspCommand = fillBuilderObject(new TrashNetworkVspCommand.Builder()).build();
TrashNetworkVspCommand trashNetworkVspCommand = fillObject(TrashNetworkVspCommand.class);
TrashNetworkVspCommand otherTrashNetworkVspCommand = fillObject(TrashNetworkVspCommand.class);
SupportedApiVersionCommand supportedApiVersionCommand = new SupportedApiVersionCommand("3.2");
SupportedApiVersionCommand otherSupportedApiVersionCommand = new SupportedApiVersionCommand("3.2");
@ -77,15 +75,9 @@ public class CommandsTest {
SyncNuageVspCmsIdCommand syncNuageVspCmsIdCommand = fillObject(SyncNuageVspCmsIdCommand.class);
SyncNuageVspCmsIdCommand otherSyncNuageVspCmsIdCommand = fillObject(SyncNuageVspCmsIdCommand.class);
SyncVspCommand syncVspCommand = fillObject(SyncVspCommand.class);
SyncVspCommand otherSyncVspCommand = fillObject(SyncVspCommand.class);
PingNuageVspCommand pingNuageVspCommand = fillObject(PingNuageVspCommand.class);
PingNuageVspCommand otherPingNuageVspCommand = fillObject(PingNuageVspCommand.class);
VspResourceCommand vspResourceCommand = fillObject(VspResourceCommand.class);
VspResourceCommand otherVspResourceCommand = fillObject(VspResourceCommand.class);
new EqualsTester()
.addEqualityGroup(applyAclRuleVspCommand, otherApplyAclRuleVspCommand)
.addEqualityGroup(applyStaticNatVspCommand, otherApplyStaticNatVspCommand)
@ -98,33 +90,10 @@ public class CommandsTest {
.addEqualityGroup(supportedApiVersionCommand, otherSupportedApiVersionCommand)
.addEqualityGroup(syncDomainCommand, otherSyncDomainCommand)
.addEqualityGroup(syncNuageVspCmsIdCommand, otherSyncNuageVspCmsIdCommand)
.addEqualityGroup(syncVspCommand, otherSyncVspCommand)
.addEqualityGroup(pingNuageVspCommand, otherPingNuageVspCommand)
.addEqualityGroup(vspResourceCommand, otherVspResourceCommand)
.testEquals();
}
private <T extends CmdBuilder> T fillBuilderObject(T obj) throws IllegalAccessException, InvocationTargetException {
Class clazz = obj.getClass();
for (Method method : clazz.getDeclaredMethods()) {
if (method.getParameterTypes().length == 1) {
Class paramType = method.getParameterTypes()[0];
if (isNumericType(paramType)) {
if (Long.class.isAssignableFrom(paramType)) {
method.invoke(obj, Long.valueOf(method.getName().length()));
} else {
method.invoke(obj, method.getName().length());
}
} else if (String.class.isAssignableFrom(paramType)) {
method.invoke(obj, method.getName());
} else if (Boolean.class.isAssignableFrom(paramType) || boolean.class.isAssignableFrom(paramType)) {
method.invoke(obj, method.getName().length() % 2 == 0);
}
}
}
return obj;
}
private <T> T fillObject(Class<T> clazz) throws IllegalAccessException, InvocationTargetException, InstantiationException {
Constructor constructor = clazz.getDeclaredConstructors()[0];
Object[] constructorArgs = new Object[constructor.getParameterTypes().length];

View File

@ -19,6 +19,7 @@
package com.cloud.network.element;
import com.cloud.NuageTest;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
@ -35,7 +36,6 @@ import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkModel;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.NuageVspDeviceVO;
@ -59,15 +59,15 @@ import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.resource.ResourceManager;
import com.cloud.user.Account;
import com.cloud.util.NuageVspEntityBuilder;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.dao.DomainRouterDao;
import com.google.common.collect.Lists;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.resourcedetail.dao.VpcDetailsDao;
import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import javax.naming.ConfigurationException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
@ -76,9 +76,6 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import static com.cloud.network.manager.NuageVspManager.NuageVspIsolatedNetworkDomainTemplateName;
import static com.cloud.network.manager.NuageVspManager.NuageVspSharedNetworkDomainTemplateName;
import static com.cloud.network.manager.NuageVspManager.NuageVspVpcDomainTemplateName;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
@ -86,55 +83,48 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class NuageVspElementTest {
public class NuageVspElementTest extends NuageTest {
private static final long NETWORK_ID = 42L;
NuageVspElement element = new NuageVspElement();
NetworkOrchestrationService networkManager = mock(NetworkOrchestrationService.class);
NetworkModel networkModel = mock(NetworkModel.class);
NetworkServiceMapDao ntwkSrvcDao = mock(NetworkServiceMapDao.class);
AgentManager agentManager = mock(AgentManager.class);
HostDao hostDao = mock(HostDao.class);
NuageVspDao nuageVspDao = mock(NuageVspDao.class);
DomainDao domainDao = mock(DomainDao.class);
NetworkOfferingDao ntwkOfferingDao = mock(NetworkOfferingDao.class);
NetworkOfferingServiceMapDao ntwkOfferingSrvcDao = mock(NetworkOfferingServiceMapDao.class);
ConfigurationDao configDao = mock(ConfigurationDao.class);
NuageVspManager nuageVspManager = mock(NuageVspManager.class);
FirewallRulesDao firewallRulesDao = mock(FirewallRulesDao.class);
IPAddressDao ipAddressDao = mock(IPAddressDao.class);
PhysicalNetworkDao physNetDao = mock(PhysicalNetworkDao.class);
private NuageVspElement _nuageVspElement = new NuageVspElement();
org.mockito.stubbing.Answer<Object> genericAnswer = new org.mockito.stubbing.Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
return null;
}
};
private NetworkServiceMapDao _networkServiceMapDao = mock(NetworkServiceMapDao.class);
private AgentManager _agentManager = mock(AgentManager.class);
private HostDao _hostDao = mock(HostDao.class);
private NuageVspDao _nuageVspDao = mock(NuageVspDao.class);
private DomainDao _domainDao = mock(DomainDao.class);
private NetworkOfferingDao _networkOfferingDao = mock(NetworkOfferingDao.class);
private NetworkOfferingServiceMapDao _networkOfferingServiceMapDao = mock(NetworkOfferingServiceMapDao.class);
private NuageVspManager _nuageVspManager = mock(NuageVspManager.class);
private FirewallRulesDao _firewallRulesDao = mock(FirewallRulesDao.class);
private IPAddressDao _ipAddressDao = mock(IPAddressDao.class);
private PhysicalNetworkDao _physicalNetworkDao = mock(PhysicalNetworkDao.class);
private NuageVspEntityBuilder _nuageVspEntityBuilder = mock(NuageVspEntityBuilder.class);
private VpcDetailsDao _vpcDetailsDao = mock(VpcDetailsDao.class);
private DomainRouterDao _domainRouterDao = mock(DomainRouterDao.class);
@Before
public void setUp() throws ConfigurationException {
element._resourceMgr = mock(ResourceManager.class);
element._ntwkSrvcDao = ntwkSrvcDao;
element._networkModel = networkModel;
element._agentMgr = agentManager;
element._hostDao = hostDao;
element._nuageVspDao = nuageVspDao;
element._ntwkOfferingSrvcDao = ntwkOfferingSrvcDao;
element._domainDao = domainDao;
element._ntwkOfferingDao = ntwkOfferingDao;
element._configDao = configDao;
element._nuageVspManager = nuageVspManager;
element._firewallRulesDao = firewallRulesDao;
element._ipAddressDao = ipAddressDao;
element._physicalNetworkDao = physNetDao;
public void setUp() throws Exception {
super.setUp();
// Standard responses
when(networkModel.isProviderForNetwork(Provider.NuageVsp, NETWORK_ID)).thenReturn(true);
when(configDao.getValue(NuageVspIsolatedNetworkDomainTemplateName.key())).thenReturn("IsolatedDomainTemplate");
when(configDao.getValue(NuageVspVpcDomainTemplateName.key())).thenReturn("VpcDomainTemplate");
when(configDao.getValue(NuageVspSharedNetworkDomainTemplateName.key())).thenReturn("SharedDomainTemplate");
_nuageVspElement._resourceMgr = mock(ResourceManager.class);
_nuageVspElement._ntwkSrvcDao = _networkServiceMapDao;
_nuageVspElement._networkModel = _networkModel;
_nuageVspElement._agentMgr = _agentManager;
_nuageVspElement._hostDao = _hostDao;
_nuageVspElement._nuageVspDao = _nuageVspDao;
_nuageVspElement._ntwkOfferingSrvcDao = _networkOfferingServiceMapDao;
_nuageVspElement._domainDao = _domainDao;
_nuageVspElement._ntwkOfferingDao = _networkOfferingDao;
_nuageVspElement._configDao = _configurationDao;
_nuageVspElement._nuageVspManager = _nuageVspManager;
_nuageVspElement._firewallRulesDao = _firewallRulesDao;
_nuageVspElement._ipAddressDao = _ipAddressDao;
_nuageVspElement._physicalNetworkDao = _physicalNetworkDao;
_nuageVspElement._nuageVspEntityBuilder = _nuageVspEntityBuilder;
_nuageVspElement._vpcDetailsDao = _vpcDetailsDao;
_nuageVspElement._routerDao = _domainRouterDao;
element.configure("NuageVspTestElement", Collections.<String, Object> emptyMap());
_nuageVspElement.configure("NuageVspTestElement", Collections.<String, Object>emptyMap());
}
@Test
@ -147,29 +137,29 @@ public class NuageVspElementTest {
final NetworkOfferingVO ntwkoffer = mock(NetworkOfferingVO.class);
when(ntwkoffer.getId()).thenReturn(NETWORK_ID);
when(ntwkoffer.getIsPersistent()).thenReturn(true);
when(ntwkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffer);
when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffer);
when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NuageVsp)).thenReturn(true);
when(_networkServiceMapDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NuageVsp)).thenReturn(true);
// Golden path
assertTrue(element.canHandle(net, Service.Connectivity));
assertTrue(_nuageVspElement.canHandle(net, Service.Connectivity));
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
// Only broadcastdomaintype Vsp is supported
assertFalse(element.canHandle(net, Service.Connectivity));
assertFalse(_nuageVspElement.canHandle(net, Service.Connectivity));
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vsp);
when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NuageVsp)).thenReturn(false);
when(_networkServiceMapDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NuageVsp)).thenReturn(false);
// No NuageVsp provider in the network
assertFalse(element.canHandle(net, Service.Connectivity));
assertFalse(_nuageVspElement.canHandle(net, Service.Connectivity));
when(networkModel.isProviderForNetwork(Provider.NuageVsp, NETWORK_ID)).thenReturn(false);
when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NuageVsp)).thenReturn(true);
when(_networkModel.isProviderForNetwork(Provider.NuageVsp, NETWORK_ID)).thenReturn(false);
when(_networkServiceMapDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NuageVsp)).thenReturn(true);
// NusageVsp provider does not provide Connectivity for this network
assertFalse(element.canHandle(net, Service.Connectivity));
assertFalse(_nuageVspElement.canHandle(net, Service.Connectivity));
when(networkModel.isProviderForNetwork(Provider.NuageVsp, NETWORK_ID)).thenReturn(true);
when(_networkModel.isProviderForNetwork(Provider.NuageVsp, NETWORK_ID)).thenReturn(true);
// Only service Connectivity is supported
assertFalse(element.canHandle(net, Service.Dhcp));
assertFalse(_nuageVspElement.canHandle(net, Service.Dhcp));
}
@ -182,8 +172,8 @@ public class NuageVspElementTest {
when(network.getBroadcastUri()).thenReturn(new URI(""));
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getDomainId()).thenReturn(NETWORK_ID);
when(networkModel.isProviderForNetwork(Provider.NuageVsp, NETWORK_ID)).thenReturn(true);
when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NuageVsp)).thenReturn(true);
when(_networkModel.isProviderForNetwork(Provider.NuageVsp, NETWORK_ID)).thenReturn(true);
when(_networkServiceMapDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NuageVsp)).thenReturn(true);
final NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(NETWORK_ID);
@ -194,7 +184,7 @@ public class NuageVspElementTest {
final DomainVO dom = mock(DomainVO.class);
when(dom.getName()).thenReturn("domain");
when(domainDao.findById(NETWORK_ID)).thenReturn(dom);
when(_domainDao.findById(NETWORK_ID)).thenReturn(dom);
final Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
final ReservationContext context = mock(ReservationContext.class);
@ -205,15 +195,15 @@ public class NuageVspElementTest {
when(host.getId()).thenReturn(NETWORK_ID);
final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
when(nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] {nuageVspDevice}));
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[]{nuageVspDevice}));
when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
when(firewallRulesDao.listByNetworkPurposeTrafficType(NETWORK_ID, FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Ingress)).thenReturn(new ArrayList<FirewallRuleVO>());
when(firewallRulesDao.listByNetworkPurposeTrafficType(NETWORK_ID, FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Egress)).thenReturn(new ArrayList<FirewallRuleVO>());
when(ipAddressDao.listStaticNatPublicIps(NETWORK_ID)).thenReturn(new ArrayList<IPAddressVO>());
when(nuageVspManager.getDnsDetails(network)).thenReturn(new ArrayList<String>());
when(_firewallRulesDao.listByNetworkPurposeTrafficType(NETWORK_ID, FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Ingress)).thenReturn(new ArrayList<FirewallRuleVO>());
when(_firewallRulesDao.listByNetworkPurposeTrafficType(NETWORK_ID, FirewallRule.Purpose.Firewall, FirewallRule.TrafficType.Egress)).thenReturn(new ArrayList<FirewallRuleVO>());
when(_ipAddressDao.listStaticNatPublicIps(NETWORK_ID)).thenReturn(new ArrayList<IPAddressVO>());
when(_nuageVspManager.getDnsDetails(network)).thenReturn(new ArrayList<String>());
assertTrue(element.implement(network, offering, deployDest, context));
assertTrue(_nuageVspElement.implement(network, offering, deployDest, context));
}
@Test
@ -224,14 +214,14 @@ public class NuageVspElementTest {
services.add(Service.SourceNat);
services.add(Service.Connectivity);
services.add(Service.Firewall);
assertTrue(element.verifyServicesCombination(services));
assertTrue(_nuageVspElement.verifyServicesCombination(services));
services = new HashSet<Service>();
services.add(Service.Dhcp);
services.add(Service.StaticNat);
services.add(Service.Connectivity);
services.add(Service.Firewall);
assertFalse(element.verifyServicesCombination(services));
assertFalse(_nuageVspElement.verifyServicesCombination(services));
}
@Test
@ -244,25 +234,24 @@ public class NuageVspElementTest {
when(network.getDomainId()).thenReturn(NETWORK_ID);
final DomainVO domVo = mock(DomainVO.class);
when(domainDao.findById(41l)).thenReturn(domVo);
when(_domainDao.findById(41l)).thenReturn(domVo);
final NetworkOfferingVO ntwkoffer = mock(NetworkOfferingVO.class);
when(ntwkoffer.getId()).thenReturn(NETWORK_ID);
when(ntwkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffer);
when(element.isL3Network(NETWORK_ID)).thenReturn(true);
when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffer);
final HostVO host = mock(HostVO.class);
when(host.getId()).thenReturn(NETWORK_ID);
final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
when(nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] {nuageVspDevice}));
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[]{nuageVspDevice}));
when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
when(domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
when(_domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
assertTrue(element.applyStaticNats(network, new ArrayList<StaticNat>()));
when(_agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
assertTrue(_nuageVspElement.applyStaticNats(network, new ArrayList<StaticNat>()));
}
@Test
@ -277,21 +266,21 @@ public class NuageVspElementTest {
final NetworkOfferingVO ntwkoffer = mock(NetworkOfferingVO.class);
when(ntwkoffer.getId()).thenReturn(NETWORK_ID);
when(ntwkoffer.getEgressDefaultPolicy()).thenReturn(true);
when(ntwkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffer);
when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffer);
final HostVO host = mock(HostVO.class);
when(host.getId()).thenReturn(NETWORK_ID);
final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
when(nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] {nuageVspDevice}));
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[]{nuageVspDevice}));
when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
when(domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
when(_domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
assertTrue(element.applyFWRules(network, new ArrayList<FirewallRule>()));
when(_agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
assertTrue(_nuageVspElement.applyFWRules(network, new ArrayList<FirewallRule>()));
}
@Test
@ -306,20 +295,20 @@ public class NuageVspElementTest {
final NetworkOfferingVO ntwkoffer = mock(NetworkOfferingVO.class);
when(ntwkoffer.getId()).thenReturn(NETWORK_ID);
when(ntwkoffer.getEgressDefaultPolicy()).thenReturn(true);
when(ntwkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffer);
when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffer);
final HostVO host = mock(HostVO.class);
when(host.getId()).thenReturn(NETWORK_ID);
final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
when(nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] {nuageVspDevice}));
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[]{nuageVspDevice}));
when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
when(domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
when(_domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
assertTrue(element.applyNetworkACLs(network, new ArrayList<NetworkACLItem>()));
when(_agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
assertTrue(_nuageVspElement.applyNetworkACLs(network, new ArrayList<NetworkACLItem>()));
}
@Test
@ -329,10 +318,11 @@ public class NuageVspElementTest {
when(vpc.getState()).thenReturn(Vpc.State.Inactive);
when(vpc.getDomainId()).thenReturn(NETWORK_ID);
when(vpc.getZoneId()).thenReturn(NETWORK_ID);
when(vpc.getId()).thenReturn(NETWORK_ID);
final DomainVO dom = mock(DomainVO.class);
when(dom.getName()).thenReturn("domain");
when(domainDao.findById(NETWORK_ID)).thenReturn(dom);
when(_domainDao.findById(NETWORK_ID)).thenReturn(dom);
final Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
final ReservationContext context = mock(ReservationContext.class);
@ -342,18 +332,22 @@ public class NuageVspElementTest {
PhysicalNetworkVO physNet = mock(PhysicalNetworkVO.class);
when(physNet.getIsolationMethods()).thenReturn(Lists.newArrayList(PhysicalNetwork.IsolationMethod.VSP.name()));
when(physNet.getId()).thenReturn(NETWORK_ID);
when(physNetDao.listByZone(NETWORK_ID)).thenReturn(Lists.newArrayList(physNet));
when(_physicalNetworkDao.listByZone(NETWORK_ID)).thenReturn(Lists.newArrayList(physNet));
final HostVO host = mock(HostVO.class);
when(host.getId()).thenReturn(NETWORK_ID);
final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
when(nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] {nuageVspDevice}));
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Lists.newArrayList(nuageVspDevice));
when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
DomainRouterVO domainRouter = mock(DomainRouterVO.class);
when(domainRouter.getUuid()).thenReturn("aaaaaa");
when(_domainRouterDao.listByVpcId(NETWORK_ID)).thenReturn(Lists.newArrayList(domainRouter));
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
assertTrue(element.shutdownVpc(vpc, context));
when(_agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
assertTrue(_nuageVspElement.shutdownVpc(vpc, context));
}
}

View File

@ -19,6 +19,7 @@
package com.cloud.network.guru;
import com.cloud.NuageTest;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
@ -46,6 +47,7 @@ import com.cloud.network.Networks.TrafficType;
import com.cloud.network.NuageVspDeviceVO;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkDetailsDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.NuageVspDao;
import com.cloud.network.dao.PhysicalNetworkDao;
@ -64,7 +66,6 @@ import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.NicDao;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.junit.Before;
import org.junit.Test;
@ -86,60 +87,61 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class NuageVspGuestNetworkGuruTest {
public class NuageVspGuestNetworkGuruTest extends NuageTest {
private static final long NETWORK_ID = 42L;
PhysicalNetworkDao physnetdao = mock(PhysicalNetworkDao.class);
DataCenterDao dcdao = mock(DataCenterDao.class);
NetworkOfferingServiceMapDao nosd = mock(NetworkOfferingServiceMapDao.class);
AgentManager agentManager = mock(AgentManager.class);
NetworkOrchestrationService netmgr = mock(NetworkOrchestrationService.class);
NetworkModel networkModel = mock(NetworkModel.class);
AccountDao accountDao = mock(AccountDao.class);
DomainDao domainDao = mock(DomainDao.class);
NicDao nicDao = mock(NicDao.class);
NetworkOfferingDao ntwkOfferDao = mock(NetworkOfferingDao.class);
NuageVspDao nuageVspDao = mock(NuageVspDao.class);
HostDao hostDao = mock(HostDao.class);
NetworkDao networkDao = mock(NetworkDao.class);
ConfigurationDao configDao = mock(ConfigurationDao.class);
IPAddressDao ipAddressDao = mock(IPAddressDao.class);
NuageVspManager nuageVspManager = mock(NuageVspManager.class);
ConfigurationManager configurationManager = mock(ConfigurationManager.class);
NetworkDao netdao = mock(NetworkDao.class);
NuageVspGuestNetworkGuru guru;
private PhysicalNetworkDao _physicalNetworkDao = mock(PhysicalNetworkDao.class);
private DataCenterDao _dataCenterDao = mock(DataCenterDao.class);
private NetworkOfferingServiceMapDao _networkOfferingServiceMapDao = mock(NetworkOfferingServiceMapDao.class);
private AgentManager _agentManager = mock(AgentManager.class);
private NetworkModel _networkModel = mock(NetworkModel.class);
private AccountDao _accountDao = mock(AccountDao.class);
private DomainDao _domainDao = mock(DomainDao.class);
private NicDao _nicDao = mock(NicDao.class);
private NetworkOfferingDao _networkOfferingDao = mock(NetworkOfferingDao.class);
private NuageVspDao _nuageVspDao = mock(NuageVspDao.class);
private HostDao _hostDao = mock(HostDao.class);
private NetworkDao _networkDao = mock(NetworkDao.class);
private ConfigurationDao _configurationDao = mock(ConfigurationDao.class);
private IPAddressDao _ipAddressDao = mock(IPAddressDao.class);
private NuageVspManager _nuageVspManager = mock(NuageVspManager.class);
private ConfigurationManager _configurationManager = mock(ConfigurationManager.class);
private NetworkDetailsDao _networkDetailsDao = mock(NetworkDetailsDao.class);
private NuageVspGuestNetworkGuru _nuageVspGuestNetworkGuru;
@Before
public void setUp() {
guru = new NuageVspGuestNetworkGuru();
guru._physicalNetworkDao = physnetdao;
guru._physicalNetworkDao = physnetdao;
guru._nuageVspDao = nuageVspDao;
guru._dcDao = dcdao;
guru._ntwkOfferingSrvcDao = nosd;
guru._networkModel = networkModel;
guru._hostDao = hostDao;
guru._agentMgr = agentManager;
guru._networkDao = netdao;
guru._networkDao = networkDao;
guru._accountDao = accountDao;
guru._domainDao = domainDao;
guru._nicDao = nicDao;
guru._ntwkOfferingDao = ntwkOfferDao;
guru._configDao = configDao;
guru._ipAddressDao = ipAddressDao;
guru._nuageVspManager = nuageVspManager;
guru._configMgr = configurationManager;
public void setUp() throws Exception {
super.setUp();
_nuageVspGuestNetworkGuru = new NuageVspGuestNetworkGuru();
_nuageVspGuestNetworkGuru._physicalNetworkDao = _physicalNetworkDao;
_nuageVspGuestNetworkGuru._physicalNetworkDao = _physicalNetworkDao;
_nuageVspGuestNetworkGuru._nuageVspDao = _nuageVspDao;
_nuageVspGuestNetworkGuru._dcDao = _dataCenterDao;
_nuageVspGuestNetworkGuru._ntwkOfferingSrvcDao = _networkOfferingServiceMapDao;
_nuageVspGuestNetworkGuru._networkModel = _networkModel;
_nuageVspGuestNetworkGuru._hostDao = _hostDao;
_nuageVspGuestNetworkGuru._agentMgr = _agentManager;
_nuageVspGuestNetworkGuru._networkDao = _networkDao;
_nuageVspGuestNetworkGuru._accountDao = _accountDao;
_nuageVspGuestNetworkGuru._domainDao = _domainDao;
_nuageVspGuestNetworkGuru._nicDao = _nicDao;
_nuageVspGuestNetworkGuru._ntwkOfferingDao = _networkOfferingDao;
_nuageVspGuestNetworkGuru._configDao = _configurationDao;
_nuageVspGuestNetworkGuru._ipAddressDao = _ipAddressDao;
_nuageVspGuestNetworkGuru._nuageVspManager = _nuageVspManager;
_nuageVspGuestNetworkGuru._configMgr = _configurationManager;
_nuageVspGuestNetworkGuru._nuageVspEntityBuilder = _nuageVspEntityBuilder;
_nuageVspGuestNetworkGuru._networkDetailsDao = _networkDetailsDao;
final DataCenterVO dc = mock(DataCenterVO.class);
when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
when(dc.getGuestNetworkCidr()).thenReturn("10.1.1.1/24");
when(dcdao.findById((Long)any())).thenReturn(dc);
when(_dataCenterDao.findById((Long)any())).thenReturn(dc);
when(configDao.getValue(NuageVspIsolatedNetworkDomainTemplateName.key())).thenReturn("IsolatedDomainTemplate");
when(configDao.getValue(NuageVspVpcDomainTemplateName.key())).thenReturn("VpcDomainTemplate");
when(configDao.getValue(NuageVspSharedNetworkDomainTemplateName.key())).thenReturn("SharedDomainTemplate");
when(_configurationDao.getValue(NuageVspIsolatedNetworkDomainTemplateName.key())).thenReturn("IsolatedDomainTemplate");
when(_configurationDao.getValue(NuageVspVpcDomainTemplateName.key())).thenReturn("VpcDomainTemplate");
when(_configurationDao.getValue(NuageVspSharedNetworkDomainTemplateName.key())).thenReturn("SharedDomainTemplate");
}
@Test
@ -149,47 +151,47 @@ public class NuageVspGuestNetworkGuruTest {
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(offering.getIsPersistent()).thenReturn(false);
when(configurationManager.isOfferingForVpc(any(NetworkOffering.class))).thenReturn(false);
when(_configurationManager.isOfferingForVpc(any(NetworkOffering.class))).thenReturn(false);
final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] {"VSP"}));
when(physnet.getId()).thenReturn(NETWORK_ID);
when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(true);
when(_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(true);
assertTrue(guru.canHandle(offering, NetworkType.Advanced, physnet));
assertTrue(_nuageVspGuestNetworkGuru.canHandle(offering, NetworkType.Advanced, physnet) == true);
// Not supported TrafficType != Guest
when(offering.getTrafficType()).thenReturn(TrafficType.Management);
assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet));
assertFalse(_nuageVspGuestNetworkGuru.canHandle(offering, NetworkType.Advanced, physnet) == true);
// Supported: GuestType Shared
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Shared);
assertTrue(guru.canHandle(offering, NetworkType.Advanced, physnet));
assertTrue(_nuageVspGuestNetworkGuru.canHandle(offering, NetworkType.Advanced, physnet) == true);
// Not supported: Basic networking
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
assertFalse(guru.canHandle(offering, NetworkType.Basic, physnet));
assertFalse(_nuageVspGuestNetworkGuru.canHandle(offering, NetworkType.Basic, physnet) == true);
// Not supported: IsolationMethod != STT
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] {"VLAN"}));
assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet));
assertFalse(_nuageVspGuestNetworkGuru.canHandle(offering, NetworkType.Advanced, physnet) == true);
// Not supported: Non-persistent VPC tier
when(configurationManager.isOfferingForVpc(any(NetworkOffering.class))).thenReturn(true);
assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet));
when(_configurationManager.isOfferingForVpc(any(NetworkOffering.class))).thenReturn(true);
assertFalse(_nuageVspGuestNetworkGuru.canHandle(offering, NetworkType.Advanced, physnet));
}
@Test
public void testDesign() {
final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long)any())).thenReturn(physnet);
when(_physicalNetworkDao.findById((Long)any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] {"VSP"}));
when(physnet.getId()).thenReturn(NETWORK_ID);
final NuageVspDeviceVO device = mock(NuageVspDeviceVO.class);
when(nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] {device}));
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[]{device}));
when(device.getId()).thenReturn(1L);
final NetworkOffering offering = mock(NetworkOffering.class);
@ -197,32 +199,32 @@ public class NuageVspGuestNetworkGuruTest {
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(offering.getIsPersistent()).thenReturn(false);
when(configurationManager.isOfferingForVpc(any(NetworkOffering.class))).thenReturn(false);
when(_configurationManager.isOfferingForVpc(any(NetworkOffering.class))).thenReturn(false);
when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(true);
when(_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(true);
final DeploymentPlan plan = mock(DeploymentPlan.class);
final Network network = mock(Network.class);
final Account account = mock(Account.class);
final Network designednetwork = guru.design(offering, plan, network, account);
final Network designednetwork = _nuageVspGuestNetworkGuru.design(offering, plan, network, account);
assertTrue(designednetwork != null);
assertTrue(designednetwork.getBroadcastDomainType() == BroadcastDomainType.Vsp);
// Can't design non-persistent VPC tier
when(configurationManager.isOfferingForVpc(any(NetworkOffering.class))).thenReturn(true);
assertNull(guru.design(offering, plan, network, account));
when(_configurationManager.isOfferingForVpc(any(NetworkOffering.class))).thenReturn(true);
assertNull(_nuageVspGuestNetworkGuru.design(offering, plan, network, account));
}
@Test
public void testDesignNoElementOnPhysicalNetwork() {
final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long)any())).thenReturn(physnet);
when(_physicalNetworkDao.findById((Long)any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] {"STT"}));
when(physnet.getId()).thenReturn(NETWORK_ID);
mock(NuageVspDeviceVO.class);
when(nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Collections.<NuageVspDeviceVO> emptyList());
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Collections.<NuageVspDeviceVO>emptyList());
final NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(NETWORK_ID);
@ -233,19 +235,19 @@ public class NuageVspGuestNetworkGuruTest {
final Network network = mock(Network.class);
final Account account = mock(Account.class);
final Network designednetwork = guru.design(offering, plan, network, account);
final Network designednetwork = _nuageVspGuestNetworkGuru.design(offering, plan, network, account);
assertTrue(designednetwork == null);
}
@Test
public void testDesignNoIsolationMethodVSP() {
final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long)any())).thenReturn(physnet);
when(_physicalNetworkDao.findById((Long)any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] {"VLAN"}));
when(physnet.getId()).thenReturn(NETWORK_ID);
mock(NuageVspDeviceVO.class);
when(nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Collections.<NuageVspDeviceVO> emptyList());
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Collections.<NuageVspDeviceVO>emptyList());
final NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(NETWORK_ID);
@ -256,7 +258,7 @@ public class NuageVspGuestNetworkGuruTest {
final Network network = mock(Network.class);
final Account account = mock(Account.class);
final Network designednetwork = guru.design(offering, plan, network, account);
final Network designednetwork = _nuageVspGuestNetworkGuru.design(offering, plan, network, account);
assertTrue(designednetwork == null);
}
@ -274,20 +276,20 @@ public class NuageVspGuestNetworkGuruTest {
when(network.getBroadcastUri()).thenReturn(new URI("vsp://aaaaaa-aavvv/10.1.1.1"));
final DataCenterVO dataCenter = mock(DataCenterVO.class);
when(dcdao.findById(NETWORK_ID)).thenReturn(dataCenter);
when(_dataCenterDao.findById(NETWORK_ID)).thenReturn(dataCenter);
final AccountVO networksAccount = mock(AccountVO.class);
when(networksAccount.getUuid()).thenReturn("aaaa-abbbb");
when(networksAccount.getType()).thenReturn(Account.ACCOUNT_TYPE_NORMAL);
when(accountDao.findById(NETWORK_ID)).thenReturn(networksAccount);
when(_accountDao.findById(NETWORK_ID)).thenReturn(networksAccount);
final DomainVO networksDomain = mock(DomainVO.class);
when(networksDomain.getUuid()).thenReturn("aaaaa-bbbbb");
when(domainDao.findById(NETWORK_ID)).thenReturn(networksDomain);
when(_domainDao.findById(NETWORK_ID)).thenReturn(networksDomain);
final NicVO nicvo = mock(NicVO.class);
when(nicvo.getId()).thenReturn(NETWORK_ID);
when(nicvo.getMacAddress()).thenReturn("aa-aa-aa-aa-aa-aa");
when(nicvo.getUuid()).thenReturn("aaaa-fffff");
when(nicDao.findById(NETWORK_ID)).thenReturn(nicvo);
when(_nicDao.findById(NETWORK_ID)).thenReturn(nicvo);
final VirtualMachine vm = mock(VirtualMachine.class);
when(vm.getId()).thenReturn(NETWORK_ID);
@ -306,24 +308,24 @@ public class NuageVspGuestNetworkGuruTest {
final NetworkOfferingVO ntwkoffering = mock(NetworkOfferingVO.class);
when(ntwkoffering.getId()).thenReturn(NETWORK_ID);
when(ntwkOfferDao.findById(NETWORK_ID)).thenReturn(ntwkoffering);
when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffering);
final HostVO host = mock(HostVO.class);
when(host.getId()).thenReturn(NETWORK_ID);
final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
when(nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] {nuageVspDevice}));
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[]{nuageVspDevice}));
when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
when(networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
when(ipAddressDao.findByVmIdAndNetworkId(NETWORK_ID, NETWORK_ID)).thenReturn(null);
when(domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
when(_ipAddressDao.findByVmIdAndNetworkId(NETWORK_ID, NETWORK_ID)).thenReturn(null);
when(_domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
when(_agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
guru.reserve(nicProfile, network, vmProfile, mock(DeployDestination.class), mock(ReservationContext.class));
_nuageVspGuestNetworkGuru.reserve(nicProfile, network, vmProfile, mock(DeployDestination.class), mock(ReservationContext.class));
}
@Test
@ -352,7 +354,7 @@ public class NuageVspGuestNetworkGuruTest {
when(offering.getTags()).thenReturn("aaaa");
when(offering.getEgressDefaultPolicy()).thenReturn(true);
when(networkModel.findPhysicalNetworkId(NETWORK_ID, "aaa", TrafficType.Guest)).thenReturn(NETWORK_ID);
when(_networkModel.findPhysicalNetworkId(NETWORK_ID, "aaa", TrafficType.Guest)).thenReturn(NETWORK_ID);
final ReservationContext reserveContext = mock(ReservationContext.class);
final Domain domain = mock(Domain.class);
@ -362,29 +364,29 @@ public class NuageVspGuestNetworkGuruTest {
when(account.getAccountId()).thenReturn(NETWORK_ID);
when(reserveContext.getAccount()).thenReturn(account);
final DomainVO domainVo = mock(DomainVO.class);
when(domainDao.findById(NETWORK_ID)).thenReturn(domainVo);
when(_domainDao.findById(NETWORK_ID)).thenReturn(domainVo);
final AccountVO accountVo = mock(AccountVO.class);
when(accountDao.findById(NETWORK_ID)).thenReturn(accountVo);
when(_accountDao.findById(NETWORK_ID)).thenReturn(accountVo);
final HostVO host = mock(HostVO.class);
when(host.getId()).thenReturn(NETWORK_ID);
final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
when(nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] {nuageVspDevice}));
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
when(networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
when(nuageVspManager.getDnsDetails(network)).thenReturn(new ArrayList<String>());
when(nuageVspManager.getGatewaySystemIds()).thenReturn(new ArrayList<String>());
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[]{nuageVspDevice}));
when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
when(_nuageVspManager.getDnsDetails(network)).thenReturn(new ArrayList<String>());
when(_nuageVspManager.getGatewaySystemIds()).thenReturn(new ArrayList<String>());
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
when(_agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
final DataCenter dc = mock(DataCenter.class);
when(dc.getId()).thenReturn(NETWORK_ID);
final DeployDestination deployDest = mock(DeployDestination.class);
when(deployDest.getDataCenter()).thenReturn(dc);
guru.implement(network, offering, deployDest, reserveContext);
_nuageVspGuestNetworkGuru.implement(network, offering, deployDest, reserveContext);
}
@Test
@ -396,22 +398,22 @@ public class NuageVspGuestNetworkGuruTest {
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getVpcId()).thenReturn(null);
when(network.getDomainId()).thenReturn(NETWORK_ID);
when(networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
final NetworkOfferingVO offering = mock(NetworkOfferingVO.class);
when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(ntwkOfferDao.findById(NETWORK_ID)).thenReturn(offering);
when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(offering);
final DomainVO domain = mock(DomainVO.class);
when(domain.getUuid()).thenReturn("aaaaaa");
when(domainDao.findById(NETWORK_ID)).thenReturn(domain);
when(_domainDao.findById(NETWORK_ID)).thenReturn(domain);
final NicVO nic = mock(NicVO.class);
when(nic.getId()).thenReturn(NETWORK_ID);
when(nic.getIPv4Address()).thenReturn("10.10.10.10");
when(nic.getMacAddress()).thenReturn("c8:60:00:56:e5:58");
when(nicDao.findById(NETWORK_ID)).thenReturn(nic);
when(_nicDao.findById(NETWORK_ID)).thenReturn(nic);
final NicProfile nicProfile = mock(NicProfile.class);
when(nicProfile.getId()).thenReturn(NETWORK_ID);
@ -431,14 +433,14 @@ public class NuageVspGuestNetworkGuruTest {
when(host.getId()).thenReturn(NETWORK_ID);
final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
when(nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] {nuageVspDevice}));
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[]{nuageVspDevice}));
when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
when(_agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
guru.deallocate(network, nicProfile, vmProfile);
_nuageVspGuestNetworkGuru.deallocate(network, nicProfile, vmProfile);
}
@Test
@ -451,31 +453,31 @@ public class NuageVspGuestNetworkGuruTest {
when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getVpcId()).thenReturn(null);
when(networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
final NetworkOfferingVO offering = mock(NetworkOfferingVO.class);
when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(ntwkOfferDao.findById(NETWORK_ID)).thenReturn(offering);
when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(offering);
final DomainVO domain = mock(DomainVO.class);
when(domain.getUuid()).thenReturn("aaaaaa");
when(domainDao.findById(NETWORK_ID)).thenReturn(domain);
when(_domainDao.findById(NETWORK_ID)).thenReturn(domain);
final HostVO host = mock(HostVO.class);
when(host.getId()).thenReturn(NETWORK_ID);
final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
when(nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[] {nuageVspDevice}));
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
when(nuageVspManager.getDnsDetails(network)).thenReturn(new ArrayList<String>());
when(nuageVspManager.getGatewaySystemIds()).thenReturn(new ArrayList<String>());
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NuageVspDeviceVO[]{nuageVspDevice}));
when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
when(_nuageVspManager.getDnsDetails(network)).thenReturn(new ArrayList<String>());
when(_nuageVspManager.getGatewaySystemIds()).thenReturn(new ArrayList<String>());
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
when(_agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
assertTrue(guru.trash(network, offering));
assertTrue(_nuageVspGuestNetworkGuru.trash(network, offering));
}
}

View File

@ -19,6 +19,7 @@
package com.cloud.network.manager;
import com.cloud.NuageTest;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer;
@ -35,6 +36,7 @@ import com.cloud.network.dao.PhysicalNetworkDao;
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.PhysicalNetworkVO;
import com.cloud.resource.ResourceManager;
import com.cloud.util.NuageVspEntityBuilder;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import org.junit.Before;
@ -48,34 +50,37 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class NuageVspManagerTest {
public class NuageVspManagerTest extends NuageTest {
private static final long NETWORK_ID = 42L;
PhysicalNetworkDao physicalNetworkDao = mock(PhysicalNetworkDao.class);
PhysicalNetworkServiceProviderDao physicalNetworkServiceProviderDao = mock(PhysicalNetworkServiceProviderDao.class);
ResourceManager resourceMgr = mock(ResourceManager.class);
HostDetailsDao hostDetailsDao = mock(HostDetailsDao.class);
NuageVspDao nuageVspDao = mock(NuageVspDao.class);
NetworkDao networkDao = mock(NetworkDao.class);
HostDao hostDao = mock(HostDao.class);
AgentManager agentManager = mock(AgentManager.class);
ConfigurationDao configDao = mock(ConfigurationDao.class);
NuageVspManagerImpl manager;
private PhysicalNetworkDao _physicalNetworkDao = mock(PhysicalNetworkDao.class);
private PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao = mock(PhysicalNetworkServiceProviderDao.class);
private ResourceManager _resourceManager = mock(ResourceManager.class);
private HostDetailsDao _hostDetailsDao = mock(HostDetailsDao.class);
private NuageVspDao _nuageVspDao = mock(NuageVspDao.class);
private NetworkDao _networkDao = mock(NetworkDao.class);
private HostDao _hostDao = mock(HostDao.class);
private AgentManager _agentManager = mock(AgentManager.class);
private ConfigurationDao _configurationDao = mock(ConfigurationDao.class);
private NuageVspEntityBuilder _nuageVspEntityBuilder = mock(NuageVspEntityBuilder.class);
private NuageVspManagerImpl _nuageVspManager;
@Before
public void setUp() {
manager = new NuageVspManagerImpl();
public void setUp() throws Exception {
super.setUp();
manager._physicalNetworkServiceProviderDao = physicalNetworkServiceProviderDao;
manager._physicalNetworkDao = physicalNetworkDao;
manager._resourceMgr = resourceMgr;
manager._hostDetailsDao = hostDetailsDao;
manager._nuageVspDao = nuageVspDao;
manager._networkDao = networkDao;
manager._hostDao = hostDao;
manager._agentMgr = agentManager;
manager._configDao = configDao;
_nuageVspManager = new NuageVspManagerImpl();
_nuageVspManager._physicalNetworkServiceProviderDao = _physicalNetworkServiceProviderDao;
_nuageVspManager._physicalNetworkDao = _physicalNetworkDao;
_nuageVspManager._resourceMgr = _resourceManager;
_nuageVspManager._hostDetailsDao = _hostDetailsDao;
_nuageVspManager._nuageVspDao = _nuageVspDao;
_nuageVspManager._networkDao = _networkDao;
_nuageVspManager._hostDao = _hostDao;
_nuageVspManager._agentMgr = _agentManager;
_nuageVspManager._configDao = _configurationDao;
_nuageVspManager._nuageVspEntityBuilder = _nuageVspEntityBuilder;
}
@Test
@ -84,31 +89,31 @@ public class NuageVspManagerTest {
final PhysicalNetworkVO physicalNetwork = mock(PhysicalNetworkVO.class);
when(physicalNetwork.getDataCenterId()).thenReturn(NETWORK_ID);
when(physicalNetwork.getId()).thenReturn(NETWORK_ID);
when(physicalNetworkDao.findById(NETWORK_ID)).thenReturn(physicalNetwork);
when(_physicalNetworkDao.findById(NETWORK_ID)).thenReturn(physicalNetwork);
final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
when(nuageVspDevice.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
when(nuageVspDao.findById(NETWORK_ID)).thenReturn(nuageVspDevice);
when(_nuageVspDao.findById(NETWORK_ID)).thenReturn(nuageVspDevice);
when(networkDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(new ArrayList<NetworkVO>());
when(_networkDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(new ArrayList<NetworkVO>());
final HostVO host = mock(HostVO.class);
when(host.getId()).thenReturn(NETWORK_ID);
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
final DeleteNuageVspDeviceCmd cmd = mock(DeleteNuageVspDeviceCmd.class);
when(cmd.getNuageVspDeviceId()).thenReturn(NETWORK_ID);
ConfigurationVO cmsIdConfig = mock(ConfigurationVO.class);
when(cmsIdConfig.getValue()).thenReturn("1:1");
when(configDao.findByName("nuagevsp.cms.id")).thenReturn(cmsIdConfig);
when(_configurationDao.findByName("nuagevsp.cms.id")).thenReturn(cmsIdConfig);
final SyncNuageVspCmsIdAnswer answer = mock(SyncNuageVspCmsIdAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
when(_agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
manager.deleteNuageVspDevice(cmd);
_nuageVspManager.deleteNuageVspDevice(cmd);
}
@Test
@ -117,12 +122,12 @@ public class NuageVspManagerTest {
when(nuageVspDevice.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
final PhysicalNetworkVO phyNtwkVO = mock(PhysicalNetworkVO.class);
when(physicalNetworkDao.findById(NETWORK_ID)).thenReturn(phyNtwkVO);
when(nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(new ArrayList<NuageVspDeviceVO>());
when(_physicalNetworkDao.findById(NETWORK_ID)).thenReturn(phyNtwkVO);
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(new ArrayList<NuageVspDeviceVO>());
final ListNuageVspDevicesCmd cmd = mock(ListNuageVspDevicesCmd.class);
when(cmd.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(cmd.getNuageVspDeviceId()).thenReturn(null);
manager.listNuageVspDevices(cmd);
_nuageVspManager.listNuageVspDevices(cmd);
}
}

View File

@ -19,6 +19,7 @@
package com.cloud.network.resource;
import com.cloud.NuageTest;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.PingCommand;
import com.cloud.agent.api.StartupCommand;
@ -29,13 +30,17 @@ import com.cloud.agent.api.guru.DeallocateVmVspCommand;
import com.cloud.agent.api.guru.ImplementNetworkVspCommand;
import com.cloud.agent.api.guru.ReserveVmInterfaceVspCommand;
import com.cloud.agent.api.guru.TrashNetworkVspCommand;
import com.cloud.agent.api.sync.SyncVspCommand;
import com.cloud.host.Host;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.nuage.vsp.acs.client.NuageVspApiClient;
import net.nuage.vsp.acs.client.NuageVspElementClient;
import net.nuage.vsp.acs.client.NuageVspGuruClient;
import net.nuage.vsp.acs.client.NuageVspSyncClient;
import net.nuage.vsp.acs.client.api.NuageVspApiClient;
import net.nuage.vsp.acs.client.api.NuageVspElementClient;
import net.nuage.vsp.acs.client.api.NuageVspGuruClient;
import net.nuage.vsp.acs.client.api.model.VspAclRule;
import net.nuage.vsp.acs.client.api.model.VspNetwork;
import net.nuage.vsp.acs.client.api.model.VspNic;
import net.nuage.vsp.acs.client.api.model.VspStaticNat;
import net.nuage.vsp.acs.client.api.model.VspVm;
import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
@ -43,20 +48,20 @@ import org.mockito.invocation.InvocationOnMock;
import javax.naming.ConfigurationException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
public class NuageVspResourceTest {
NuageVspResource _resource;
NuageVspApiClient _mockNuageVspApiClient = mock(NuageVspApiClient.class);
NuageVspElementClient _mockNuageVspElementClient = mock(NuageVspElementClient.class);
NuageVspGuruClient _mockNuageVspGuruClient = mock(NuageVspGuruClient.class);
NuageVspSyncClient _mockNuageVspSyncClient = mock(NuageVspSyncClient.class);
NuageVspResource.Configuration _resourceConfiguration;
Map<String, Object> _hostDetails;
public class NuageVspResourceTest extends NuageTest {
private NuageVspResource _resource;
private NuageVspApiClient _mockNuageVspApiClient = mock(NuageVspApiClient.class);
private NuageVspElementClient _mockNuageVspElementClient = mock(NuageVspElementClient.class);
private NuageVspGuruClient _mockNuageVspGuruClient = mock(NuageVspGuruClient.class);
private NuageVspResource.Configuration _resourceConfiguration;
private Map<String, Object> _hostDetails;
org.mockito.stubbing.Answer<Object> genericAnswer = new org.mockito.stubbing.Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
@ -66,6 +71,8 @@ public class NuageVspResourceTest {
@Before
public void setUp() throws Exception {
super.setUp();
_resource = new NuageVspResource() {
@Override
@ -74,8 +81,6 @@ public class NuageVspResourceTest {
_nuageVspApiClient = _mockNuageVspApiClient;
_nuageVspElementClient = _mockNuageVspElementClient;
_nuageVspGuruClient = _mockNuageVspGuruClient;
_nuageVspSyncClient = _mockNuageVspSyncClient;
}
protected void isNuageVspApiLoaded() throws ConfigurationException {
@ -87,9 +92,6 @@ public class NuageVspResourceTest {
protected void isNuageVspElementLoaded() throws ConfigurationException {
}
protected void isNuageVspSyncLoaded() throws ConfigurationException {
}
protected void login() throws ConfigurationException {
}
@ -148,15 +150,10 @@ public class NuageVspResourceTest {
public void testImplementNetworkVspCommand() throws Exception {
_resource.configure("NuageVspResource", _hostDetails);
ImplementNetworkVspCommand.Builder cmdBuilder = new ImplementNetworkVspCommand.Builder().networkDomainName("networkDomainName").networkDomainPath("networkDomainPath")
.networkDomainUuid("networkDomainUuid").networkAccountName("networkAccountName").networkAccountUuid("networkAccountUuid").networkName("networkName")
.networkCidr("networkCidr").networkGateway("networkGateway").networkAclId(0L).dnsServers(new ArrayList<String>()).gatewaySystemIds(new ArrayList<String>())
.networkUuid("networkUuid").isL3Network(true).isVpc(true).isSharedNetwork(true).vpcName("vpcName").vpcUuid("vpcUuid").defaultEgressPolicy(true)
.ipAddressRange(new ArrayList<String[]>()).domainTemplateName("domainTemplateName");
doAnswer(genericAnswer).when(_mockNuageVspGuruClient).implement("networkDomainName", "networkDomainPath", "networkDomainUuid", "networkAccountName",
"networkAccountUuid", "networkName", "networkCidr", "networkGateway", 0L, new ArrayList<String>(), new ArrayList<String>(), true, true, true, "networkUuid",
"vpcName", "vpcUuid", true, new ArrayList<String[]>(), "domainTemplateName");
com.cloud.agent.api.Answer implNtwkAns = _resource.executeRequest(cmdBuilder.build());
VspNetwork vspNetwork = buildVspNetwork();
ImplementNetworkVspCommand cmd = new ImplementNetworkVspCommand(vspNetwork, new ArrayList<String>());
doAnswer(genericAnswer).when(_mockNuageVspGuruClient).implement(vspNetwork, new ArrayList<String>());
com.cloud.agent.api.Answer implNtwkAns = _resource.executeRequest(cmd);
assertTrue(implNtwkAns.getResult());
}
@ -164,16 +161,13 @@ public class NuageVspResourceTest {
public void testReserveVmInterfaceVspCommand() throws Exception {
_resource.configure("NuageVspResource", _hostDetails);
ReserveVmInterfaceVspCommand.Builder cmdBuilder = new ReserveVmInterfaceVspCommand.Builder().nicUuid("nicUuid").nicMacAddress("nicMacAddress")
.networkUuid("networkUuid").isL3Network(true).isSharedNetwork(true).vpcUuid("vpcUuid").networkDomainUuid("networkDomainUuid")
.networksAccountUuid("networksAccountUuid").isDomainRouter(false).domainRouterIp("domainRouterIp").vmInstanceName("vmInstanceName").vmUuid("vmUuid")
.vmUserName("vmUserName").vmUserDomainName("vmUserDomainName").useStaticIp(true).staticIp("staticIp").staticNatIpUuid("staticNatIpUuid")
.staticNatIpAddress("staticNatIpAddress").isStaticNatIpAllocated(true).isOneToOneNat(true).staticNatVlanUuid("staticNatVlanUuid")
.staticNatVlanGateway("staticNatVlanGateway").staticNatVlanNetmask("staticNatVlanNetmask");
doAnswer(genericAnswer).when(_mockNuageVspGuruClient).reserve("nicUuid", "nicMacAddress", "networkUuid", true, true, "vpcUuid", "networkDomainUuid",
"networksAccountUuid", false, "domainRouterIp", "vmInstanceName", "vmUuid", true, "staticIp", "staticNatIpUuid", "staticNatIpAddress",
true, true, "staticNatVlanUuid", "staticNatVlanGateway", "staticNatVlanNetmask");
Answer rsrvVmInfAns = _resource.executeRequest(cmdBuilder.build());
VspNetwork vspNetwork = buildVspNetwork();
VspVm vspVm = buildVspVm();
VspNic vspNic = buildVspNic();
VspStaticNat vspStaticNat = buildVspStaticNat();
ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(vspNetwork, vspVm, vspNic, vspStaticNat);
doAnswer(genericAnswer).when(_mockNuageVspGuruClient).reserve(vspNetwork, vspVm, vspNic, vspStaticNat);
Answer rsrvVmInfAns = _resource.executeRequest(cmd);
assertTrue(rsrvVmInfAns.getResult());
}
@ -181,12 +175,12 @@ public class NuageVspResourceTest {
public void testDeallocateVmVspCommand() throws Exception {
_resource.configure("NuageVspResource", _hostDetails);
DeallocateVmVspCommand.Builder cmdBuilder = new DeallocateVmVspCommand.Builder().networkUuid("networkUuid").nicFromDbUuid("nicFromDbUuid")
.nicMacAddress("nicMacAddress").nicIp4Address("nicIp4Address").isL3Network(true).isSharedNetwork(true).vpcUuid("vpcUuid")
.networksDomainUuid("networksDomainUuid").vmInstanceName("vmInstanceName").vmUuid("vmUuid").isExpungingState(true);
doAnswer(genericAnswer).when(_mockNuageVspGuruClient).deallocate("networkUuid", "nicFrmDdUuid", "nicMacAddress", "nicIp4Address", true, true, "vpcUuid", "networksDomainUuid",
"vmInstanceName", "vmUuid", true);
Answer dellocateVmAns = _resource.executeRequest(cmdBuilder.build());
VspNetwork vspNetwork = buildVspNetwork();
VspVm vspVm = buildVspVm();
VspNic vspNic = buildVspNic();
DeallocateVmVspCommand cmd = new DeallocateVmVspCommand(vspNetwork, vspVm, vspNic);
doAnswer(genericAnswer).when(_mockNuageVspGuruClient).deallocate(vspNetwork, vspVm, vspNic);
Answer dellocateVmAns = _resource.executeRequest(cmd);
assertTrue(dellocateVmAns.getResult());
}
@ -194,10 +188,10 @@ public class NuageVspResourceTest {
public void testTrashNetworkVspCommand() throws Exception {
_resource.configure("NuageVspResource", _hostDetails);
TrashNetworkVspCommand.Builder cmdBuilder = new TrashNetworkVspCommand.Builder().domainUuid("domainUuid").networkUuid("networkUuid")
.isL3Network(true).isSharedNetwork(true).vpcUuid("vpcUuid").domainTemplateName("domainTemplateName");
doAnswer(genericAnswer).when(_mockNuageVspGuruClient).trash("domainUuid", "networkUuid", true, true, "vpcUuid", "domainTemplateName");
Answer trashNtwkAns = _resource.executeRequest(cmdBuilder.build());
VspNetwork vspNetwork = buildVspNetwork();
TrashNetworkVspCommand cmd = new TrashNetworkVspCommand(vspNetwork);
doAnswer(genericAnswer).when(_mockNuageVspGuruClient).trash(vspNetwork);
Answer trashNtwkAns = _resource.executeRequest(cmd);
assertTrue(trashNtwkAns.getResult());
}
@ -205,10 +199,11 @@ public class NuageVspResourceTest {
public void testApplyStaticNatVspCommand() throws Exception {
_resource.configure("NuageVspResource", _hostDetails);
ApplyStaticNatVspCommand.Builder cmdBuilder = new ApplyStaticNatVspCommand.Builder().networkDomainUuid("networkDomainUuid").networkUuid("networkUuid")
.vpcOrSubnetUuid("vpcOrSubnetUuid").isL3Network(true).isVpc(true).staticNatDetails(new ArrayList<Map<String, Object>>());
doAnswer(genericAnswer).when(_mockNuageVspElementClient).applyStaticNats("networkDomainUuid", "networkUuid", "vpcOrSubnetUuid", true, true, new ArrayList<Map<String, Object>>());
Answer applyNatAns = _resource.executeRequest(cmdBuilder.build());
VspNetwork vspNetwork = buildVspNetwork();
List<VspStaticNat> vspStaticNatDetails = Lists.newArrayList(buildVspStaticNat());
ApplyStaticNatVspCommand cmd = new ApplyStaticNatVspCommand(vspNetwork, vspStaticNatDetails);
doAnswer(genericAnswer).when(_mockNuageVspElementClient).applyStaticNats(vspNetwork, vspStaticNatDetails);
Answer applyNatAns = _resource.executeRequest(cmd);
assertTrue(applyNatAns.getResult());
}
@ -216,12 +211,11 @@ public class NuageVspResourceTest {
public void testApplyAclRuleVspCommand() throws Exception {
_resource.configure("NuageVspResource", _hostDetails);
ApplyAclRuleVspCommand.Builder cmdBuilder = new ApplyAclRuleVspCommand.Builder().networkAcl(true).networkUuid("networkUuid").networkDomainUuid("networkDomainUuid")
.vpcOrSubnetUuid("vpcOrSubnetUuid").networkName("networkName").isL2Network(true).aclRules(new ArrayList<Map<String, Object>>()).networkId(100)
.egressDefaultPolicy(false).acsIngressAcl(true).networkReset(true).domainTemplateName("domainTemplateName");
doAnswer(genericAnswer).when(_mockNuageVspElementClient).applyAclRules(true, "networkUuid", "networkDomainUuid", "vpcOrSubnetUuid", "networkName", true,
new ArrayList<Map<String, Object>>(), 100, false, true, true, "domainTemplateName");
Answer applyAclAns = _resource.executeRequest(cmdBuilder.build());
VspNetwork vspNetwork = buildVspNetwork();
List<VspAclRule> vspAclRules = Lists.newArrayList(buildVspAclRule());
ApplyAclRuleVspCommand cmd = new ApplyAclRuleVspCommand(VspAclRule.ACLType.NetworkACL, vspNetwork, vspAclRules, false);
doAnswer(genericAnswer).when(_mockNuageVspElementClient).applyAclRules(VspAclRule.ACLType.NetworkACL, vspNetwork, vspAclRules, false);
Answer applyAclAns = _resource.executeRequest(cmd);
assertTrue(applyAclAns.getResult());
}
@ -229,19 +223,9 @@ public class NuageVspResourceTest {
public void testShutDownVpcVspCommand() throws Exception {
_resource.configure("NuageVspResource", _hostDetails);
ShutDownVpcVspCommand.Builder cmdBuilder = new ShutDownVpcVspCommand.Builder().domainUuid("domainUuid").vpcUuid("vpcUuid").domainTemplateName("domainTemplateName");
doAnswer(genericAnswer).when(_mockNuageVspElementClient).shutdownVpc("domainUuid", "vpcUuid", "domainTemplateName");
Answer shutVpcAns = _resource.executeRequest(cmdBuilder.build());
assertTrue(shutVpcAns.getResult());
}
@Test
public void testSyncVspCommand() throws Exception {
_resource.configure("NuageVspResource", _hostDetails);
SyncVspCommand shutVpcCmd = new SyncVspCommand("nuageVspEntity");
doAnswer(genericAnswer).when(_mockNuageVspSyncClient).syncWithNuageVsp("nuageVspEntity");
Answer shutVpcAns = _resource.executeRequest(shutVpcCmd);
ShutDownVpcVspCommand cmd = new ShutDownVpcVspCommand("domainUuid", "vpcUuid", "domainTemplateName", Lists.<String>newArrayList());
doAnswer(genericAnswer).when(_mockNuageVspElementClient).shutdownVpc("domainUuid", "vpcUuid", "domainTemplateName", Lists.<String>newArrayList());
Answer shutVpcAns = _resource.executeRequest(cmd);
assertTrue(shutVpcAns.getResult());
}
}

View File

@ -1,72 +0,0 @@
//
// 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 com.cloud.network.sync;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.network.NuageVspDeviceVO;
import com.cloud.network.dao.NuageVspDao;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class NuageVspSyncTest {
private static final long NETWORK_ID = 42L;
NuageVspDao nuageVspDao = mock(NuageVspDao.class);
AgentManager agentManager = mock(AgentManager.class);
HostDao hostDao = mock(HostDao.class);
NuageVspSyncImpl sync;
@Before
public void setUp() {
sync = new NuageVspSyncImpl();
sync._nuageVspDao = nuageVspDao;
sync._agentMgr = agentManager;
sync._hostDao = hostDao;
}
@Test
public void testSyncWithNuageVsp() {
final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
when(nuageVspDevice.getId()).thenReturn(NETWORK_ID);
when(nuageVspDao.listAll()).thenReturn(Arrays.asList(new NuageVspDeviceVO[] {nuageVspDevice}));
final HostVO host = mock(HostVO.class);
when(host.getId()).thenReturn(NETWORK_ID);
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
sync.syncWithNuageVsp("users");
}
}

View File

@ -0,0 +1,412 @@
//
// 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 com.cloud.util;
import com.cloud.NuageTest;
import com.cloud.dc.VlanVO;
import com.cloud.dc.dao.VlanDao;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.network.Network;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.network.dao.NetworkDetailsDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.vpc.NetworkACLItem;
import com.cloud.network.vpc.VpcVO;
import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.user.AccountVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.utils.net.Ip;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.VirtualMachine;
import com.google.common.collect.Lists;
import net.nuage.vsp.acs.client.api.model.VspAclRule;
import net.nuage.vsp.acs.client.api.model.VspDomain;
import net.nuage.vsp.acs.client.api.model.VspNetwork;
import net.nuage.vsp.acs.client.api.model.VspNic;
import net.nuage.vsp.acs.client.api.model.VspStaticNat;
import net.nuage.vsp.acs.client.api.model.VspVm;
import net.nuage.vsp.acs.client.common.model.Pair;
import org.junit.Before;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class NuageVspEntityBuilderTest extends NuageTest {
private static final long DOMAIN_ID = 1L;
private static final long ACCOUNT_ID = 1L;
private static final long NETWORK_OFFERING_ID = 1L;
private static final long SHARED_NETWORK_OFFERING_ID = 2L;
private static final long L2_NETWORK_OFFERING_ID = 3L;
private static final long VPC_ID = 1L;
private static final long SOURCE_IP_ADDRESS_ID = 1L;
private VpcDao _vpcDao = mock(VpcDao.class);
private DomainDao _domainDao = mock(DomainDao.class);
private AccountDao _accountDao = mock(AccountDao.class);
private NetworkOfferingDao _networkOfferingDao = mock(NetworkOfferingDao.class);
private NetworkOfferingServiceMapDao _networkOfferingServiceMapDao = mock(NetworkOfferingServiceMapDao.class);
private VlanDao _vlanDao = mock(VlanDao.class);
private IPAddressDao _ipAddressDao = mock(IPAddressDao.class);
private NetworkDetailsDao _networkDetailsDao = mock(NetworkDetailsDao.class);
private NuageVspEntityBuilder _nuageVspEntityBuilder = new NuageVspEntityBuilder();
private DomainVO _mockedDomain = mock(DomainVO.class);
private AccountVO _mockedAccount = mock(AccountVO.class);
private NetworkOfferingVO _mockedNetworkOffering = mock(NetworkOfferingVO.class);
private NetworkOfferingVO _mockedSharedNetworkOffering = mock(NetworkOfferingVO.class);
private NetworkOfferingVO _mockedL2NetworkOffering = mock(NetworkOfferingVO.class);
private VlanVO _mockedVlan = mock(VlanVO.class);
private VpcVO _mockedVpc = mock(VpcVO.class);
private NetworkVO _mockedNetwork = mock(NetworkVO.class);
private NetworkVO _mockedVpcNetwork = mock(NetworkVO.class);
private NetworkVO _mockedSharedNetwork = mock(NetworkVO.class);
private NetworkVO _mockedL2Network = mock(NetworkVO.class);
private VirtualMachine _mockedUserVirtualMachine = mock(VirtualMachine.class);
private VirtualMachine _mockedDomainRouterVirtualMachine = mock(VirtualMachine.class);
private NicProfile _mockedNicProfile = mock(NicProfile.class);
private NicVO _mockedNic = mock(NicVO.class);
private IPAddressVO _mockedStaticNatIp = mock(IPAddressVO.class);
private VlanVO _mockedStaticNatVlan = mock(VlanVO.class);
private FirewallRule _mockedFirewallRule = mock(FirewallRule.class);
private NetworkACLItem _mockedNetworkAclItem = mock(NetworkACLItem.class);
@Before
public void setUp() throws Exception {
super.setUp();
_nuageVspEntityBuilder._vpcDao = _vpcDao;
_nuageVspEntityBuilder._domainDao = _domainDao;
_nuageVspEntityBuilder._accountDao = _accountDao;
_nuageVspEntityBuilder._networkOfferingDao = _networkOfferingDao;
_nuageVspEntityBuilder._networkOfferingServiceMapDao = _networkOfferingServiceMapDao;
_nuageVspEntityBuilder._vlanDao = _vlanDao;
_nuageVspEntityBuilder._configurationDao = _configurationDao;
_nuageVspEntityBuilder._ipAddressDao = _ipAddressDao;
_nuageVspEntityBuilder._networkModel = _networkModel;
_nuageVspEntityBuilder._networkDetailsDao = _networkDetailsDao;
setUpMockedDomain();
setUpMockedAccount();
setUpMockedNetworkOffering(_mockedNetworkOffering, Network.GuestType.Isolated);
setUpMockedNetworkOffering(_mockedSharedNetworkOffering, Network.GuestType.Shared);
setUpMockedNetworkOffering(_mockedL2NetworkOffering, Network.GuestType.Isolated);
setUpMockedVlan();
setUpMockedVpc();
setUpMockedNetwork(_mockedNetwork, NETWORK_OFFERING_ID, null);
setUpMockedNetwork(_mockedVpcNetwork, NETWORK_OFFERING_ID, VPC_ID);
setUpMockedNetwork(_mockedSharedNetwork, SHARED_NETWORK_OFFERING_ID, null);
setUpMockedNetwork(_mockedL2Network, L2_NETWORK_OFFERING_ID, null);
setUpMockedVirtualMachine(_mockedUserVirtualMachine, false);
setUpMockedVirtualMachine(_mockedDomainRouterVirtualMachine, true);
setUpMockedNicProfile();
setUpMockedNic();
setUpMockedStaticNatIp();
setUpMockedStaticNatVlan();
setUpMockedFirewallRule();
setUpMockedNetworkAclItem();
setUpMockedDaoCalls();
}
@Test
public void testBuildVspDomain() {
VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(_mockedDomain);
validateVspDomain(vspDomain);
}
@Test
public void testBuildVspNetwork() {
VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(_mockedL2Network, true);
validateVspNetwork(vspNetwork, true, false, false, false, "IsolatedDomainTemplate", true);
vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(_mockedL2Network, false);
validateVspNetwork(vspNetwork, true, false, false, false, "IsolatedDomainTemplate", false);
vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(_mockedNetwork, true);
validateVspNetwork(vspNetwork, false, true, false, false, "IsolatedDomainTemplate", true);
vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(_mockedNetwork, false);
validateVspNetwork(vspNetwork, false, true, false, false, "IsolatedDomainTemplate", false);
vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(_mockedVpcNetwork, true);
validateVspNetwork(vspNetwork, false, false, true, false, "VpcDomainTemplate", true);
vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(_mockedVpcNetwork, false);
validateVspNetwork(vspNetwork, false, false, true, false, "VpcDomainTemplate", false);
vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(_mockedSharedNetwork, true);
validateVspNetwork(vspNetwork, false, false, false, true, "SharedDomainTemplate", true);
vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(_mockedSharedNetwork, false);
validateVspNetwork(vspNetwork, false, false, false, true, "SharedDomainTemplate", false);
}
@Test
public void testBuildVspVm() {
VspVm vspVm = _nuageVspEntityBuilder.buildVspVm(_mockedUserVirtualMachine, _mockedNetwork);
validateVspVm(vspVm, false);
vspVm = _nuageVspEntityBuilder.buildVspVm(_mockedDomainRouterVirtualMachine, _mockedNetwork);
validateVspVm(vspVm, true);
}
@Test
public void testBuildVspNic() {
VspNic vspNic = _nuageVspEntityBuilder.buildVspNic("nicUuid", _mockedNicProfile);
validateVspNic(vspNic);
vspNic = _nuageVspEntityBuilder.buildVspNic(_mockedNic);
validateVspNic(vspNic);
}
@Test
public void testBuildVspStaticNat() {
VspStaticNat vspStaticNat = _nuageVspEntityBuilder.buildVspStaticNat(true, _mockedStaticNatIp, _mockedStaticNatVlan, _mockedNic);
validateVspStaticNat(vspStaticNat, true);
}
@Test
public void testBuildVspAclRule() {
VspAclRule vspAclRule = _nuageVspEntityBuilder.buildVspAclRule(_mockedFirewallRule, _mockedNetwork);
validateVspAclRule(vspAclRule, true);
vspAclRule = _nuageVspEntityBuilder.buildVspAclRule(_mockedNetworkAclItem);
validateVspAclRule(vspAclRule, false);
}
private void validateVspDomain(VspDomain vspDomain) {
assertEquals("domainUuid", vspDomain.getUuid());
assertEquals("domainName", vspDomain.getName());
assertEquals("domainPath", vspDomain.getPath());
}
private void validateVspNetwork(VspNetwork vspNetwork, boolean isL2, boolean isL3, boolean isVpc, boolean isShared,
String domainTemplateName, boolean hasAddressRanges) {
assertEquals(NETWORK_ID, vspNetwork.getId());
assertEquals("networkUuid", vspNetwork.getUuid());
assertEquals("networkName", vspNetwork.getName());
assertNotNull(vspNetwork.getVspDomain());
validateVspDomain(vspNetwork.getVspDomain());
assertEquals("accountName", vspNetwork.getAccountName());
assertEquals("accountUuid", vspNetwork.getAccountUuid());
if (isVpc) {
assertEquals("vpcUuid", vspNetwork.getVpcUuid());
assertEquals("vpcName", vspNetwork.getVpcName());
} else {
assertNull(vspNetwork.getVpcUuid());
assertNull(vspNetwork.getVpcName());
}
assertEquals(isL2, vspNetwork.isL2());
assertEquals(isL3, vspNetwork.isL3());
assertEquals(isVpc, vspNetwork.isVpc());
assertEquals(isShared, vspNetwork.isShared());
assertEquals(true, vspNetwork.isFirewallServiceSupported());
assertEquals(true, vspNetwork.isEgressDefaultPolicy());
assertEquals(domainTemplateName, vspNetwork.getDomainTemplateName());
assertEquals("10.10.10.0/24", vspNetwork.getCidr());
assertEquals("10.10.10.1", vspNetwork.getGateway());
if (hasAddressRanges) {
if (isShared) {
assertEquals("192.168.2.2", vspNetwork.getVirtualRouterIp());
} else {
assertEquals("10.10.10.2", vspNetwork.getVirtualRouterIp());
}
List<Pair<String, String>> ipAddressRanges;
if (isShared) {
ipAddressRanges = Lists.newArrayList(Pair.of("192.168.2.3", "192.168.2.200"));
} else {
ipAddressRanges = Lists.newArrayList(Pair.of("10.10.10.3", "10.10.10.254"));
}
assertEquals(ipAddressRanges, vspNetwork.getIpAddressRanges());
}
}
private void validateVspVm(VspVm vspVm, boolean isDomainRouter) {
assertEquals("virtualMachineUuid", vspVm.getUuid());
assertEquals("virtualMachineInstanceName", vspVm.getName());
assertEquals(VspVm.State.Running, vspVm.getState());
assertEquals(isDomainRouter, vspVm.getDomainRouter());
}
private void validateVspNic(VspNic vspNic) {
assertEquals("nicUuid", vspNic.getUuid());
assertEquals("macAddress", vspNic.getMacAddress());
assertEquals(true, vspNic.getUseStaticIp());
assertEquals("10.10.10.2", vspNic.getIp());
}
private void validateVspStaticNat(VspStaticNat vspStaticNat, Boolean forRevoke) {
assertEquals("staticNatIpUuid", vspStaticNat.getIpUuid());
assertEquals("10.10.10.2", vspStaticNat.getIpAddress());
assertEquals(forRevoke, vspStaticNat.getRevoke());
assertEquals(true, vspStaticNat.getOneToOneNat());
assertEquals("staticNatVlanUuid", vspStaticNat.getVlanUuid());
assertEquals("10.10.10.1", vspStaticNat.getVlanGateway());
assertEquals("255.255.255.0", vspStaticNat.getVlanNetmask());
}
private void validateVspAclRule(VspAclRule vspAclRule, boolean isFirewall) {
assertEquals("aclUuid", vspAclRule.getUuid());
assertEquals("aclProtocol", vspAclRule.getProtocol());
assertEquals(new Integer(1), vspAclRule.getStartPort());
assertEquals(new Integer(20), vspAclRule.getEndPort());
assertEquals(Lists.newArrayList("10.10.0.0/16"), vspAclRule.getSourceCidrList());
assertEquals(VspAclRule.ACLState.Active, vspAclRule.getState());
assertEquals(VspAclRule.ACLTrafficType.Egress, vspAclRule.getTrafficType());
if (isFirewall) {
assertEquals(VspAclRule.ACLType.Firewall, vspAclRule.getType());
assertEquals("192.168.0.24/32", vspAclRule.getSourceIpAddress());
assertEquals(VspAclRule.ACLAction.Deny, vspAclRule.getAction());
} else {
assertEquals(VspAclRule.ACLType.NetworkACL, vspAclRule.getType());
assertNull(vspAclRule.getSourceIpAddress());
assertEquals(VspAclRule.ACLAction.Allow, vspAclRule.getAction());
}
}
private void setUpMockedDomain() {
when(_mockedDomain.getUuid()).thenReturn("domainUuid");
when(_mockedDomain.getName()).thenReturn("domainName");
when(_mockedDomain.getPath()).thenReturn("domainPath");
}
private void setUpMockedAccount() {
when(_mockedAccount.getUuid()).thenReturn("accountUuid");
when(_mockedAccount.getAccountName()).thenReturn("accountName");
}
private void setUpMockedNetworkOffering(NetworkOfferingVO networkOfferingToMock, Network.GuestType guestType) {
when(networkOfferingToMock.getEgressDefaultPolicy()).thenReturn(true);
when(networkOfferingToMock.getGuestType()).thenReturn(guestType);
}
private void setUpMockedVlan() {
when(_mockedVlan.getIpRange()).thenReturn("192.168.2.2-192.168.2.200");
}
private void setUpMockedVpc() {
when(_mockedVpc.getUuid()).thenReturn("vpcUuid");
when(_mockedVpc.getName()).thenReturn("vpcName");
}
private void setUpMockedNetwork(NetworkVO networkToMock, long networkOfferingId, Long vpcId) {
when(networkToMock.getId()).thenReturn(NETWORK_ID);
when(networkToMock.getUuid()).thenReturn("networkUuid");
when(networkToMock.getName()).thenReturn("networkName");
when(networkToMock.getCidr()).thenReturn("10.10.10.0/24");
when(networkToMock.getGateway()).thenReturn("10.10.10.1");
when(networkToMock.getDomainId()).thenReturn(DOMAIN_ID);
when(networkToMock.getAccountId()).thenReturn(ACCOUNT_ID);
when(networkToMock.getNetworkOfferingId()).thenReturn(networkOfferingId);
when(networkToMock.getVpcId()).thenReturn(vpcId != null ? vpcId : null);
}
private void setUpMockedVirtualMachine(VirtualMachine virtualMachineToMock, boolean isDomainRouter) {
when(virtualMachineToMock.getUuid()).thenReturn("virtualMachineUuid");
when(virtualMachineToMock.getInstanceName()).thenReturn("virtualMachineInstanceName");
when(virtualMachineToMock.getState()).thenReturn(VirtualMachine.State.Running);
when(virtualMachineToMock.getType()).thenReturn(isDomainRouter ? VirtualMachine.Type.DomainRouter : VirtualMachine.Type.User);
}
private void setUpMockedNicProfile() {
when(_mockedNicProfile.getMacAddress()).thenReturn("macAddress");
when(_mockedNicProfile.getIPv4Address()).thenReturn("10.10.10.2");
}
private void setUpMockedNic() {
when(_mockedNic.getUuid()).thenReturn("nicUuid");
when(_mockedNic.getMacAddress()).thenReturn("macAddress");
when(_mockedNic.getIPv4Address()).thenReturn("10.10.10.2");
}
private void setUpMockedStaticNatIp() {
when(_mockedStaticNatIp.getUuid()).thenReturn("staticNatIpUuid");
when(_mockedStaticNatIp.getAddress()).thenReturn(new Ip("10.10.10.2"));
when(_mockedStaticNatIp.isOneToOneNat()).thenReturn(true);
when(_mockedStaticNatIp.getVmIp()).thenReturn("192.168.0.24");
}
private void setUpMockedStaticNatVlan() {
when(_mockedStaticNatVlan.getUuid()).thenReturn("staticNatVlanUuid");
when(_mockedStaticNatVlan.getVlanGateway()).thenReturn("10.10.10.1");
when(_mockedStaticNatVlan.getVlanNetmask()).thenReturn("255.255.255.0");
}
private void setUpMockedFirewallRule() {
when(_mockedFirewallRule.getUuid()).thenReturn("aclUuid");
when(_mockedFirewallRule.getProtocol()).thenReturn("aclProtocol");
when(_mockedFirewallRule.getSourcePortStart()).thenReturn(1);
when(_mockedFirewallRule.getSourcePortEnd()).thenReturn(20);
when(_mockedFirewallRule.getSourceCidrList()).thenReturn(Lists.newArrayList("10.10.0.0/16"));
when(_mockedFirewallRule.getState()).thenReturn(FirewallRule.State.Active);
when(_mockedFirewallRule.getTrafficType()).thenReturn(FirewallRule.TrafficType.Egress);
when(_mockedFirewallRule.getSourceIpAddressId()).thenReturn(SOURCE_IP_ADDRESS_ID);
}
private void setUpMockedNetworkAclItem() {
when(_mockedNetworkAclItem.getUuid()).thenReturn("aclUuid");
when(_mockedNetworkAclItem.getProtocol()).thenReturn("aclProtocol");
when(_mockedNetworkAclItem.getSourcePortStart()).thenReturn(1);
when(_mockedNetworkAclItem.getSourcePortEnd()).thenReturn(20);
when(_mockedNetworkAclItem.getSourceCidrList()).thenReturn(Lists.newArrayList("10.10.0.0/16"));
when(_mockedNetworkAclItem.getNumber()).thenReturn(1337);
when(_mockedNetworkAclItem.getState()).thenReturn(NetworkACLItem.State.Active);
when(_mockedNetworkAclItem.getTrafficType()).thenReturn(NetworkACLItem.TrafficType.Egress);
when(_mockedNetworkAclItem.getAction()).thenReturn(NetworkACLItem.Action.Allow);
}
private void setUpMockedDaoCalls() {
when(_domainDao.findById(DOMAIN_ID)).thenReturn(_mockedDomain);
when(_accountDao.findById(ACCOUNT_ID)).thenReturn(_mockedAccount);
when(_networkOfferingDao.findById(NETWORK_OFFERING_ID)).thenReturn(_mockedNetworkOffering);
when(_networkOfferingDao.findById(SHARED_NETWORK_OFFERING_ID)).thenReturn(_mockedSharedNetworkOffering);
when(_networkOfferingDao.findById(L2_NETWORK_OFFERING_ID)).thenReturn(_mockedL2NetworkOffering);
when(_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(NETWORK_OFFERING_ID, Network.Service.SourceNat)).thenReturn(true);
when(_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(NETWORK_OFFERING_ID, Network.Service.StaticNat)).thenReturn(true);
when(_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(SHARED_NETWORK_OFFERING_ID, Network.Service.SourceNat)).thenReturn(true);
when(_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(SHARED_NETWORK_OFFERING_ID, Network.Service.StaticNat)).thenReturn(true);
when(_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(L2_NETWORK_OFFERING_ID, Network.Service.SourceNat)).thenReturn(false);
when(_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(L2_NETWORK_OFFERING_ID, Network.Service.StaticNat)).thenReturn(false);
when(_networkModel.areServicesSupportedByNetworkOffering(NETWORK_OFFERING_ID, Network.Service.Firewall)).thenReturn(true);
when(_networkModel.areServicesSupportedByNetworkOffering(SHARED_NETWORK_OFFERING_ID, Network.Service.Firewall)).thenReturn(true);
when(_networkModel.areServicesSupportedByNetworkOffering(L2_NETWORK_OFFERING_ID, Network.Service.Firewall)).thenReturn(true);
when(_vlanDao.listVlansByNetworkId(NETWORK_ID)).thenReturn(Lists.newArrayList(_mockedVlan));
when(_vpcDao.findById(VPC_ID)).thenReturn(_mockedVpc);
when(_ipAddressDao.findById(SOURCE_IP_ADDRESS_ID)).thenReturn(_mockedStaticNatIp);
}
}

View File

@ -75,6 +75,7 @@
<module>network-elements/palo-alto</module>
<module>network-elements/netscaler</module>
<module>network-elements/nicira-nvp</module>
<module>network-elements/nuage-vsp</module>
<module>network-elements/bigswitch</module>
<module>network-elements/brocade-vcs</module>
<module>network-elements/midonet</module>
@ -170,17 +171,6 @@
<module>network-elements/juniper-srx</module>
</modules>
</profile>
<profile>
<id>nuagevsp</id>
<activation>
<property>
<name>noredist</name>
</property>
</activation>
<modules>
<module>network-elements/nuage-vsp</module>
</modules>
</profile>
<profile>
<id>vmware</id>
<activation>

View File

@ -50,7 +50,7 @@ import socket
class nuageTestCase(cloudstackTestCase):
@classmethod
def setUpClass(cls):
def setUpClass(cls, zone=None):
cls.debug("setUpClass nuageTestCase")
# We want to fail quicker, if it's a failure
@ -60,9 +60,11 @@ class nuageTestCase(cloudstackTestCase):
cls.api_client = test_client.getApiClient()
cls.db_client = test_client.getDbConnection()
cls.test_data = test_client.getParsedTestDataConfig()
# Get Zone, Domain and templates
cls.zone = get_zone(cls.api_client)
cls.zone = get_zone(cls.api_client,
zone_name=zone.name if zone else None,
zone_id=zone.id if zone else None
)
cls.domain = get_domain(cls.api_client)
cls.template = get_template(cls.api_client,
cls.zone.id,

View File

@ -15,22 +15,22 @@
# specific language governing permissions and limitations
# under the License.
""" Tests for basic VPC Network functionality with Nuage VSP SDN plugin
""" Component tests for basic VPC Network functionality with Nuage VSP SDN plugin
"""
# Import Local Modules
from nuageTestCase import nuageTestCase
from marvin.lib.base import Account
from marvin.lib.base import Account, Zone
# Import System Modules
from nose.plugins.attrib import attr
class TestVpcNetworkNuage(nuageTestCase):
class TestNuageVpcNetwork(nuageTestCase):
""" Test basic VPC Network functionality with Nuage VSP SDN plugin
"""
@classmethod
def setUpClass(cls):
super(TestVpcNetworkNuage, cls).setUpClass()
def setUpClass(cls, zone=None):
super(TestNuageVpcNetwork, cls).setUpClass(zone=zone)
return
def setUp(self):
@ -45,7 +45,7 @@ class TestVpcNetworkNuage(nuageTestCase):
@attr(tags=["advanced", "nuagevsp"], required_hardware="false")
def test_nuage_vpc_network(self):
""" Test Basic VPC Network Functionality with Nuage VSP SDN plugin
""" Test basic VPC Network functionality with Nuage VSP SDN plugin
"""
# 1. Create Nuage VSP VPC offering, check if it is successfully created and enabled.
@ -97,3 +97,19 @@ class TestVpcNetworkNuage(nuageTestCase):
# VSD verification for ACL item
self.verify_vsp_firewall_rule(acl_item)
@attr(tags=["advanced", "nuagevsp", "multizone"], required_hardware="false")
def test_nuage_vpc_network_multizone(self):
""" Test basic VPC Network functionality with Nuage VSP SDN plugin on multiple zones
"""
# Repeat the tests in the above testcase "test_nuage_vpc_network" on multiple zones
self.debug("Testing basic VPC Network functionality with Nuage VSP SDN plugin on multiple zones...")
zones = Zone.list(self.api_client)
if len(zones) == 1:
self.skipTest("There is only one Zone configured: skipping test")
for zone in zones:
self.debug("Zone - %s" % zone.name)
self.setUpClass(zone=zone)
self.test_nuage_vpc_network()

View File

@ -561,7 +561,7 @@ class DeployDataCenters(object):
netprov.physicalnetworkid = phynetwrk.id
result = self.__apiClient.addNetworkServiceProvider(netprov)
self.enableProvider(result.id)
elif provider.name in ['Netscaler', 'JuniperSRX', 'F5BigIp', 'NiciraNvp']:
elif provider.name in ['Netscaler', 'JuniperSRX', 'F5BigIp', 'NiciraNvp', 'NuageVsp']:
netprov = addNetworkServiceProvider.\
addNetworkServiceProviderCmd()
netprov.name = provider.name
@ -631,6 +631,21 @@ class DeployDataCenters(object):
self.__tcRunLogger.\
debug("==== AddNiciraNvp Successful =====")
self.__addToCleanUp("NiciraNvp", ret.id)
elif provider.name == 'NuageVsp':
dev = addNuageVspDevice.addNuageVspDeviceCmd()
dev.hostname = device.hostname
dev.port = device.port
dev.username = device.username
dev.password = device.password
dev.retrycount = device.retrycount
dev.retryinterval = device.retryinterval
dev.physicalnetworkid = phynetwrk.id
ret = self.__apiClient.addNuageVspDevice(dev)
if ret.id:
self.__tcRunLogger.\
debug("==== addNuageVspDevice "
"Successful=====")
self.__addToCleanUp("addNuageVspDevice", ret.id)
else:
raise InvalidParameterException(
"Device %s doesn't match "

View File

@ -7109,7 +7109,7 @@
},
apiversion: {
label: 'label.api.version',
defaultValue: 'v1_0',
defaultValue: 'v3_2',
validation: {
required: true
},
@ -13185,7 +13185,7 @@
},
apiversion: {
label: 'label.api.version',
defaultValue: 'v1_0'
defaultValue: 'v3_2'
},
retrycount: {
label: 'label.numretries',