Merge pull request #801 from nlivens/updated-nuage-vsp-plugin

CLOUDSTACK-8832 : Update Nuage VSP plugin to work with Nuage VSP release 3.2

* pr/801:
  CLOUDSTACK-8832 : Update Nuage VSP plugin to work with Nuage VSP release 3.2

Signed-off-by: Remi Bergsma <github@remi.nl>
This commit is contained in:
Remi Bergsma 2015-11-18 12:09:09 +01:00
commit 95ae7963d5
72 changed files with 5096 additions and 1292 deletions

View File

@ -59,4 +59,26 @@ public class Answer extends Command {
public static UnsupportedAnswer createUnsupportedVersionAnswer(final Command cmd) {
return new UnsupportedAnswer(cmd, "Unsuppored Version.");
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Answer)) return false;
if (!super.equals(o)) return false;
Answer answer = (Answer) o;
if (result != answer.result) return false;
if (details != null ? !details.equals(answer.details) : answer.details != null) return false;
return true;
}
@Override
public int hashCode() {
int result1 = super.hashCode();
result1 = 31 * result1 + (result ? 1 : 0);
result1 = 31 * result1 + (details != null ? details.hashCode() : 0);
return result1;
}
}

View File

@ -73,4 +73,24 @@ public abstract class Command {
public boolean allowCaching() {
return true;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Command)) return false;
Command command = (Command) o;
if (wait != command.wait) return false;
if (contextMap != null ? !contextMap.equals(command.contextMap) : command.contextMap != null) return false;
return true;
}
@Override
public int hashCode() {
int result = contextMap != null ? contextMap.hashCode() : 0;
result = 31 * result + wait;
return result;
}
}

View File

@ -434,6 +434,7 @@ public class EventTypes {
// external network mapping events
public static final String EVENT_EXTERNAL_VSP_VSD_ADD = "PHYSICAL.NUAGE.VSD.ADD";
public static final String EVENT_EXTERNAL_VSP_VSD_UPDATE = "PHYSICAL.NUAGE.VSD.UPDATE";
public static final String EVENT_EXTERNAL_VSP_VSD_DELETE = "PHYSICAL.NUAGE.VSD.DELETE";
// AutoScale
public static final String EVENT_COUNTER_CREATE = "COUNTER.CREATE";

View File

@ -134,7 +134,6 @@ public interface Network extends ControlledEntity, StateObject<Network.State>, I
public static final Provider Opendaylight = new Provider("Opendaylight", false);
// add Nuage Vsp Providers
public static final Provider NuageVsp = new Provider("NuageVsp", false);
public static final Provider NuageVspVpc = new Provider("NuageVspVpc", false);
public static final Provider BrocadeVcs = new Provider("BrocadeVcs", false);
// add GloboDns provider
public static final Provider GloboDns = new Provider("GloboDns", true);

View File

@ -644,6 +644,7 @@ deleteStratoshereSsp=1
#### nuage vsp commands
addNuageVspDevice=1
updateNuageVspDevice=1
deleteNuageVspDevice=1
listNuageVspDevices=1
issueNuageVspResourceRequest=15

View File

@ -45,4 +45,26 @@ public class PingCommand extends Command {
public boolean executeInSequence() {
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PingCommand)) return false;
if (!super.equals(o)) return false;
PingCommand that = (PingCommand) o;
if (hostId != that.hostId) return false;
if (hostType != that.hostType) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (hostType != null ? hostType.hashCode() : 0);
result = 31 * result + (int) (hostId ^ (hostId >>> 32));
return result;
}
}

View File

@ -87,4 +87,6 @@ public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
void lockRange(long vlandbId);
List<IPAddressVO> listByAssociatedVmId(long vmId);
IPAddressVO findByVmIdAndNetworkId(long networkId, long vmId);
}

View File

@ -458,6 +458,14 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
return listBy(sc);
}
@Override
public IPAddressVO findByVmIdAndNetworkId(long networkId, long vmId) {
SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
sc.setParameters("network", networkId);
sc.setParameters("associatedWithVmId", vmId);
return findOneBy(sc);
}
@Override
public void lockRange(long vlandbId) {
SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();

View File

@ -29,7 +29,7 @@ public interface NetworkACLItemDao extends GenericDao<NetworkACLItemVO, Long> {
boolean revoke(NetworkACLItemVO rule);
List<NetworkACLItemVO> listByACL(long aclId);
List<NetworkACLItemVO> listByACL(Long aclId);
int getMaxNumberByACL(long aclId);

View File

@ -99,6 +99,14 @@ public class VpcOfferingVO implements VpcOffering {
this.redundantRouter = redundantRouter;
}
public VpcOfferingVO(String name, String displayText, boolean isDefault, Long serviceOfferingId,
boolean supportsDistributedRouter, boolean offersRegionLevelVPC) {
this(name, displayText, serviceOfferingId);
this.isDefault = isDefault;
this.supportsDistributedRouter = supportsDistributedRouter;
this.offersRegionLevelVPC = offersRegionLevelVPC;
}
@Override
public long getId() {
return id;

View File

@ -21,6 +21,7 @@ import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import com.google.common.collect.Lists;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@ -115,7 +116,9 @@ public class NetworkACLItemDaoImpl extends GenericDaoBase<NetworkACLItemVO, Long
}
@Override
public List<NetworkACLItemVO> listByACL(long aclId) {
public List<NetworkACLItemVO> listByACL(Long aclId) {
if (aclId == null) return Lists.newArrayList();
SearchCriteria<NetworkACLItemVO> sc = AllFieldsSearch.create();
sc.setParameters("aclId", aclId);
List<NetworkACLItemVO> list = listBy(sc);

View File

@ -28,6 +28,13 @@
<version>4.7.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${cs.lang3.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

View File

@ -17,18 +17,8 @@
// under the License.
//
package com.cloud.agent.api.sync;
import com.cloud.agent.api.Answer;
public class SyncVspAnswer extends Answer {
public SyncVspAnswer(SyncVspCommand cmd, boolean success, String details) {
super(cmd, success, details);
}
public SyncVspAnswer(SyncVspCommand cmd, Exception e) {
super(cmd, e);
}
package com.cloud.agent.api;
public interface CmdBuilder<T> {
T build();
}

View File

@ -0,0 +1,56 @@
//
// 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;
import com.cloud.host.Host;
public class PingNuageVspCommand extends PingCommand {
private final boolean shouldAudit;
public PingNuageVspCommand(Host.Type type, long id, boolean shouldAudit) {
super(type, id);
this.shouldAudit = shouldAudit;
}
public boolean shouldAudit() {
return shouldAudit;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PingNuageVspCommand)) return false;
if (!super.equals(o)) return false;
PingNuageVspCommand that = (PingNuageVspCommand) o;
if (shouldAudit != that.shouldAudit) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (shouldAudit ? 1 : 0);
return result;
}
}

View File

@ -21,9 +21,14 @@ package com.cloud.agent.api;
import com.cloud.host.Host;
/**
* 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 StartupVspCommand extends StartupCommand {
public StartupVspCommand() {
super(Host.Type.L2Networking);
}
}

View File

@ -21,7 +21,7 @@ package com.cloud.agent.api;
public class VspResourceAnswer extends Answer {
String _resourceInfo;
private String _resourceInfo;
public VspResourceAnswer(Command cmd, String resourceInfo, String details) {
super(cmd, true, details);
@ -39,4 +39,22 @@ public class VspResourceAnswer extends Answer {
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

@ -21,14 +21,14 @@ package com.cloud.agent.api;
public class VspResourceCommand extends Command {
String _method;
String _resource;
String _resourceId;
String _childResource;
Object _entityDetails;
String _resourceFilter;
String _proxyUserUuid;
String _proxyUserDomainuuid;
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) {
@ -79,4 +79,41 @@ public class VspResourceCommand extends Command {
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

@ -1,34 +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.element;
import com.cloud.agent.api.Answer;
public class ApplyAclRuleVspAnswer extends Answer {
public ApplyAclRuleVspAnswer(ApplyAclRuleVspCommand cmd, boolean success, String details) {
super(cmd, success, details);
}
public ApplyAclRuleVspAnswer(ApplyAclRuleVspCommand cmd, Exception e) {
super(cmd, e);
}
}

View File

@ -19,31 +19,46 @@
package com.cloud.agent.api.element;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
import java.util.List;
import java.util.Map;
import com.cloud.agent.api.Command;
public class ApplyAclRuleVspCommand extends Command {
String _networkUuid;
String _networkDomainUuid;
String _vpcOrSubnetUuid;
boolean _isL3Network;
List<Map<String, Object>> _aclRules;
boolean _isVpc;
long _networkId;
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 boolean _networkReset;
private final String _domainTemplateName;
public ApplyAclRuleVspCommand(String networkUuid, String networkDomainUuid, String vpcOrSubnetUuid, boolean isL3Network, List<Map<String, Object>> aclRules, boolean isVpc,
long networkId) {
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) {
super();
this._networkAcl = networkAcl;
this._networkUuid = networkUuid;
this._networkDomainUuid = networkDomainUuid;
this._vpcOrSubnetUuid = vpcOrSubnetUuid;
this._isL3Network = isL3Network;
this._networkName = networkName;
this._isL2Network = isL2Network;
this._aclRules = aclRules;
this._isVpc = isVpc;
this._networkId = networkId;
this._egressDefaultPolicy = egressDefaultPolicy;
this._acsIngressAcl = acsIngressAcl;
this._networkReset = networkReset;
this._domainTemplateName = domainTemplateName;
}
public boolean isNetworkAcl() {
return _networkAcl;
}
public String getNetworkUuid() {
@ -58,20 +73,117 @@ public class ApplyAclRuleVspCommand extends Command {
return _vpcOrSubnetUuid;
}
public boolean isL3Network() {
return _isL3Network;
public String getNetworkName() {
return _networkName;
}
public boolean isL2Network() {
return _isL2Network;
}
public List<Map<String, Object>> getAclRules() {
return _aclRules;
}
public boolean isVpc() {
return _isVpc;
public long getNetworkId() {
return _networkId;
}
public long getNetworkId() {
return this._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
@ -79,4 +191,49 @@ public class ApplyAclRuleVspCommand extends Command {
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ApplyAclRuleVspCommand)) return false;
if (!super.equals(o)) return false;
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;
return true;
}
@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 + (_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

@ -1,34 +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.element;
import com.cloud.agent.api.Answer;
public class ApplyStaticNatVspAnswer extends Answer {
public ApplyStaticNatVspAnswer(ApplyStaticNatVspCommand cmd, boolean success, String details) {
super(cmd, success, details);
}
public ApplyStaticNatVspAnswer(ApplyStaticNatVspCommand cmd, Exception e) {
super(cmd, e);
}
}

View File

@ -19,23 +19,29 @@
package com.cloud.agent.api.element;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
import java.util.List;
import java.util.Map;
import com.cloud.agent.api.Command;
public class ApplyStaticNatVspCommand extends Command {
String _networkDomainUuid;
String _vpcOrSubnetUuid;
boolean _isL3Network;
List<Map<String, Object>> _staticNatDetails;
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;
public ApplyStaticNatVspCommand(String networkDomainUuid, String vpcOrSubnetUuid, boolean isL3Network, List<Map<String, Object>> staticNatDetails) {
private ApplyStaticNatVspCommand(String networkDomainUuid, String networkUuid, String vpcOrSubnetUuid, boolean isL3Network, boolean isVpc,
List<Map<String, Object>> staticNatDetails) {
super();
this._networkDomainUuid = networkDomainUuid;
this._networkUuid = networkUuid;
this._vpcOrSubnetUuid = vpcOrSubnetUuid;
this._isL3Network = isL3Network;
this._isVpc = isVpc;
this._staticNatDetails = staticNatDetails;
}
@ -43,6 +49,10 @@ public class ApplyStaticNatVspCommand extends Command {
return _networkDomainUuid;
}
public String getNetworkUuid() {
return _networkUuid;
}
public String getVpcOrSubnetUuid() {
return _vpcOrSubnetUuid;
}
@ -51,13 +61,93 @@ public class ApplyStaticNatVspCommand extends Command {
return _isL3Network;
}
public boolean isVpc() {
return _isVpc;
}
public List<Map<String, Object>> 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;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ApplyStaticNatVspCommand)) return false;
if (!super.equals(o)) return false;
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 (_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;
}
@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 + (_staticNatDetails != null ? _staticNatDetails.hashCode() : 0);
return result;
}
}

View File

@ -0,0 +1,297 @@
//
// 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.element;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
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 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 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) {
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._dnsServers = dnsServers;
this._ingressFirewallRules = ingressFirewallRules;
this._egressFirewallRules = egressFirewallRules;
this._acsFipUuid = acsFipUuid;
this._egressDefaultPolicy = egressDefaultPolicy;
}
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 List<String> getDnsServers() {
return _dnsServers;
}
public List<Map<String, Object>> getIngressFirewallRules() {
return _ingressFirewallRules;
}
public List<Map<String, Object>> 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);
}
}
@Override
public boolean executeInSequence() {
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ImplementVspCommand)) return false;
if (!super.equals(o)) return false;
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 (_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;
return true;
}
@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 + (_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);
return result;
}
}

View File

@ -1,34 +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.element;
import com.cloud.agent.api.Answer;
public class ShutDownVpcVspAnswer extends Answer {
public ShutDownVpcVspAnswer(ShutDownVpcVspCommand cmd, boolean success, String details) {
super(cmd, success, details);
}
public ShutDownVpcVspAnswer(ShutDownVpcVspCommand cmd, Exception e) {
super(cmd, e);
}
}

View File

@ -19,17 +19,20 @@
package com.cloud.agent.api.element;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
public class ShutDownVpcVspCommand extends Command {
String _domainUuid;
String _vpcUuid;
private final String _domainUuid;
private final String _vpcUuid;
private final String _domainTemplateName;
public ShutDownVpcVspCommand(String domainUuid, String vpcUuid) {
private ShutDownVpcVspCommand(String domainUuid, String vpcUuid, String domainTemplateName) {
super();
this._domainUuid = domainUuid;
this._vpcUuid = vpcUuid;
this._domainTemplateName = domainTemplateName;
}
public String getDomainUuid() {
@ -40,9 +43,63 @@ public class ShutDownVpcVspCommand extends Command {
return _vpcUuid;
}
public String getDomainTemplateName() {
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);
}
}
@Override
public boolean executeInSequence() {
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ShutDownVpcVspCommand)) return false;
if (!super.equals(o)) return false;
ShutDownVpcVspCommand that = (ShutDownVpcVspCommand) o;
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 (_vpcUuid != null ? !_vpcUuid.equals(that._vpcUuid) : that._vpcUuid != null) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_domainUuid != null ? _domainUuid.hashCode() : 0);
result = 31 * result + (_vpcUuid != null ? _vpcUuid.hashCode() : 0);
result = 31 * result + (_domainTemplateName != null ? _domainTemplateName.hashCode() : 0);
return result;
}
}

View File

@ -1,34 +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.guru;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
public class DeallocateVmVspAnswer extends Answer {
public DeallocateVmVspAnswer(Command command, Exception e) {
super(command, e);
}
public DeallocateVmVspAnswer(DeallocateVmVspCommand cmd, boolean success, String details) {
super(cmd, success, details);
}
}

View File

@ -19,40 +19,45 @@
package com.cloud.agent.api.guru;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
public class DeallocateVmVspCommand extends Command {
String _networkUuid;
String _nicFrmDdUuid;
String _nicMacAddress;
String _nicIp4Address;
boolean _isL3Network;
String _vpcUuid;
String _networksDomainUuid;
String _vmInstanceName;
String _vmUuid;
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;
public DeallocateVmVspCommand(String networkUuid, String nicFrmDdUuid, String nicMacAddress, String nicIp4Address, boolean isL3Network, String vpcUuid,
String networksDomainUuid, String vmInstanceName, String vmUuid) {
private DeallocateVmVspCommand(String networkUuid, String nicFromDdUuid, String nicMacAddress, String nicIp4Address, boolean isL3Network, boolean isSharedNetwork, String vpcUuid,
String networksDomainUuid, String vmInstanceName, String vmUuid, boolean isExpungingState) {
super();
this._networkUuid = networkUuid;
this._nicFrmDdUuid = nicFrmDdUuid;
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;
}
public String getNetworkUuid() {
return _networkUuid;
}
public String getNicFrmDdUuid() {
return _nicFrmDdUuid;
public String getNicFromDdUuid() {
return _nicFromDdUuid;
}
public String getNicMacAddress() {
@ -67,6 +72,10 @@ public class DeallocateVmVspCommand extends Command {
return _isL3Network;
}
public boolean isSharedNetwork() {
return _isSharedNetwork;
}
public String getVpcUuid() {
return _vpcUuid;
}
@ -83,9 +92,132 @@ public class DeallocateVmVspCommand extends Command {
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);
}
}
@Override
public boolean executeInSequence() {
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DeallocateVmVspCommand)) return false;
if (!super.equals(o)) return false;
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;
return true;
}
@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);
return result;
}
}

View File

@ -19,30 +19,39 @@
package com.cloud.agent.api.guru;
import java.util.Collection;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
import java.util.Collection;
import java.util.List;
public class ImplementNetworkVspCommand extends Command {
String _networkDomainName;
String _networkDomainPath;
String _networkDomainUuid;
String _networkAccountName;
String _networkAccountUuid;
String _networkName;
String _networkCidr;
String _networkGateway;
String _networkUuid;
boolean _isL3Network;
String _vpcName;
String _vpcUuid;
boolean _defaultEgressPolicy;
Collection<String> _ipAddressRange;
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 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;
public ImplementNetworkVspCommand(String networkDomainName, String networkDomainPath, String networkDomainUuid, String networkAccountName, String networkAccountUuid,
String networkName, String networkCidr, String networkGateway, String networkUuid, boolean isL3Network, String vpcName, String vpcUuid, boolean defaultEgressPolicy,
Collection<String> ipAddressRange) {
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) {
super();
this._networkDomainName = networkDomainName;
this._networkDomainPath = networkDomainPath;
@ -52,12 +61,18 @@ public class ImplementNetworkVspCommand extends Command {
this._networkName = networkName;
this._networkCidr = networkCidr;
this._networkGateway = networkGateway;
this._networkAclId = networkAclId;
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() {
@ -92,6 +107,18 @@ public class ImplementNetworkVspCommand extends Command {
return _networkGateway;
}
public Long getNetworkAclId() {
return _networkAclId;
}
public List<String> getDnsServers() {
return _dnsServers;
}
public List<String> getGatewaySystemIds() {
return _gatewaySystemIds;
}
public String getNetworkUuid() {
return _networkUuid;
}
@ -100,6 +127,14 @@ public class ImplementNetworkVspCommand extends Command {
return _isL3Network;
}
public boolean isVpc() {
return _isVpc;
}
public boolean isSharedNetwork() {
return _isSharedNetwork;
}
public String getVpcName() {
return _vpcName;
}
@ -112,13 +147,214 @@ public class ImplementNetworkVspCommand extends Command {
return _defaultEgressPolicy;
}
public Collection<String> getIpAddressRange() {
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;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ImplementNetworkVspCommand)) return false;
if (!super.equals(o)) return false;
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;
return true;
}
@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 + (_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

@ -1,34 +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.guru;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
public class ReleaseVmVspAnswer extends Answer {
public ReleaseVmVspAnswer(Command command, Exception e) {
super(command, e);
}
public ReleaseVmVspAnswer(ReleaseVmVspCommand cmd, boolean success, String details) {
super(cmd, success, details);
}
}

View File

@ -19,31 +19,45 @@
package com.cloud.agent.api.guru;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
public class ReserveVmInterfaceVspCommand extends Command {
String _nicUuid;
String _nicMacAddress;
String _networkUuid;
boolean _isL3Network;
String _vpcUuid;
String _networkDomainUuid;
String _networksAccountUuid;
boolean _isDomainRouter;
String _domainRouterIp;
String _vmInstanceName;
String _vmUuid;
String _vmUserName;
String _vmUserDomainName;
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;
public ReserveVmInterfaceVspCommand(String nicUuid, String nicMacAddress, String networkUuid, boolean isL3Network, String vpcUuid, String networkDomainUuid,
String networksAccountUuid, boolean isDomainRouter, String domainRouterIp, String vmInstanceName, String vmUuid, String vmUserName, String vmUserDomainName) {
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) {
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;
@ -53,6 +67,15 @@ public class ReserveVmInterfaceVspCommand extends Command {
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;
}
public String getNicUuid() {
@ -71,6 +94,10 @@ public class ReserveVmInterfaceVspCommand extends Command {
return _isL3Network;
}
public boolean isSharedNetwork() {
return _isSharedNetwork;
}
public String getVpcUuid() {
return _vpcUuid;
}
@ -87,29 +114,287 @@ public class ReserveVmInterfaceVspCommand extends Command {
return _isDomainRouter;
}
public String _getDomainRouterIp() {
public String getDomainRouterIp() {
return _domainRouterIp;
}
public String _getVmInstanceName() {
public String getVmInstanceName() {
return _vmInstanceName;
}
public String _getVmUuid() {
public String getVmUuid() {
return _vmUuid;
}
public String _getVmUserName() {
public String getVmUserName() {
return _vmUserName;
}
public String _getVmUserDomainName() {
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);
}
}
@Override
public boolean executeInSequence() {
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ReserveVmInterfaceVspCommand)) return false;
if (!super.equals(o)) return false;
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;
return true;
}
@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);
return result;
}
}

View File

@ -1,34 +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.guru;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
public class TrashNetworkVspAnswer extends Answer {
public TrashNetworkVspAnswer(Command command, Exception e) {
super(command, e);
}
public TrashNetworkVspAnswer(TrashNetworkVspCommand cmd, boolean success, String details) {
super(cmd, success, details);
}
}

View File

@ -19,21 +19,26 @@
package com.cloud.agent.api.guru;
import com.cloud.agent.api.CmdBuilder;
import com.cloud.agent.api.Command;
public class TrashNetworkVspCommand extends Command {
String _domainUuid;
String _networkUuid;
boolean _isL3Network;
String _vpcUuid;
private final String _domainUuid;
private final String _networkUuid;
private final boolean _isL3Network;
private final boolean _isSharedNetwork;
private final String _vpcUuid;
private final String _domainTemplateName;
public TrashNetworkVspCommand(String domainUuid, String networkUuid, boolean isL3Network, String vpcUuid) {
private TrashNetworkVspCommand(String domainUuid, String networkUuid, boolean isL3Network, boolean isSharedNetwork, String vpcUuid, String domainTemplateName) {
super();
this._domainUuid = domainUuid;
this._networkUuid = networkUuid;
this._isL3Network = isL3Network;
this._isSharedNetwork = isSharedNetwork;
this._vpcUuid = vpcUuid;
this._domainTemplateName = domainTemplateName;
}
public String getDomainUuid() {
@ -48,13 +53,95 @@ public class TrashNetworkVspCommand extends Command {
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);
}
}
@Override
public boolean executeInSequence() {
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof TrashNetworkVspCommand)) return false;
if (!super.equals(o)) return false;
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;
return true;
}
@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);
return result;
}
}

View File

@ -0,0 +1,81 @@
//
// 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

@ -17,19 +17,22 @@
// under the License.
//
package com.cloud.agent.api.guru;
package com.cloud.agent.api.manager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
public class ImplementNetworkVspAnswer extends Answer {
/**
* 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 ImplementNetworkVspAnswer(Command command, Exception e) {
super(command, e);
public GetClientDefaultsCommand() {
super();
}
public ImplementNetworkVspAnswer(ImplementNetworkVspCommand cmd, boolean success, String details) {
super(cmd, success, details);
@Override
public boolean executeInSequence() {
return false;
}
}

View File

@ -0,0 +1,61 @@
//
// 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.Command;
public class SupportedApiVersionCommand extends Command {
private final String _apiVersion;
public SupportedApiVersionCommand(String apiVersion) {
super();
this._apiVersion = apiVersion;
}
public String getApiVersion() {
return _apiVersion;
}
@Override
public boolean executeInSequence() {
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SupportedApiVersionCommand)) return false;
if (!super.equals(o)) return false;
SupportedApiVersionCommand that = (SupportedApiVersionCommand) o;
if (_apiVersion != null ? !_apiVersion.equals(that._apiVersion) : that._apiVersion != null) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_apiVersion != null ? _apiVersion.hashCode() : 0);
return result;
}
}

View File

@ -17,38 +17,41 @@
// under the License.
//
package com.cloud.agent.api.guru;
package com.cloud.agent.api.sync;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.Answer;
public class ReleaseVmVspCommand extends Command {
public class SyncDomainAnswer extends Answer {
String _networkUuid;
String _vmUuid;
String _vmInstanceName;
private final boolean _success;
public ReleaseVmVspCommand(String networkUuid, String vmUuid, String vmInstanceName) {
public SyncDomainAnswer(boolean success) {
super();
this._networkUuid = networkUuid;
this._vmUuid = vmUuid;
this._vmInstanceName = vmInstanceName;
this._success = success;
}
public String getNetworkUuid() {
return _networkUuid;
public boolean getSuccess() {
return _success;
}
public String getVmUuid() {
return _vmUuid;
}
public String getVmInstanceName() {
return _vmInstanceName;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SyncDomainAnswer)) return false;
if (!super.equals(o)) return false;
SyncDomainAnswer that = (SyncDomainAnswer) o;
if (_success != that._success) return false;
return true;
}
@Override
public boolean executeInSequence() {
return false;
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_success ? 1 : 0);
return result;
}
}

View File

@ -0,0 +1,93 @@
//
// 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.sync;
import com.cloud.agent.api.Command;
public class SyncDomainCommand extends Command {
private final String _domainUuid;
private final String _domainName;
private final String _domainPath;
private final boolean _toAdd;
private final boolean _toRemove;
public SyncDomainCommand(String domainUuid, String domainName, String domainPath, boolean toAdd, boolean toRemove) {
super();
this._domainUuid = domainUuid;
this._domainName = domainName;
this._domainPath = domainPath;
this._toAdd = toAdd;
this._toRemove = toRemove;
}
public String getDomainUuid() {
return _domainUuid;
}
public String getDomainName() {
return _domainName;
}
public String getDomainPath() {
return _domainPath;
}
public boolean isToAdd() {
return _toAdd;
}
public boolean isToRemove() {
return _toRemove;
}
@Override
public boolean executeInSequence() {
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SyncDomainCommand)) return false;
if (!super.equals(o)) return false;
SyncDomainCommand that = (SyncDomainCommand) o;
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;
return true;
}
@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 + (_toAdd ? 1 : 0);
result = 31 * result + (_toRemove ? 1 : 0);
return result;
}
}

View File

@ -0,0 +1,73 @@
//
// 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.sync;
import com.cloud.agent.api.Answer;
public class SyncNuageVspCmsIdAnswer extends Answer {
private final boolean _success;
private final String _nuageVspCmsId;
private final SyncNuageVspCmsIdCommand.SyncType _syncType;
public SyncNuageVspCmsIdAnswer(boolean success, String nuageVspCmsId, SyncNuageVspCmsIdCommand.SyncType syncType) {
super();
this._success = success;
this._nuageVspCmsId = nuageVspCmsId;
this._syncType = syncType;
}
public boolean getSuccess() {
return _success;
}
public String getNuageVspCmsId() {
return _nuageVspCmsId;
}
public SyncNuageVspCmsIdCommand.SyncType getSyncType() {
return _syncType;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SyncNuageVspCmsIdAnswer)) return false;
if (!super.equals(o)) return false;
SyncNuageVspCmsIdAnswer that = (SyncNuageVspCmsIdAnswer) o;
if (_success != that._success) return false;
if (_nuageVspCmsId != null ? !_nuageVspCmsId.equals(that._nuageVspCmsId) : that._nuageVspCmsId != null)
return false;
if (_syncType != that._syncType) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_success ? 1 : 0);
result = 31 * result + (_nuageVspCmsId != null ? _nuageVspCmsId.hashCode() : 0);
result = 31 * result + (_syncType != null ? _syncType.hashCode() : 0);
return result;
}
}

View File

@ -0,0 +1,72 @@
//
// 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.sync;
import com.cloud.agent.api.Command;
public class SyncNuageVspCmsIdCommand extends Command {
public static enum SyncType { AUDIT, AUDIT_ONLY, REGISTER, UNREGISTER }
private final SyncType _syncType;
private final String _nuageVspCmsId;
public SyncNuageVspCmsIdCommand(SyncType syncType, String nuageVspCmsId) {
super();
this._syncType = syncType;
this._nuageVspCmsId = nuageVspCmsId;
}
public SyncType getSyncType() {
return _syncType;
}
public String getNuageVspCmsId() {
return _nuageVspCmsId;
}
@Override
public boolean executeInSequence() {
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SyncNuageVspCmsIdCommand)) return false;
if (!super.equals(o)) return false;
SyncNuageVspCmsIdCommand that = (SyncNuageVspCmsIdCommand) o;
if (_nuageVspCmsId != null ? !_nuageVspCmsId.equals(that._nuageVspCmsId) : that._nuageVspCmsId != null)
return false;
if (_syncType != that._syncType) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_syncType != null ? _syncType.hashCode() : 0);
result = 31 * result + (_nuageVspCmsId != null ? _nuageVspCmsId.hashCode() : 0);
return result;
}
}

View File

@ -23,7 +23,7 @@ import com.cloud.agent.api.Command;
public class SyncVspCommand extends Command {
String _nuageVspEntity;
private final String _nuageVspEntity;
public SyncVspCommand(String nuageVspEntity) {
super();
@ -39,4 +39,24 @@ public class SyncVspCommand extends Command {
return _nuageVspEntity;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof SyncVspCommand)) return false;
if (!super.equals(o)) return false;
SyncVspCommand that = (SyncVspCommand) o;
if (_nuageVspEntity != null ? !_nuageVspEntity.equals(that._nuageVspEntity) : that._nuageVspEntity != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (_nuageVspEntity != null ? _nuageVspEntity.hashCode() : 0);
return result;
}
}

View File

@ -19,18 +19,6 @@
package com.cloud.api.commands;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
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.PhysicalNetworkResponse;
import org.apache.cloudstack.context.CallContext;
import com.cloud.api.response.NuageVspDeviceResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
@ -41,8 +29,19 @@ 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.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
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.PhysicalNetworkResponse;
import org.apache.cloudstack.context.CallContext;
@APICommand(name = "addNuageVspDevice", responseObject = NuageVspDeviceResponse.class, description = "Adds a Nuage VSP device")
import javax.inject.Inject;
@APICommand(name = "addNuageVspDevice", responseObject = NuageVspDeviceResponse.class, description = "Adds a Nuage VSP device", since = "4.5")
public class AddNuageVspDeviceCmd extends BaseAsyncCmd {
private static final String s_name = "addnuagevspdeviceresponse";

View File

@ -19,16 +19,6 @@
package com.cloud.api.commands;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.context.CallContext;
import com.cloud.api.response.NuageVspDeviceResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
@ -38,8 +28,17 @@ 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.api.APICommand;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.context.CallContext;
@APICommand(name = "deleteNuageVspDevice", responseObject = SuccessResponse.class, description = "delete a nuage vsp device")
import javax.inject.Inject;
@APICommand(name = "deleteNuageVspDevice", responseObject = SuccessResponse.class, description = "delete a nuage vsp device", since = "4.5")
public class DeleteNuageVspDeviceCmd extends BaseAsyncCmd {
private static final String s_name = "deletenuagevspdeviceresponse";
@Inject

View File

@ -19,23 +19,6 @@
package com.cloud.api.commands;
import java.util.List;
import javax.inject.Inject;
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 com.cloud.agent.AgentManager;
import com.cloud.agent.api.VspResourceAnswer;
import com.cloud.agent.api.VspResourceCommand;
@ -53,8 +36,23 @@ 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;
@APICommand(name = "issueNuageVspResourceRequest", responseObject = NuageVspResourceResponse.class, description = "Issues a Nuage VSP REST API resource request")
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";

View File

@ -19,20 +19,6 @@
package com.cloud.api.commands;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
import com.cloud.api.response.NuageVspDeviceResponse;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
@ -42,8 +28,20 @@ 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.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
@APICommand(name = "listNuageVspDevices", responseObject = NuageVspDeviceResponse.class, description = "Lists Nuage VSP devices")
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")
public class ListNuageVspDevicesCmd extends BaseListCmd {
private static final String s_name = "listnuagevspdeviceresponse";
@Inject

View File

@ -0,0 +1,180 @@
//
// 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.api.response.NuageVspDeviceResponse;
import com.cloud.event.EventTypes;
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.network.NuageVspDeviceVO;
import com.cloud.network.manager.NuageVspManager;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
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.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")
public class UpdateNuageVspDeviceCmd extends BaseAsyncCmd {
private static final Logger s_logger = Logger.getLogger(UpdateNuageVspDeviceCmd.class);
private static final String s_name = "updatenuagevspdeviceresponse";
@Inject
NuageVspManager _nuageVspManager;
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name = ApiConstants.PHYSICAL_NETWORK_ID, type = BaseCmd.CommandType.UUID, entityType = PhysicalNetworkResponse.class,
required = true, description = "the ID of the physical network in to which Nuage VSP is added")
private Long physicalNetworkId;
@Parameter(name = VspConstants.NUAGE_VSP_API_PORT, type = CommandType.INTEGER, description = "the port to communicate to Nuage VSD")
private Integer port;
@Parameter(name = ApiConstants.HOST_NAME, type = CommandType.STRING, description = "the hostname of the Nuage VSD")
private String hostName;
@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, description = "the user name of the CMS user in Nuage VSD")
private String userName;
@Parameter(name = ApiConstants.PASSWORD, type = CommandType.STRING, description = "the password of CMS user in Nuage VSD")
private String password;
@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, 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, description = "the time to wait after failure before retrying to communicate to Nuage VSD")
private Long apiRetryInterval;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getPhysicalNetworkId() {
return physicalNetworkId;
}
public Integer getPort() {
return port;
}
public void setPort(Integer port) {
this.port = port;
}
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
public String getUserName() {
return userName;
}
public String getPassword() {
return password;
}
public String getApiVersion() {
return apiVersion;
}
public void setApiVersion(String apiVersion) {
this.apiVersion = apiVersion;
}
public Integer getApiRetryCount() {
return apiRetryCount;
}
public void setApiRetryCount(Integer apiRetryCount) {
this.apiRetryCount = apiRetryCount;
}
public Long getApiRetryInterval() {
return apiRetryInterval;
}
public void setApiRetryInterval(Long apiRetryInterval) {
this.apiRetryInterval = apiRetryInterval;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
NuageVspDeviceVO nuageVspDeviceVO = _nuageVspManager.updateNuageVspDevice(this);
if (nuageVspDeviceVO != null) {
NuageVspDeviceResponse response = _nuageVspManager.createNuageVspDeviceResponse(nuageVspDeviceVO);
response.setObjectName("nuagevspdevice");
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Nuage VSP device due to internal error.");
}
} catch (InvalidParameterValueException invalidParamExcp) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccount().getId();
}
@Override
public String getEventType() {
return EventTypes.EVENT_EXTERNAL_VSP_VSD_UPDATE;
}
@Override
public String getEventDescription() {
return "Updating a Nuage VSD";
}
}

View File

@ -21,13 +21,12 @@ package com.cloud.api.response;
import com.cloud.api.commands.VspConstants;
import com.cloud.network.NuageVspDeviceVO;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@EntityReference(value = NuageVspDeviceVO.class)
public class NuageVspDeviceResponse extends BaseResponse {
@SerializedName(VspConstants.NUAGE_VSP_DEVICE_ID)

View File

@ -20,10 +20,9 @@
package com.cloud.api.response;
import com.cloud.api.commands.VspConstants;
import org.apache.cloudstack.api.BaseResponse;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.BaseResponse;
public class NuageVspResourceResponse extends BaseResponse {
@SerializedName(VspConstants.NUAGE_VSP_API_RESOURCE_INFO)

View File

@ -19,7 +19,7 @@
package com.cloud.network;
import java.util.UUID;
import org.apache.cloudstack.api.InternalIdentity;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -27,8 +27,7 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.apache.cloudstack.api.InternalIdentity;
import java.util.UUID;
@Entity
@Table(name = "external_nuage_vsp_devices")

View File

@ -33,4 +33,12 @@ public interface NuageVspDao extends GenericDao<NuageVspDeviceVO, Long> {
*/
List<NuageVspDeviceVO> listByPhysicalNetwork(long physicalNetworkId);
/**
* List all the Nuage Vsp devices by a specific host
*
* @param hostId host Id
* @return list of NuageVspDeviceVO for this host.
*/
List<NuageVspDeviceVO> listByHost(long hostId);
}

View File

@ -19,15 +19,13 @@
package com.cloud.network.dao;
import javax.ejb.Local;
import com.cloud.network.NuageVspDeviceVO;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import org.springframework.stereotype.Component;
import com.cloud.utils.db.GenericDaoBase;
import javax.ejb.Local;
import java.util.List;
@Component
@ -35,12 +33,17 @@ import java.util.List;
public class NuageVspDaoImpl extends GenericDaoBase<NuageVspDeviceVO, Long>
implements NuageVspDao {
protected final SearchBuilder<NuageVspDeviceVO> physicalNetworkIdSearch;
private final SearchBuilder<NuageVspDeviceVO> physicalNetworkIdSearch;
private final SearchBuilder<NuageVspDeviceVO> hostIdSearch;
public NuageVspDaoImpl() {
physicalNetworkIdSearch = createSearchBuilder();
physicalNetworkIdSearch.and("physicalNetworkId", physicalNetworkIdSearch.entity().getPhysicalNetworkId(), SearchCriteria.Op.EQ);
physicalNetworkIdSearch.done();
hostIdSearch = createSearchBuilder();
hostIdSearch.and("hostId", hostIdSearch.entity().getHostId(), SearchCriteria.Op.EQ);
hostIdSearch.done();
}
@Override
@ -49,4 +52,11 @@ public class NuageVspDaoImpl extends GenericDaoBase<NuageVspDeviceVO, Long>
sc.setParameters("physicalNetworkId", physicalNetworkId);
return search(sc, null);
}
@Override
public List<NuageVspDeviceVO> listByHost(long hostId) {
SearchCriteria<NuageVspDeviceVO> sc = hostIdSearch.create();
sc.setParameters("hostId", hostId);
return search(sc, null);
}
}

View File

@ -19,34 +19,20 @@
package com.cloud.network.element;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.api.InternalIdentity;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupVspCommand;
import com.cloud.agent.api.element.ApplyAclRuleVspAnswer;
import com.cloud.agent.api.element.ApplyAclRuleVspCommand;
import com.cloud.agent.api.element.ApplyStaticNatVspAnswer;
import com.cloud.agent.api.element.ApplyStaticNatVspCommand;
import com.cloud.agent.api.element.ImplementVspCommand;
import com.cloud.agent.api.element.ShutDownVpcVspCommand;
import com.cloud.dc.VlanVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.deploy.DeployDestination;
import com.cloud.domain.Domain;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.CloudException;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
@ -60,17 +46,28 @@ import com.cloud.network.Network.Service;
import com.cloud.network.NetworkModel;
import com.cloud.network.Networks;
import com.cloud.network.NuageVspDeviceVO;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.PublicIpAddress;
import com.cloud.network.dao.FirewallRulesCidrsDao;
import com.cloud.network.dao.FirewallRulesDao;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkServiceMapDao;
import com.cloud.network.dao.NuageVspDao;
import com.cloud.network.dao.PhysicalNetworkDao;
import com.cloud.network.dao.PhysicalNetworkVO;
import com.cloud.network.manager.NuageVspManager;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.FirewallRule.FirewallRuleType;
import com.cloud.network.rules.FirewallRuleVO;
import com.cloud.network.rules.StaticNat;
import com.cloud.network.vpc.NetworkACLItem;
import com.cloud.network.vpc.NetworkACLItemDao;
import com.cloud.network.vpc.NetworkACLItemVO;
import com.cloud.network.vpc.PrivateGateway;
import com.cloud.network.vpc.StaticRouteProfile;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.offering.NetworkOffering;
@ -81,17 +78,34 @@ 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.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.NicDao;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import org.apache.cloudstack.api.InternalIdentity;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager;
import org.apache.log4j.Logger;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@Local(value = {NetworkElement.class, ConnectivityProvider.class, IpDeployer.class, SourceNatServiceProvider.class, StaticNatServiceProvider.class, FirewallServiceProvider.class,
DhcpServiceProvider.class, NetworkACLServiceProvider.class})
DhcpServiceProvider.class, VpcProvider.class, NetworkACLServiceProvider.class})
public class NuageVspElement extends AdapterBase implements ConnectivityProvider, IpDeployer, SourceNatServiceProvider, StaticNatServiceProvider, FirewallServiceProvider,
DhcpServiceProvider, NetworkACLServiceProvider, ResourceStateAdapter {
DhcpServiceProvider, ResourceStateAdapter, VpcProvider, NetworkACLServiceProvider {
private static final Logger s_logger = Logger.getLogger(NuageVspElement.class);
@ -129,6 +143,18 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
AgentManager _agentMgr;
@Inject
NetworkOfferingDao _ntwkOfferingDao;
@Inject
ConfigurationDao _configDao;
@Inject
NuageVspManager _nuageVspManager;
@Inject
FirewallRulesDao _firewallRulesDao;
@Inject
FirewallRulesCidrsDao _firewallRulesCidrsDao;
@Inject
PhysicalNetworkDao _physicalNetworkDao;
@Inject
NetworkACLItemDao _networkACLItemDao;
@Override
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> service) throws ResourceUnavailableException {
@ -149,9 +175,12 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
// L3 Support : Generic
capabilities.put(Service.Gateway, null);
// Security Group
capabilities.put(Service.SecurityGroup, null);
// L3 Support : SourceNat
Map<Capability, String> sourceNatCapabilities = new HashMap<Capability, String>();
sourceNatCapabilities.put(Capability.SupportedSourceNatTypes, "peraccount");
sourceNatCapabilities.put(Capability.SupportedSourceNatTypes, "perzone");
sourceNatCapabilities.put(Capability.RedundantRouter, "false");
capabilities.put(Service.SourceNat, sourceNatCapabilities);
@ -194,7 +223,13 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Entering NuageElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")");
}
if (network.getVpcId() != null) {
return applyACLRulesForVpc(network, offering);
}
if (!canHandle(network, Service.Connectivity)) {
return false;
@ -205,9 +240,85 @@ 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);
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<IPAddressVO> ips = _ipAddressDao.listStaticNatPublicIps(network.getId());
List<String> acsFipUuid = new ArrayList<String>();
for (IPAddressVO ip : ips) {
acsFipUuid.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());
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())) {
throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
}
}
return true;
}
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);
}
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);
for (FirewallRuleVO rule : firewallRulesToApply) {
// load cidrs if any
rule.setSourceCidrList(_firewallRulesCidrsDao.getSourceCidrs(rule.getId()));
}
return Lists.transform(firewallRulesToApply, new Function<FirewallRuleVO, Map<String, Object>>() {
@Override
public Map<String, Object> apply(FirewallRuleVO firewallRuleVO) {
return getACLRuleDetails(firewallRuleVO, egressDefaultPolicy);
}
});
}
@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
@ -258,7 +369,7 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
@Override
public boolean canEnableIndividualServices() {
return false;
return true;
}
@Override
@ -303,13 +414,17 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
}
if (!_networkModel.isProviderForNetwork(getProvider(), network.getId())) {
s_logger.debug("NuageElement is not a provider for network " + network.getDisplayText());
if (s_logger.isDebugEnabled()) {
s_logger.debug("NuageVsp is not a provider for network " + network.getDisplayText());
}
return false;
}
if (service != null) {
if (!_ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(), service, getProvider())) {
s_logger.debug("NuageElement can't provide the " + service.getName() + " service on network " + network.getDisplayText());
if (s_logger.isDebugEnabled()) {
s_logger.debug("NuageVsp can't provide the " + service.getName() + " service on network " + network.getDisplayText());
}
return false;
}
}
@ -360,6 +475,7 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
//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());
@ -367,23 +483,22 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
sourceNatDetail.put("sourceNatVlanNetmask", sourceNatVan.getVlanNetmask());
sourceNatDetails.add(sourceNatDetail);
}
try {
try {
HostVO nuageVspHost = getNuageVspHost(config.getPhysicalNetworkId());
ApplyStaticNatVspCommand cmd = new ApplyStaticNatVspCommand(networkDomain.getUuid(), vpcOrSubnetUuid, isL3Network, sourceNatDetails);
ApplyStaticNatVspAnswer answer = (ApplyStaticNatVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
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());
if (answer == null || !answer.getResult()) {
s_logger.error("ApplyStaticNatNuageVspCommand for network " + config.getUuid() + " failed");
s_logger.error("ApplyStaticNatNuageVspCommand for network " + config.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
throw new ResourceUnavailableException(answer.getDetails(), Network.class, config.getId());
}
}
} catch (Exception e) {
s_logger.warn("Failed to apply static Nat in Vsp " + e.getMessage());
}
} catch (Exception e) {
throw new ResourceUnavailableException("Failed to apply Static NAT in VSP", Network.class, config.getId(), e);
}
return true;
}
@ -395,32 +510,25 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
@Override
public boolean applyFWRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
s_logger.debug("Handling applyFWRules for network " + network.getName() + " with " + rules.size() + " FWRules");
if (rules != null && rules.size() == 1 && rules.iterator().next().getType().equals(FirewallRuleType.System)) {
s_logger.debug("Default ACL added by CS as system is ignored for network " + network.getName() + " with rule " + rules);
return true;
}
return applyACLRules(network, rules, false);
}
@Override
public boolean applyNetworkACLs(Network network, List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
if (rules == null || rules.isEmpty()) {
s_logger.debug("No rules to apply. So, delete all the existing ACL in VSP from Subnet with uuid " + network.getUuid());
} else {
s_logger.debug("New rules has to applied. So, delete all the existing ACL in VSP from Subnet with uuid " + network.getUuid());
return true;
}
if (rules != null) {
s_logger.debug("Handling applyNetworkACLs for network " + network.getName() + " with " + rules.size() + " Network ACLs");
applyACLRules(network, rules, true);
if (rules.size() == 1 && rules.iterator().next().getType().equals(FirewallRuleType.System)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Default ACL added by CS as system is ignored for network " + network.getName() + " with rule " + rules);
}
return true;
}
protected boolean applyACLRules(Network network, List<? extends InternalIdentity> rules, boolean isVpc) throws ResourceUnavailableException {
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);
}
protected boolean applyACLRules(Network network, List<? extends InternalIdentity> rules, boolean isNetworkAcl, Boolean isAcsIngressAcl, boolean networkReset)
throws ResourceUnavailableException {
Domain networksDomain = _domainDao.findById(network.getDomainId());
NetworkOfferingVO networkOferringVO = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
try {
NetworkOfferingVO networkOfferingVO = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
Long vpcId = network.getVpcId();
String vpcOrSubnetUuid = null;
if (vpcId != null) {
@ -429,30 +537,114 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
} else {
vpcOrSubnetUuid = network.getUuid();
}
boolean egressDefaultPolicy = networkOferringVO.getEgressDefaultPolicy();
boolean egressDefaultPolicy = networkOfferingVO.getEgressDefaultPolicy();
List<Map<String, Object>> aclRules = new ArrayList<Map<String, Object>>();
for (InternalIdentity acl : rules) {
aclRules.add(getACLRuleDetails(acl, egressDefaultPolicy));
}
boolean isL3Network = isL3Network(network.getNetworkOfferingId());
HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
ApplyAclRuleVspCommand cmd = new ApplyAclRuleVspCommand(network.getUuid(), networksDomain.getUuid(), vpcOrSubnetUuid, isL3Network(networkOferringVO.getId()), aclRules,
isVpc, network.getId());
ApplyAclRuleVspAnswer answer = (ApplyAclRuleVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
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());
if (answer == null || !answer.getResult()) {
s_logger.error("ApplyAclRuleNuageVspCommand for network " + network.getUuid() + " failed");
s_logger.error("ApplyAclRuleNuageVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
}
}
} catch (Exception e1) {
throw new ResourceUnavailableException(e1.getMessage(), Network.class, network.getId());
return true;
}
@Override
public boolean applyNetworkACLs(Network config, List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
if (rules == null || rules.isEmpty()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No rules to apply. So, delete all the existing ACL in VSP from Subnet with uuid " + config.getUuid());
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("New rules has to applied. So, delete all the existing ACL in VSP from Subnet with uuid " + config.getUuid());
}
}
if (rules != null) {
s_logger.info("Applying " + rules.size() + " Network ACLs for network " + config.getName());
applyACLRules(config, rules, true, null, rules.isEmpty());
}
return true;
}
@Override
public boolean implementVpc(Vpc vpc, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
return true;
}
@Override
public boolean shutdownVpc(Vpc vpc, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
if (vpc.getState().equals(Vpc.State.Inactive)) {
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());
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())) {
throw new ResourceUnavailableException(answer.getDetails(), Vpc.class, vpc.getId());
}
}
}
return true;
}
private Long getPhysicalNetworkId(Long zoneId) {
Long guestPhysicalNetworkId = 0L;
List<PhysicalNetworkVO> physicalNetworkList = _physicalNetworkDao.listByZone(zoneId);
for (PhysicalNetworkVO phyNtwk : physicalNetworkList) {
if (phyNtwk.getIsolationMethods().contains(PhysicalNetwork.IsolationMethod.VSP.name())) {
guestPhysicalNetworkId = phyNtwk.getId();
break;
}
}
return guestPhysicalNetworkId;
}
@Override
public boolean createPrivateGateway(PrivateGateway gateway) throws ConcurrentOperationException, ResourceUnavailableException {
return false;
}
@Override
public boolean deletePrivateGateway(PrivateGateway privateGateway) throws ConcurrentOperationException, ResourceUnavailableException {
return false;
}
@Override
public boolean applyStaticRoutes(Vpc vpc, List<StaticRouteProfile> routes) throws ResourceUnavailableException {
return true;
}
@Override
public boolean applyACLItemsToPrivateGw(PrivateGateway gateway, List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
return false;
}
@Override
public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
return null;
@ -475,7 +667,7 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
return new DeleteHostAnswer(true);
}
protected HostVO getNuageVspHost(Long physicalNetworkId) throws CloudException {
private HostVO getNuageVspHost(Long physicalNetworkId) {
HostVO nuageVspHost;
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
if (nuageVspDevices != null && (!nuageVspDevices.isEmpty())) {
@ -483,7 +675,7 @@ public class NuageVspElement extends AdapterBase implements ConnectivityProvider
nuageVspHost = _hostDao.findById(config.getHostId());
_hostDao.loadDetails(nuageVspHost);
} else {
throw new CloudException("Nuage VSD is not configured on physical network " + physicalNetworkId);
throw new CloudRuntimeException("There is no Nuage VSP device configured on physical network " + physicalNetworkId);
}
return nuageVspHost;
}

View File

@ -19,42 +19,26 @@
package com.cloud.network.guru;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ejb.Local;
import javax.inject.Inject;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.guru.DeallocateVmVspAnswer;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.guru.DeallocateVmVspCommand;
import com.cloud.agent.api.guru.ImplementNetworkVspAnswer;
import com.cloud.agent.api.guru.ImplementNetworkVspCommand;
import com.cloud.agent.api.guru.ReleaseVmVspAnswer;
import com.cloud.agent.api.guru.ReleaseVmVspCommand;
import com.cloud.agent.api.guru.ReserveVmInterfaceVspAnswer;
import com.cloud.agent.api.guru.ReserveVmInterfaceVspCommand;
import com.cloud.agent.api.guru.TrashNetworkVspAnswer;
import com.cloud.agent.api.guru.TrashNetworkVspCommand;
import com.cloud.dc.DataCenter;
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;
@ -64,9 +48,11 @@ import com.cloud.network.Networks;
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.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;
@ -75,13 +61,29 @@ 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.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 org.apache.log4j.Logger;
import javax.ejb.Local;
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;
@Local(value = NetworkGuru.class)
public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
@ -103,6 +105,8 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
VpcDao _vpcDao;
@Inject
AgentManager _agentMgr;
@Inject
NuageVspManager _nuageVspManager;
public NuageVspGuestNetworkGuru() {
super();
@ -114,7 +118,9 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
if (!canHandle(offering, dc.getNetworkType(), physnet)) {
s_logger.debug("Refusing to design this network");
if (s_logger.isDebugEnabled()) {
s_logger.debug("Refusing to design network using network offering " + offering.getId() + (physnet != null ? " on physical network " + physnet.getId() : ""));
}
return null;
}
@ -129,8 +135,17 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
long networkId = network.getId();
network = _networkDao.acquireInLockTable(network.getId(), 1200);
if (network == null) {
throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
}
assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
NetworkVO implemented = null;
try {
if (network.getState() != State.Implementing) {
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
@ -139,7 +154,7 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
if (physicalNetworkId == null) {
physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
}
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
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());
@ -147,8 +162,8 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
if (network.getCidr() != null) {
implemented.setCidr(network.getCidr());
}
Collection<String> ipAddressRange = new ArrayList<String>();
String virtualRouterIp = getVirtualRouterIP(network, ipAddressRange);
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;
@ -162,33 +177,69 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
//Get the Account details and find the type
AccountVO networksAccount = _accountDao.findById(network.getAccountId());
if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
String errorMessage = "CS project support is not yet implemented in NuageVsp";
s_logger.debug(errorMessage);
String errorMessage = "Networks created by account " + networksAccount.getAccountName() + " of type Project (" + Account.ACCOUNT_TYPE_PROJECT + ") " +
"are not yet supported by NuageVsp provider";
s_logger.error(errorMessage);
throw new InsufficientVirtualNetworkCapacityException(errorMessage, Account.class, network.getAccountId());
}
boolean isL3Network = isL3Network(offering.getId());
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();
}
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);
}
}
HostVO nuageVspHost = getNuageVspHost(physicalNetworkId);
ImplementNetworkVspCommand cmd = new ImplementNetworkVspCommand(networksDomain.getName(), networksDomain.getPath(), networksDomain.getUuid(),
networksAccount.getAccountName(), networksAccount.getUuid(), network.getName(), network.getCidr(), network.getGateway(), network.getUuid(), isL3Network, vpcName,
vpcUuid, offering.getEgressDefaultPolicy(), ipAddressRange);
ImplementNetworkVspAnswer answer = (ImplementNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
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());
if (answer == null || !answer.getResult()) {
s_logger.error("ImplementNetworkNuageVspCommand failed");
s_logger.error("ImplementNetworkVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
s_logger.error(answer.getDetails());
}
return null;
}
s_logger.info("Implemented OK, network " + networkUuid + " in tenant " + tenantId + " linked to " + implemented.getBroadcastUri().toString());
s_logger.info("Implemented OK, network " + networkUuid + " in tenant " + tenantId + " linked to " + implemented.getBroadcastUri());
} finally {
_networkDao.releaseFromLockTable(network.getId());
}
return implemented;
}
@ -201,10 +252,17 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
boolean lockedNetwork = lockNetworkForUserVm(network, vm);
if (lockedNetwork && s_logger.isDebugEnabled()) {
s_logger.debug("Locked network " + network.getId() + " for creation of user VM " + vm.getInstanceName());
}
try {
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());
s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
DataCenter dc = _dcDao.findById(network.getDataCenterId());
Account networksAccount = _accountDao.findById(network.getAccountId());
DomainVO networksDomain = _domainDao.findById(network.getDomainId());
@ -212,14 +270,21 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
long networkOwnedBy = network.getAccountId();
AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
throw new InsufficientVirtualNetworkCapacityException("CS project support is " + "not yet implemented in NuageVsp", DataCenter.class, dc.getId());
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());
long networkOfferingId = _ntwkOfferingDao.findById(network.getNetworkOfferingId()).getId();
boolean isL3Network = isL3Network(networkOfferingId);
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("/")) {
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) {
@ -227,71 +292,91 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
vpcUuid = vpcObj.getUuid();
}
HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(nicFrmDB.getUuid(), nic.getMacAddress(), network.getUuid(), isL3Network, vpcUuid,
networksDomain.getUuid(), networksAccount.getUuid(), vm.getType().equals(VirtualMachine.Type.DomainRouter), network.getBroadcastUri().getPath().substring(1),
vm.getInstanceName(), vm.getUuid(), networksDomain.getUuid(), networksAccount.getUuid());
ReserveVmInterfaceVspAnswer answer = (ReserveVmInterfaceVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
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());
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());
}
Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
if (answer == null || !answer.getResult()) {
s_logger.error("ReserveVmInterfaceNuageVspCommand failed");
s_logger.error("ReserveVmInterfaceNuageVspCommand failed for NIC " + nic.getId() + " attached to VM " + vm.getId() + " in network " + network.getId());
if ((null != answer) && (null != answer.getDetails())) {
s_logger.error(answer.getDetails());
}
throw new InsufficientVirtualNetworkCapacityException("Failed to reserve VM in Nuage VSP.", Network.class, network.getId());
}
List<Map<String, String>> vmInterfacesDetails = answer.getInterfaceDetails();
setIPGatewayMaskInfo(network, nic, vmInterfacesDetails);
if (isDomainRouter) {
nic.setIPv4Address(domainRouterIp);
}
} finally {
if (network != null && lockedNetwork) {
_networkDao.releaseFromLockTable(network.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unlocked network " + network.getId() + " for creation of user VM " + vm.getInstanceName());
}
}
}
}
@Override
protected boolean canHandle(NetworkOffering offering, final NetworkType networkType, final PhysicalNetwork physicalNetwork) {
if (networkType == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && offering.getGuestType() == Network.GuestType.Isolated
if (networkType == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && (offering.getGuestType() == Network.GuestType.Isolated || offering.getGuestType() == Network.GuestType.Shared)
&& isMyIsolationMethod(physicalNetwork)) {
return true;
} else {
if (s_logger.isTraceEnabled()) {
s_logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced);
}
return false;
}
}
@Override
public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
long networkId = nic.getNetworkId();
Network network = _networkDao.findById(networkId);
s_logger.debug("Handling release() call back, which is called when a VM is stopped or destroyed, to delete the VM with state " + vm.getVirtualMachine().getState()
+ " from netork " + network.getName());
if (vm.getVirtualMachine().getState().equals(VirtualMachine.State.Stopping)) {
try {
HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
ReleaseVmVspCommand cmd = new ReleaseVmVspCommand(network.getUuid(), vm.getUuid(), vm.getInstanceName());
ReleaseVmVspAnswer answer = (ReleaseVmVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ReleaseVmNuageVspCommand for VM " + vm.getUuid() + " failed");
if ((null != answer) && (null != answer.getDetails())) {
s_logger.error(answer.getDetails());
}
}
} catch (InsufficientVirtualNetworkCapacityException e) {
s_logger.debug("Handling release() call back. Failed to delete CS VM " + vm.getInstanceName() + " in VSP. " + e.getMessage());
}
} else {
s_logger.debug("Handling release() call back. VM " + vm.getInstanceName() + " is in " + vm.getVirtualMachine().getState() + " state. So, the CS VM is not deleted."
+ " This could be a case where VM interface is deleted. deallocate() call back should be called later");
}
return super.release(nic, vm, reservationId);
}
@Override
@DB
public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) {
boolean lockedNetwork = lockNetworkForUserVm(network, vm);
if (lockedNetwork && s_logger.isDebugEnabled()) {
s_logger.debug("Locked network " + network.getId() + " for deallocation of user VM " + vm.getInstanceName());
}
try {
if (s_logger.isDebugEnabled()) {
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());
long networkOfferingId = _ntwkOfferingDao.findById(network.getNetworkOfferingId()).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) {
@ -299,22 +384,49 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
vpcUuid = vpcObj.getUuid();
}
HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
DeallocateVmVspCommand cmd = new DeallocateVmVspCommand(network.getUuid(), nicFrmDd.getUuid(), nic.getMacAddress(), nic.getIPv4Address(),
isL3Network(networkOfferingId), vpcUuid, networksDomain.getUuid(), vm.getInstanceName(), vm.getUuid());
DeallocateVmVspAnswer answer = (DeallocateVmVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
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());
if (answer == null || !answer.getResult()) {
s_logger.error("DeallocateVmNuageVspCommand for VM " + vm.getUuid() + " failed");
s_logger.error("DeallocateVmNuageVspCommand for VM " + vm.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
if ((null != answer) && (null != answer.getDetails())) {
s_logger.error(answer.getDetails());
}
}
} catch (InsufficientVirtualNetworkCapacityException e) {
s_logger.error("Handling deallocate(). VM " + vm.getInstanceName() + " with NIC IP " + nic.getIPv4Address()
+ " is getting destroyed. REST API failed to update the VM state in NuageVsp", e);
} finally {
if (network != null && lockedNetwork) {
_networkDao.releaseFromLockTable(network.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unlocked network " + network.getId() + " for deallocation of user VM " + vm.getInstanceName());
}
}
}
super.deallocate(network, nic, vm);
}
private boolean lockNetworkForUserVm(Network network, VirtualMachineProfile vm) {
if (!vm.getVirtualMachine().getType().isUsedBySystem()) {
long networkId = network.getId();
network = _networkDao.acquireInLockTable(network.getId(), 1200);
if (network == null) {
throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
}
return true;
}
return false;
}
@Override
public void shutdown(NetworkProfile profile, NetworkOffering offering) {
super.shutdown(profile, offering);
@ -322,55 +434,82 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
@Override
public boolean trash(Network network, NetworkOffering offering) {
long networkId = network.getId();
network = _networkDao.acquireInLockTable(networkId, 1200);
if (network == null) {
throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
}
try {
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();
}
try {
String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configDao, network, offering);
HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
TrashNetworkVspCommand cmd = new TrashNetworkVspCommand(domain.getUuid(), network.getUuid(), isL3Network(offering.getId()), vpcUuid);
TrashNetworkVspAnswer answer = (TrashNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
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());
if (answer == null || !answer.getResult()) {
s_logger.error("TrashNetworkNuageVspCommand for network " + network.getUuid() + " failed");
if ((null != answer) && (null != answer.getDetails())) {
s_logger.error(answer.getDetails());
}
return false;
}
} catch (Exception e) {
s_logger.warn("Failed to clean up network information in Vsp " + e.getMessage());
} finally {
_networkDao.releaseFromLockTable(network.getId());
}
return super.trash(network, offering);
}
private String getVirtualRouterIP(Network network, Collection<String> addressRange) throws InsufficientVirtualNetworkCapacityException {
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) {
s_logger.debug("Gateway of the Network(" + network.getUuid() + ") has the first IP " + NetUtils.long2Ip(vip));
vip = ipIterator.next();
virtualRouterIp = NetUtils.long2Ip(vip);
s_logger.debug("So, reserving the 2nd IP " + virtualRouterIp + " for the Virtual Router IP in Network(" + network.getUuid() + ")");
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);
s_logger.debug("1nd IP is not used as the gateway IP. So, reserving" + virtualRouterIp + " for the Virtual Router IP for " + "Network(" + network.getUuid() + ")");
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() + ")");
}
addressRange.add(NetUtils.long2Ip(ipIterator.next()));
addressRange.add(NetUtils.long2Ip((Long)allIPsInCidr.toArray()[allIPsInCidr.size() - 1]));
}
ipAddressRanges.add(new String[] {
NetUtils.long2Ip(ipIterator.next()),
NetUtils.getIpRangeEndIpFromCidr(subnet, cidrSize)
});
return virtualRouterIp;
}
@ -378,30 +517,13 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
network.getId());
}
private void setIPGatewayMaskInfo(Network network, NicProfile nic, List<Map<String, String>> vmInterfacesDetails) throws InsufficientVirtualNetworkCapacityException {
try {
for (Map<String, String> interfaces : vmInterfacesDetails) {
String macFromNuage = interfaces.get("mac");
if (StringUtils.equals(macFromNuage, nic.getMacAddress())) {
nic.setIPv4Address(interfaces.get("ip4Address"));
nic.setIPv4Gateway(interfaces.get("gateway"));
nic.setIPv4Netmask(interfaces.get("netmask"));
break;
}
}
} catch (Exception e) {
s_logger.error("Failed to parse the VM interface Json response from VSP REST API. VM interface json string is " + vmInterfacesDetails, e);
throw new InsufficientVirtualNetworkCapacityException("Failed to parse the VM interface Json response from VSP REST API. VM interface Json " + "string is "
+ vmInterfacesDetails + ". So. failed to get IP for the VM from VSP address for network " + network, 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 boolean isL3Network(Long offeringId) {
return _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offeringId, Service.SourceNat)
|| _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offeringId, Service.StaticNat);
}
private HostVO getNuageVspHost(long physicalNetworkId) throws InsufficientVirtualNetworkCapacityException {
private HostVO getNuageVspHost(long physicalNetworkId) {
HostVO nuageVspHost;
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
if (nuageVspDevices != null && (!nuageVspDevices.isEmpty())) {
@ -409,7 +531,7 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
nuageVspHost = _hostDao.findById(config.getHostId());
_hostDao.loadDetails(nuageVspHost);
} else {
throw new InsufficientVirtualNetworkCapacityException("Nuage VSD is not configured on physical network ", PhysicalNetwork.class, physicalNetworkId);
throw new CloudRuntimeException("There is no Nuage VSP device configured on physical network " + physicalNetworkId);
}
return nuageVspHost;
}

View File

@ -19,37 +19,66 @@
package com.cloud.network.manager;
import java.util.List;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
import com.cloud.api.commands.AddNuageVspDeviceCmd;
import com.cloud.api.commands.DeleteNuageVspDeviceCmd;
import com.cloud.api.commands.ListNuageVspDevicesCmd;
import com.cloud.api.commands.UpdateNuageVspDeviceCmd;
import com.cloud.api.response.NuageVspDeviceResponse;
import com.cloud.network.Network;
import com.cloud.network.NuageVspDeviceVO;
import com.cloud.utils.component.PluggableService;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
import java.util.List;
public interface NuageVspManager extends PluggableService {
static final String NUAGE_VPC_OFFERING_NAME = "Default VPC offering with NuageVsp";
static final String nuageVspSharedNetworkOfferingWithSGServiceName = "DefaultNuageVspSharedNetworkOfferingWithSGService";
static final String NUAGE_VPC_OFFERING_DISPLAY_TEXT = "Default VPC offering with NuageVsp";
static final String nuageVPCOfferingName = "Nuage VSP VPC Offering";
static final ConfigKey<Integer> NuageVspSyncInterval = new ConfigKey<Integer>(Integer.class, "nuagevsp.sync.interval", "Advanced", "480",
"The interval (in minutes) to wait before running the next synchronization worker to synchronize the information between CloudStack and NuageVsp", false, Scope.Global,
1);
static final String nuageVPCOfferingDisplayText = "Nuage VSP VPC Offering";
static final ConfigKey<Integer> NuageVspSyncWorkers = new ConfigKey<Integer>(Integer.class, "nuagevsp.sync.workers", "Advanced", "1",
"Number of workers to synchronize the information between CloudStack and NuageVsp", false, Scope.Global, 1);
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);
static final ConfigKey<Boolean> NuageVspDnsExternal = new ConfigKey<Boolean>(
Boolean.class,
"nuagevsp.dns.external",
"Advanced",
"true",
"Defines if NuageVsp plugin needs to configure either internal or external DNS server configured during Zone provisioning. "
+ "Value true uses the external DNS and value false uses the internal DNS to configure in the VM. But, this flag depends on "
+ "nuagevsp.configure.dns. Only if nuagevsp.configure.dns is set to true, DNS server will be configured in the VM. "
+ "If nuagevsp.configure.dns is false, DNS server will not be configured in the VM. Default value for this flag is true",
true, Scope.Global, null);
static final ConfigKey<String> NuageVspConfigGateway = new ConfigKey<String>(String.class, "nuagevsp.configure.gateway.systemid", "Advanced", "",
"Defines the systemID of the gateway configured in VSP", true, Scope.Global, null);
static final ConfigKey<String> NuageVspSharedNetworkDomainTemplateName = new ConfigKey<String>(String.class, "nuagevsp.sharedntwk.domaintemplate.name",
"Advanced", "", "Defines if NuageVsp plugin needs to use pre created Domain Template configured in VSP for shared networks", true, Scope.Global, null);
static final ConfigKey<String> NuageVspVpcDomainTemplateName = new ConfigKey<String>(String.class, "nuagevsp.vpc.domaintemplate.name",
"Advanced", "", "Defines if NuageVsp plugin needs to use pre created Domain Template configured in VSP for VPCs", true, Scope.Global, null);
static final ConfigKey<String> NuageVspIsolatedNetworkDomainTemplateName = new ConfigKey<String>(String.class, "nuagevsp.isolatedntwk.domaintemplate.name",
"Advanced", "", "Defines if NuageVsp plugin needs to use pre created Domain Template configured in VSP for isolated networks", true, Scope.Global, null);
NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd);
NuageVspDeviceVO updateNuageVspDevice(UpdateNuageVspDeviceCmd cmd);
NuageVspDeviceResponse createNuageVspDeviceResponse(NuageVspDeviceVO nuageVspDeviceVO);
boolean deleteNuageVspDevice(DeleteNuageVspDeviceCmd cmd);
List<NuageVspDeviceVO> listNuageVspDevices(ListNuageVspDevicesCmd cmd);
List<String> getDnsDetails(Network network);
List<String> getGatewaySystemIds();
}

View File

@ -19,45 +19,49 @@
package com.cloud.network.manager;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager;
import com.cloud.agent.Listener;
import com.cloud.agent.api.AgentControlAnswer;
import com.cloud.agent.api.AgentControlCommand;
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.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.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;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.ConnectionException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.host.DetailVO;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao;
import com.cloud.network.Network;
import com.cloud.network.NetworkModel;
import com.cloud.network.Networks;
import com.cloud.network.NuageVspDeviceVO;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.dao.FirewallRulesDao;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.NuageVspDao;
@ -67,25 +71,79 @@ 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;
import com.cloud.network.vpc.VpcOfferingVO;
import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.network.vpc.dao.VpcOfferingDao;
import com.cloud.network.vpc.dao.VpcOfferingServiceMapDao;
import com.cloud.network.vpc.dao.VpcServiceMapDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingServiceMapVO;
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.ResourceState;
import com.cloud.resource.ServerResource;
import com.cloud.user.AccountManager;
import com.cloud.user.DomainManager;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.db.TransactionCallback;
import com.cloud.utils.db.TransactionCallbackNoReturn;
import com.cloud.utils.db.TransactionStatus;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.fsm.StateListener;
import com.cloud.utils.fsm.StateMachine2;
import com.google.common.base.Joiner;
import com.google.common.base.MoreObjects;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.nuage.vsp.acs.NuageVspPluginClientLoader;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import org.apache.cloudstack.framework.messagebus.MessageBus;
import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.collections.CollectionUtils;
import org.apache.log4j.Logger;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
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;
@Local(value = {NuageVspManager.class})
public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager, Configurable {
public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager, Configurable, StateListener<Status, Status.Event, Host> {
private static final Logger s_logger = Logger.getLogger(NuageVspManagerImpl.class);
private static final int ONE_MINUTE_MULTIPLIER = 60 * 1000;
private static final Set<Network.Provider> NUAGE_VSP_PROVIDERS;
private 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 };
@Inject
ResourceManager _resourceMgr;
@Inject
@ -97,10 +155,6 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
@Inject
PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao;
@Inject
ConfigurationDao _configDao;
@Inject
NuageVspDao _nuageVspDao;
@Inject
NetworkDao _networkDao;
@Inject
VpcOfferingDao _vpcOffDao;
@ -109,26 +163,59 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
@Inject
VpcDao _vpcDao;
@Inject
NuageVspDao nuageVspDao;
VpcManager _vpcManager;
@Inject
NuageVspSync nuageVspSync;
NuageVspDao _nuageVspDao;
@Inject
NuageVspSync _nuageVspSync;
@Inject
DataCenterDao _dataCenterDao;
@Inject
ConfigurationDao _configDao;
@Inject
NetworkModel _ntwkModel;
@Inject
AccountManager _accountMgr;
@Inject
IPAddressDao _ipAddressDao;
@Inject
FirewallRulesDao _firewallDao;
@Inject
VpcServiceMapDao _vpcSrvcDao;
@Inject
AgentManager _agentMgr;
@Inject
private DomainDao _domainDao;
@Inject
NetworkOfferingDao _networkOfferingDao;
@Inject
NetworkOfferingServiceMapDao _networkOfferingServiceMapDao;
private ScheduledExecutorService scheduler;
@Inject
MessageBus _messageBus;
static {
NUAGE_VSP_PROVIDERS = ImmutableSet.of(Network.Provider.NuageVsp);
NUAGE_VSP_VPC_SERVICE_MAP = ImmutableMap.<Network.Service, Set<Network.Provider>>builder()
.put(Network.Service.Connectivity, NUAGE_VSP_PROVIDERS)
.put(Network.Service.Dhcp, NUAGE_VSP_PROVIDERS)
.put(Network.Service.StaticNat, NUAGE_VSP_PROVIDERS)
.put(Network.Service.SourceNat, NUAGE_VSP_PROVIDERS)
.put(Network.Service.NetworkACL, NUAGE_VSP_PROVIDERS)
.build();
}
@Override
public List<Class<?>> getCommands() {
List<Class<?>> cmdList = new ArrayList<Class<?>>();
cmdList.add(AddNuageVspDeviceCmd.class);
cmdList.add(DeleteNuageVspDeviceCmd.class);
cmdList.add(ListNuageVspDevicesCmd.class);
cmdList.add(IssueNuageVspResourceRequestCmd.class);
return cmdList;
return Lists.<Class<?>>newArrayList(AddNuageVspDeviceCmd.class, DeleteNuageVspDeviceCmd.class, ListNuageVspDevicesCmd.class,
IssueNuageVspResourceRequestCmd.class, UpdateNuageVspDeviceCmd.class);
}
@Override
public NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd) {
ServerResource resource = new NuageVspResource();
final NuageVspResource resource = new NuageVspResource();
final String deviceName = Network.Provider.NuageVsp.getName();
ExternalNetworkDeviceManager.NetworkDevice networkDevice = ExternalNetworkDeviceManager.NetworkDevice.getNetworkDevice(deviceName);
final Long physicalNetworkId = cmd.getPhysicalNetworkId();
@ -141,8 +228,8 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(),
networkDevice.getNetworkServiceProvder());
if (ntwkSvcProvider == null) {
throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not added in the physical network: " + physicalNetworkId
+ "to add this device");
throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: "
+ physicalNetworkId + "to add this device");
} else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: "
+ physicalNetworkId + "to add this device");
@ -152,50 +239,186 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
}
Map<String, String> params = new HashMap<String, String>();
params.put("guid", UUID.randomUUID().toString());
params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
params.put("name", "Nuage VSD - " + cmd.getHostName());
params.put("hostname", cmd.getHostName());
params.put("cmsuser", cmd.getUserName());
String cmsUserPasswordBase64 = org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.encodeBase64(cmd.getPassword().getBytes(Charset.forName("UTF-8"))));
params.put("cmsuserpass", cmsUserPasswordBase64);
try {
NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(null, null, 1, 1, null);
Map<String, Object> clientDefaults = clientLoader.getNuageVspManagerClient().getClientDefaults();
String apiVersion = MoreObjects.firstNonNull(cmd.getApiVersion(), (String) clientDefaults.get("CURRENT_API_VERSION"));
if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(apiVersion)) {
throw new CloudRuntimeException("Unsupported API version : " + apiVersion);
}
int port = cmd.getPort();
if (0 == port) {
port = 443;
port = 8443;
}
params.put("port", String.valueOf(port));
params.put("apirelativepath", "/nuage/api/" + cmd.getApiVersion());
params.put("retrycount", String.valueOf(cmd.getApiRetryCount()));
params.put("retryinterval", String.valueOf(cmd.getApiRetryInterval()));
String cmsUserPasswordBase64 = org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.encodeBase64(cmd.getPassword().getBytes()));
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")));
NuageVspResource.Configuration resourceConfiguration = new NuageVspResource.Configuration()
.name("Nuage VSD - " + cmd.getHostName())
.guid(UUID.randomUUID().toString())
.zoneId(String.valueOf(physicalNetwork.getDataCenterId()))
.hostName(cmd.getHostName())
.cmsUser(cmd.getUserName())
.cmsUserPassword(cmsUserPasswordBase64)
.port(String.valueOf(port))
.apiVersion(apiVersion)
.apiRelativePath("/nuage/api/" + apiVersion)
.retryCount(retryCount)
.retryInterval(retryInterval);
Map<String, Object> hostdetails = new HashMap<String, Object>();
hostdetails.putAll(params);
Map<String, String> hostDetails = resourceConfiguration.build();
resource.configure(cmd.getHostName(), Maps.<String, Object>newHashMap(hostDetails));
Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, hostDetails);
if (host == null) {
throw new CloudRuntimeException("Failed to add Nuage Vsp Device due to internal error.");
}
try {
resource.configure(cmd.getHostName(), hostdetails);
final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params);
if (host != null) {
return Transaction.execute(new TransactionCallback<NuageVspDeviceVO>() {
@Override
public NuageVspDeviceVO doInTransaction(TransactionStatus status) {
NuageVspDeviceVO nuageVspDevice = new NuageVspDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
_nuageVspDao.persist(nuageVspDevice);
DetailVO detail = new DetailVO(host.getId(), "nuagevspdeviceid", String.valueOf(nuageVspDevice.getId()));
_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);
} else {
throw new CloudRuntimeException("Failed to register CMS ID");
}
return nuageVspDevice;
} catch (ConfigurationException e) {
s_logger.error("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
throw new CloudRuntimeException("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
} catch (ExecutionException ee) {
s_logger.error("Failed to add Nuage VSP device " + cmd.getHostName(), ee);
throw new CloudRuntimeException("Failed to add Nuage VSP device " + cmd.getHostName(), ee);
}
}
@Override
public NuageVspDeviceVO updateNuageVspDevice(UpdateNuageVspDeviceCmd command) {
NuageVspResource resource = new NuageVspResource();
final String deviceName = Network.Provider.NuageVsp.getName();
ExternalNetworkDeviceManager.NetworkDevice networkDevice = ExternalNetworkDeviceManager.NetworkDevice.getNetworkDevice(deviceName);
final Long physicalNetworkId = command.getPhysicalNetworkId();
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
if (physicalNetwork == null) {
throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
}
final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(),
networkDevice.getNetworkServiceProvder());
if (ntwkSvcProvider == null) {
throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: "
+ physicalNetworkId + "to add this device");
}
if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: "
+ physicalNetworkId + "to add this device");
}
HostVO nuageVspHost = null;
NuageVspDeviceVO nuageVspDevice = null;
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
if (nuageVspDevices == null || nuageVspDevices.isEmpty()) {
throw new CloudRuntimeException("Nuage VSD is not configured on physical network " + physicalNetworkId);
} else {
nuageVspDevice = nuageVspDevices.iterator().next();
nuageVspHost = _hostDao.findById(nuageVspDevice.getHostId());
_hostDao.loadDetails(nuageVspHost);
}
boolean updateRequired = false;
NuageVspResource.Configuration resourceConfiguration = NuageVspResource.Configuration.fromConfiguration(nuageVspHost.getDetails());
if (!Strings.isNullOrEmpty(command.getHostName()) &&
!command.getHostName().equals(resourceConfiguration.hostName())) {
resourceConfiguration.name("Nuage VSD - " + command.getHostName());
resourceConfiguration.hostName(command.getHostName());
updateRequired = true;
}
if (!Strings.isNullOrEmpty(command.getUserName()) &&
!command.getUserName().equals(resourceConfiguration.cmsUser())) {
resourceConfiguration.cmsUser(command.getUserName());
updateRequired = true;
}
if (!Strings.isNullOrEmpty(command.getPassword())) {
String encodedNewPassword = org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.encodeBase64(command.getPassword().getBytes()));
if (!encodedNewPassword.equals(resourceConfiguration.cmsUserPassword())) {
resourceConfiguration.cmsUserPassword(encodedNewPassword);
updateRequired = true;
}
}
if (command.getPort() != null &&
command.getPort() != Integer.parseInt(resourceConfiguration.port())) {
resourceConfiguration.port(String.valueOf(command.getPort()));
updateRequired = true;
}
GetClientDefaultsCommand getClientDefaultsCmd = new GetClientDefaultsCommand();
GetClientDefaultsAnswer getClientDefaultsAnswer = (GetClientDefaultsAnswer) _agentMgr.easySend(nuageVspHost.getId(), getClientDefaultsCmd);
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());
}
String apiRelativePath = "/nuage/api/" + apiVersion;
if (!apiRelativePath.equals(resourceConfiguration.apiRelativePath())) {
resourceConfiguration.apiVersion(apiVersion);
resourceConfiguration.apiRelativePath(apiRelativePath);
updateRequired = true;
}
if (command.getApiRetryCount() != null && resourceConfiguration.retryCount() != null) {
final int retryCount = Integer.parseInt(resourceConfiguration.retryCount());
if (command.getApiRetryCount() != retryCount) {
resourceConfiguration.retryCount(String.valueOf(command.getApiRetryCount()));
updateRequired = true;
}
}
if (command.getApiRetryInterval() != null && resourceConfiguration.retryInterval() != null) {
final int apiRetryInterval = Integer.parseInt(resourceConfiguration.retryInterval());
if (command.getApiRetryInterval() != apiRetryInterval) {
resourceConfiguration.retryInterval(String.valueOf(command.getApiRetryInterval()));
updateRequired = true;
}
}
if (!updateRequired) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No change in the NuageVsp device parameters. None of the NuageVsp device parameters are modified");
}
return nuageVspDevice;
}
});
} else {
throw new CloudRuntimeException("Failed to add Nuage Vsp Device due to internal error.");
}
Map<String, String> config = resourceConfiguration.build();
String updateParameters = "{" + Joiner.on(", ").withKeyValueSeparator(": ").join(config) + "}";
Map<String, Object> hostDetails = Maps.<String, Object>newHashMap(config);
try {
resource.configure(resourceConfiguration.hostName(), hostDetails);
_hostDetailsDao.persist(nuageVspDevice.getHostId(), config);
} catch (ConfigurationException e) {
throw new CloudRuntimeException(e.getMessage());
throw new CloudRuntimeException("Failed to update Nuage VSP device " + nuageVspDevice.getId() + " with parameters " + updateParameters, e);
}
return nuageVspDevice;
}
@Override
@ -234,7 +457,7 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
if (physicalNetwork != null) {
// Lets see if there are networks that use us
// Find the NuageVsp on this physical network
// Find the nuage networks on this physical network
List<NetworkVO> networkList = _networkDao.listByPhysicalNetwork(physicalNetworkId);
// Networks with broadcast type lswitch are ours
@ -247,6 +470,26 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
}
}
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);
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;
}
HostVO nuageHost = _hostDao.findById(nuageVspDevice.getHostId());
Long hostId = nuageHost.getId();
@ -285,60 +528,331 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
return responseList;
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
try {
initNuageScheduledTasks();
} catch (Exception ce) {
s_logger.warn("Failed to load NuageVsp configuration properties. Check if the NuageVsp properties are configured correctly");
private void registerNewNuageVspDevice(ConfigurationVO currentConfig, String registeredNuageVspDevice) {
if (currentConfig == null) {
ConfigKey<String> configKey = new ConfigKey<String>("Advanced", String.class, "nuagevsp.cms.id", registeredNuageVspDevice,
"<ACS Nuage VSP Device ID>:<Allocated VSD CMS ID> - Do not edit", false);
ConfigurationVO configuration = new ConfigurationVO("management-server", configKey);
_configDao.persist(configuration);
} else {
String newValue;
String currentValue = currentConfig.getValue();
if (!Strings.isNullOrEmpty(currentValue)) {
newValue = currentValue + ";" + registeredNuageVspDevice;
} else {
newValue = registeredNuageVspDevice;
}
_configDao.update("nuagevsp.cms.id", newValue);
}
}
private void auditHost(HostVO host) {
_hostDao.loadDetails(host);
boolean validateDomains = true;
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByHost(host.getId());
if (!CollectionUtils.isEmpty(nuageVspDevices)) {
for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
ConfigurationVO cmsIdConfig = _configDao.findByName("nuagevsp.cms.id");
String nuageVspCmsId = findNuageVspCmsIdForDevice(nuageVspDevice.getId(), cmsIdConfig);
SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.AUDIT, nuageVspCmsId);
SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
if (answer != null && !answer.getSuccess()) {
s_logger.error("Nuage VSP Device with ID " + nuageVspDevice.getId() + " is configured with an unknown CMS ID!");
validateDomains = false;
} else if (answer != null && answer.getSyncType() == SyncType.REGISTER) {
registerNewNuageVspDevice(cmsIdConfig, nuageVspDevice.getId() + ":" + answer.getNuageVspCmsId());
}
}
}
if (validateDomains) {
auditDomainsOnVsp(host, true, false);
}
}
private boolean auditDomainsOnVsp(HostVO host, boolean add, boolean remove) {
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByHost(host.getId());
if (CollectionUtils.isEmpty(nuageVspDevices)) {
return true;
}
_hostDao.loadDetails(host);
List<DomainVO> allDomains = _domainDao.listAll();
for (DomainVO domain : allDomains) {
SyncDomainCommand cmd = new SyncDomainCommand(domain.getUuid(), domain.getName(), domain.getPath(), add, remove);
SyncDomainAnswer answer = (SyncDomainAnswer) _agentMgr.easySend(host.getId(), cmd);
return answer.getSuccess();
}
return true;
}
private void initNuageScheduledTasks() {
Integer numOfSyncThreads = Integer.valueOf(_configDao.getValue(NuageVspManager.NuageVspSyncWorkers.key()));
Integer syncUpIntervalInMinutes = Integer.valueOf(_configDao.getValue(NuageVspManager.NuageVspSyncInterval.key()));
if (numOfSyncThreads != null && syncUpIntervalInMinutes != null) {
ThreadFactory threadFactory = new ThreadFactory() {
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable, "Nuage Vsp sync task");
if (thread.isDaemon())
thread.setDaemon(false);
if (thread.getPriority() != Thread.NORM_PRIORITY)
thread.setPriority(Thread.NORM_PRIORITY);
return thread;
private String findNuageVspCmsIdForDevice(long deviceId, ConfigurationVO cmsIdConfig) {
String configValue = cmsIdConfig.getValue();
if (!Strings.isNullOrEmpty(configValue)) {
String[] configuredNuageVspDevices = configValue.split(";");
for (String configuredNuageVspDevice : configuredNuageVspDevices) {
if (configuredNuageVspDevice.startsWith(deviceId + ":")) {
String[] split = configuredNuageVspDevice.split(":");
if (split.length != 2 || (split.length > 1 && Strings.isNullOrEmpty(split[1]))) {
throw new IllegalArgumentException("The configured CMS ID for Nuage VSP device " + deviceId + " is in an incorrect format");
}
return split[1];
}
}
}
return null;
}
public List<String> getDnsDetails(Network network) {
Boolean configureDns = Boolean.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigDns.key()));
if (!configureDns) {
return Lists.newArrayList();
}
Boolean configureExternalDns = Boolean.valueOf(_configDao.getValue(NuageVspManager.NuageVspDnsExternal.key()));
DataCenterVO dc = _dataCenterDao.findById(network.getDataCenterId());
List<String> dnsServers = new ArrayList<String>();
if (configureExternalDns) {
if (!Strings.isNullOrEmpty(dc.getDns1())) {
dnsServers.add(dc.getDns1());
}
if (!Strings.isNullOrEmpty(dc.getDns2())) {
dnsServers.add(dc.getDns2());
}
};
scheduler = Executors.newScheduledThreadPool(numOfSyncThreads, threadFactory);
scheduler.scheduleWithFixedDelay(new NuageVspSyncTask("FLOATING_IP"), ONE_MINUTE_MULTIPLIER * 15, ONE_MINUTE_MULTIPLIER * syncUpIntervalInMinutes,
TimeUnit.MILLISECONDS);
scheduler.scheduleWithFixedDelay(new NuageVspSyncTask("ENTERPRISE_NTWK_MACRO"), ONE_MINUTE_MULTIPLIER * 15, ONE_MINUTE_MULTIPLIER * syncUpIntervalInMinutes,
TimeUnit.MILLISECONDS);
scheduler
.scheduleWithFixedDelay(new NuageVspSyncTask("ENTERPRISE"), ONE_MINUTE_MULTIPLIER * 15, ONE_MINUTE_MULTIPLIER * syncUpIntervalInMinutes, TimeUnit.MILLISECONDS);
} else {
s_logger.warn("NuageVsp configuration for syncWorkers=" + numOfSyncThreads + " syncInterval=" + syncUpIntervalInMinutes
+ " could not be read properly. So, check if the properties are configured properly in global properties");
if (!Strings.isNullOrEmpty(dc.getInternalDns1())) {
dnsServers.add(dc.getInternalDns1());
}
if (!Strings.isNullOrEmpty(dc.getInternalDns2())) {
dnsServers.add(dc.getInternalDns2());
}
}
public class NuageVspSyncTask implements Runnable {
private String nuageVspEntity;
public NuageVspSyncTask(String nuageVspEntity) {
this.nuageVspEntity = nuageVspEntity;
return dnsServers;
}
public String getNuageVspEntity() {
return nuageVspEntity;
public List<String> getGatewaySystemIds() {
String gatewaySystemIds = String.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigGateway.key()));
if (!Strings.isNullOrEmpty(gatewaySystemIds)) {
return Lists.newArrayList(gatewaySystemIds.split(","));
}
return Lists.newArrayList();
}
@Override
public void run() {
nuageVspSync.syncWithNuageVsp(nuageVspEntity);
public boolean preStateTransitionEvent(Status oldState, Status.Event event, Status newState, Host host, boolean status, Object opaque) {
return true;
}
@Override
public boolean postStateTransitionEvent(StateMachine2.Transition<Status, Status.Event> transition, Host vo, boolean status, Object opaque) {
// Whenever a Nuage VSP Host comes up, check if all CS domains are present and check if the CMS ID is valid
if (transition.getToState() == Status.Up && vo instanceof HostVO) {
auditHost((HostVO) vo);
}
return true;
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
initMessageBusListeners();
initNuageVspResourceListeners();
initNuageNetworkOffering();
initNuageVspVpcOffering();
Status.getStateMachine().registerListener(this);
return true;
}
@DB
private void initMessageBusListeners() {
// Create corresponding enterprise and profile in VSP when creating a CS Domain
_messageBus.subscribe(DomainManager.MESSAGE_ADD_DOMAIN_EVENT, new MessageSubscriber() {
@Override
public void onPublishMessage(String senderAddress, String subject, Object args) {
Long domainId = (Long) args;
Domain domain = _domainDao.findById(domainId);
try {
_domainDao.acquireInLockTable(domain.getId());
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);
_agentMgr.easySend(host.getId(), cmd);
}
} finally {
_domainDao.releaseFromLockTable(domain.getId());
}
}
});
// Delete corresponding enterprise and profile in VSP when deleting a CS Domain
_messageBus.subscribe(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT, new MessageSubscriber() {
@Override
public void onPublishMessage(String senderAddress, String subject, Object args) {
DomainVO domain = (DomainVO) args;
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);
_agentMgr.easySend(host.getId(), cmd);
}
}
});
}
@DB
private void initNuageVspResourceListeners() {
_agentMgr.registerForHostEvents(new Listener() {
@Override
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
return true;
}
@Override
public boolean processCommands(long agentId, long seq, Command[] commands) {
if (commands != null && commands.length == 1) {
Command command = commands[0];
if (command instanceof PingNuageVspCommand) {
PingNuageVspCommand pingNuageVspCommand = (PingNuageVspCommand) command;
if (pingNuageVspCommand.shouldAudit()) {
Host host = _hostDao.findById(pingNuageVspCommand.getHostId());
auditHost((HostVO) host);
}
}
}
return true;
}
@Override
public AgentControlAnswer processControlCommand(long agentId, AgentControlCommand cmd) {
return null;
}
@Override
public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
}
@Override
public boolean processDisconnect(long agentId, Status state) {
return true;
}
@Override
public boolean isRecurring() {
return false;
}
@Override
public int getTimeout() {
return 0;
}
@Override
public boolean processTimeout(long agentId, long seq) {
return true;
}
}, false, true, false);
}
@DB
private void initNuageNetworkOffering() {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
NetworkOffering sharedNetworkOfferingWithSG = _networkOfferingDao.findByUniqueName(nuageVspSharedNetworkOfferingWithSGServiceName);
if (sharedNetworkOfferingWithSG == null) {
NetworkOfferingVO defaultNuageVspSharedSGNetworkOffering =
new NetworkOfferingVO(nuageVspSharedNetworkOfferingWithSGServiceName, "Offering for NuageVsp Shared Security group enabled networks",
Networks.TrafficType.Guest, false, false, null, null, true, NetworkOffering.Availability.Optional, null, Network.GuestType.Shared, true, true, false, false, false);
defaultNuageVspSharedSGNetworkOffering.setState(NetworkOffering.State.Enabled);
defaultNuageVspSharedSGNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultNuageVspSharedSGNetworkOffering);
Map<Network.Service, Network.Provider> defaultNuageVspSharedSGNetworkOfferingProviders = new HashMap<>();
defaultNuageVspSharedSGNetworkOfferingProviders.put(Network.Service.Dhcp, Network.Provider.NuageVsp);
defaultNuageVspSharedSGNetworkOfferingProviders.put(Network.Service.SecurityGroup, Network.Provider.NuageVsp);
defaultNuageVspSharedSGNetworkOfferingProviders.put(Network.Service.Connectivity, Network.Provider.NuageVsp);
for (Network.Service service : defaultNuageVspSharedSGNetworkOfferingProviders.keySet()) {
NetworkOfferingServiceMapVO offService =
new NetworkOfferingServiceMapVO(defaultNuageVspSharedSGNetworkOffering.getId(), service, defaultNuageVspSharedSGNetworkOfferingProviders.get(service));
_networkOfferingServiceMapDao.persist(offService);
if (s_logger.isTraceEnabled()) {
s_logger.trace("Added service for the NuageVsp network offering: " + offService);
}
}
}
}
});
}
@DB
private void initNuageVspVpcOffering() {
//configure default Nuage VSP vpc offering
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
if (_vpcOffDao.findByUniqueName(nuageVPCOfferingName) == null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating default Nuage VPC offering " + nuageVPCOfferingName);
}
Map<Network.Service, Set<Network.Provider>> svcProviderMap = Maps.newHashMap(NUAGE_VSP_VPC_SERVICE_MAP);
Set<Network.Provider> userDataProviders = Collections.singleton(Network.Provider.VPCVirtualRouter);
svcProviderMap.put(Network.Service.UserData, userDataProviders);
createVpcOffering(nuageVPCOfferingName, nuageVPCOfferingDisplayText, svcProviderMap, true, VpcOffering.State.Enabled, null);
}
}
});
}
@DB
protected VpcOffering createVpcOffering(final String name, final String displayText, final Map<Network.Service, Set<Network.Provider>> svcProviderMap, final boolean isDefault,
final VpcOffering.State state, final Long serviceOfferingId) {
return Transaction.execute(new TransactionCallback<VpcOffering>() {
@Override
public VpcOffering doInTransaction(TransactionStatus status) {
// create vpc offering object
VpcOfferingVO offering = new VpcOfferingVO(name, displayText, isDefault, serviceOfferingId, false, false);
if (state != null) {
offering.setState(state);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Adding vpc offering " + offering);
}
offering = _vpcOffDao.persist(offering);
// populate services and providers
if (svcProviderMap != null) {
for (Network.Service service : svcProviderMap.keySet()) {
Set<Network.Provider> providers = svcProviderMap.get(service);
if (providers != null && !providers.isEmpty()) {
for (Network.Provider provider : providers) {
VpcOfferingServiceMapVO offService = new VpcOfferingServiceMapVO(offering.getId(), service, provider);
_vpcOffSvcMapDao.persist(offService);
if (s_logger.isTraceEnabled()) {
s_logger.trace("Added service for the vpc offering: " + offService + " with provider " + provider.getName());
}
}
} else {
throw new InvalidParameterValueException("Provider is missing for the VPC offering service " + service.getName());
}
}
}
return offering;
}
});
}
private HostVO findNuageVspHost(long hostId) {
HostVO host = _hostDao.findById(hostId);
_hostDao.loadDetails(host);
return host;
}
@Override
@ -348,6 +862,6 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
@Override
public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[] {NuageVspSyncWorkers, NuageVspSyncInterval};
return Arrays.copyOf(NUAGE_VSP_CONFIG_KEYS, NUAGE_VSP_CONFIG_KEYS.length);
}
}

View File

@ -19,131 +19,148 @@
package com.cloud.network.resource;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import javax.naming.ConfigurationException;
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.NuageVspSyncClient;
import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
import com.cloud.agent.IAgentControl;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.MaintainAnswer;
import com.cloud.agent.api.MaintainCommand;
import com.cloud.agent.api.PingCommand;
import com.cloud.agent.api.PingNuageVspCommand;
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.ApplyAclRuleVspAnswer;
import com.cloud.agent.api.element.ApplyAclRuleVspCommand;
import com.cloud.agent.api.element.ApplyStaticNatVspAnswer;
import com.cloud.agent.api.element.ApplyStaticNatVspCommand;
import com.cloud.agent.api.element.ShutDownVpcVspAnswer;
import com.cloud.agent.api.element.ImplementVspCommand;
import com.cloud.agent.api.element.ShutDownVpcVspCommand;
import com.cloud.agent.api.guru.DeallocateVmVspAnswer;
import com.cloud.agent.api.guru.DeallocateVmVspCommand;
import com.cloud.agent.api.guru.ImplementNetworkVspAnswer;
import com.cloud.agent.api.guru.ImplementNetworkVspCommand;
import com.cloud.agent.api.guru.ReleaseVmVspAnswer;
import com.cloud.agent.api.guru.ReleaseVmVspCommand;
import com.cloud.agent.api.guru.ReserveVmInterfaceVspAnswer;
import com.cloud.agent.api.guru.ReserveVmInterfaceVspCommand;
import com.cloud.agent.api.guru.TrashNetworkVspAnswer;
import com.cloud.agent.api.guru.TrashNetworkVspCommand;
import com.cloud.agent.api.sync.SyncVspAnswer;
import com.cloud.agent.api.manager.GetClientDefaultsAnswer;
import com.cloud.agent.api.manager.GetClientDefaultsCommand;
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.utils.StringUtils;
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.codec.binary.Base64;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.log4j.Logger;
import javax.naming.ConfigurationException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.regex.Pattern;
import static com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand.SyncType;
public class NuageVspResource extends ManagerBase implements ServerResource {
private static final Logger s_logger = Logger.getLogger(NuageVspResource.class);
private static final String NAME = "name";
private static final String GUID = "guid";
private static final String ZONE_ID = "zoneid";
private static final String HOST_NAME = "hostname";
private static final String CMS_USER = "cmsuser";
private static final String CMS_USER_PASSWORD = "cmsuserpass";
private static final String PORT = "port";
private static final String API_VERSION = "apiversion";
private static final String API_RELATIVE_PATH = "apirelativepath";
private static final String RETRY_COUNT = "retrycount";
private static final String RETRY_INTERVAL = "retryinterval";
private static final String NUAGE_VSP_CMS_ID = "nuagevspcmsid";
private String _name;
private String _guid;
private String _zoneId;
private String[] _cmsUserInfo;
private String _hostName;
private String _relativePath;
private int _numRetries;
private int _retryInterval;
private String _nuageVspCmsId;
private boolean _shouldAudit = true;
protected NuageVspApiClient _nuageVspApiClient;
protected NuageVspGuruClient _nuageVspGuruClient;
protected NuageVspElementClient _nuageVspElementClient;
protected NuageVspSyncClient _nuageVspSyncClient;
protected NuageVspManagerClient _nuageVspManagerClient;
protected boolean _isNuageVspClientLoaded;
private static final String CMS_USER_ENTEPRISE_NAME = "CSP";
private static final String NUAGE_VSP_PLUGIN_ERROR_MESSAGE = "Nuage Vsp plugin client is not installed";
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";
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_name = (String)params.get("name");
_name = (String)params.get(NAME);
if (_name == null) {
throw new ConfigurationException("Unable to find name");
}
_guid = (String)params.get("guid");
_guid = (String)params.get(GUID);
if (_guid == null) {
throw new ConfigurationException("Unable to find the guid");
}
_zoneId = (String)params.get("zoneId");
_zoneId = (String)params.get(ZONE_ID);
if (_zoneId == null) {
throw new ConfigurationException("Unable to find zone");
}
String hostname = (String)params.get("hostname");
if (hostname == null) {
_hostName = (String)params.get(HOST_NAME);
if (Strings.isNullOrEmpty(_hostName)) {
throw new ConfigurationException("Unable to find hostname");
}
String cmsUser = (String)params.get("cmsuser");
if (cmsUser == null) {
String cmsUser = (String)params.get(CMS_USER);
if (Strings.isNullOrEmpty(cmsUser)) {
throw new ConfigurationException("Unable to find CMS username");
}
String cmsUserPassBase64 = (String)params.get("cmsuserpass");
if (cmsUserPassBase64 == null) {
String cmsUserPassBase64 = (String)params.get(CMS_USER_PASSWORD);
if (Strings.isNullOrEmpty(cmsUserPassBase64)) {
throw new ConfigurationException("Unable to find CMS password");
}
String port = (String)params.get("port");
if (port == null) {
String port = (String)params.get(PORT);
if (Strings.isNullOrEmpty(port)) {
throw new ConfigurationException("Unable to find port");
}
String apiRelativePath = (String)params.get("apirelativepath");
if ((apiRelativePath != null) && (!apiRelativePath.isEmpty())) {
String apiVersion = apiRelativePath.substring(apiRelativePath.lastIndexOf('/') + 1);
if (!Pattern.matches("v\\d+_\\d+", apiVersion)) {
String apiVersion = (String)params.get(API_VERSION);
if (Strings.isNullOrEmpty(apiVersion)) {
throw new ConfigurationException("Unable to find API version");
} else if (!Pattern.matches("v\\d+_\\d+", apiVersion)) {
throw new ConfigurationException("Incorrect API version");
}
} else {
throw new ConfigurationException("Unable to find API version");
String apiRelativePath = (String)params.get(API_RELATIVE_PATH);
if (Strings.isNullOrEmpty(apiRelativePath) || !apiRelativePath.contains(apiVersion)) {
throw new ConfigurationException("Unable to find API version in relative path");
}
String retryCount = (String)params.get("retrycount");
if ((retryCount != null) && (!retryCount.isEmpty())) {
String retryCount = (String)params.get(RETRY_COUNT);
if (!Strings.isNullOrEmpty(retryCount)) {
try {
_numRetries = Integer.parseInt(retryCount);
} catch (NumberFormatException ex) {
@ -156,8 +173,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
throw new ConfigurationException("Unable to find number of retries");
}
String retryInterval = (String)params.get("retryinterval");
if ((retryInterval != null) && (!retryInterval.isEmpty())) {
String retryInterval = (String)params.get(RETRY_INTERVAL);
if (!Strings.isNullOrEmpty(retryInterval)) {
try {
_retryInterval = Integer.parseInt(retryInterval);
} catch (NumberFormatException ex) {
@ -170,57 +187,45 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
throw new ConfigurationException("Unable to find retry interval");
}
_relativePath = new StringBuffer().append("https://").append(hostname).append(":").append(port).append(apiRelativePath).toString();
_relativePath = new StringBuffer().append("https://").append(_hostName).append(":").append(port).append(apiRelativePath).toString();
String cmsUserPass = org.apache.commons.codec.binary.StringUtils.newStringUtf8(Base64.decodeBase64(cmsUserPassBase64));
_cmsUserInfo = new String[] {CMS_USER_ENTEPRISE_NAME, cmsUser, cmsUserPass};
try {
_nuageVspCmsId = (String)params.get(NUAGE_VSP_CMS_ID);
loadNuageClient();
} catch (Exception e) {
throw new CloudRuntimeException("Failed to login to Nuage VSD on " + name + " as user " + cmsUser, e);
}
try {
login();
} catch (Exception e) {
s_logger.error("Failed to login to Nuage VSD on " + name + " as user " + cmsUser + " Exception " + e.getMessage());
} 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);
}
return true;
}
protected void login() throws Exception {
protected void login() throws ConfigurationException, ExecutionException {
isNuageVspApiLoaded();
_nuageVspApiClient.login();
}
protected <A extends NuageVspApiClient, B extends NuageVspElementClient, C extends NuageVspSyncClient, D extends NuageVspGuruClient> void loadNuageClient() throws Exception {
protected <A extends NuageVspApiClient, B extends NuageVspElementClient, C extends NuageVspSyncClient, D extends NuageVspGuruClient> void loadNuageClient() {
try {
ClassLoader loader = NuageVspPluginClientLoader.getClassLoader(NUAGE_PLUGIN_CLIENT_JAR_FILE);
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);
//Instantiate the instances
_nuageVspApiClient = (NuageVspApiClient)nuageVspApiClientClass.newInstance();
_nuageVspApiClient.setNuageVspHost(_relativePath, _cmsUserInfo, _numRetries, _retryInterval);
_nuageVspSyncClient = (NuageVspSyncClient)nuageVspSyncClientClass.newInstance();
_nuageVspSyncClient.setNuageVspApiClient(_nuageVspApiClient);
_nuageVspGuruClient = (NuageVspGuruClient)nuageVspGuruClientClass.newInstance();
_nuageVspGuruClient.setNuageVspApiClient(_nuageVspApiClient);
_nuageVspElementClient = (NuageVspElementClient)nuageVspElementClientClass.newInstance();
_nuageVspElementClient.setNuageVspApiClient(_nuageVspApiClient);
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 (Exception e) {
} 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.warn(errorMessage + e.getMessage());
throw new Exception(errorMessage);
s_logger.error(errorMessage, e);
throw new CloudRuntimeException(errorMessage, e);
}
}
@ -260,17 +265,26 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
@Override
public PingCommand getCurrentStatus(long id) {
if ((_relativePath == null) || (_relativePath.isEmpty()) || (_cmsUserInfo == null) || (_cmsUserInfo.length == 0)) {
s_logger.error("Failed to ping to Nuage VSD");
if (_relativePath == null || _relativePath.isEmpty()) {
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) {
s_logger.error("Refusing to ping Nuage VSD because the resource configuration is missing the CMS user information");
_shouldAudit = true;
return null;
}
try {
login();
} catch (Exception e) {
s_logger.error("Failed to ping to Nuage VSD on " + _name + " as user " + _cmsUserInfo[1] + " Exception " + e.getMessage());
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failed to ping to Nuage VSD on " + _name + " as user " + _cmsUserInfo[1], e);
_shouldAudit = true;
return null;
}
return new PingCommand(Host.Type.L2Networking, id);
PingNuageVspCommand pingNuageVspCommand = new PingNuageVspCommand(Host.Type.L2Networking, id, _shouldAudit);
_shouldAudit = false;
return pingNuageVspCommand;
}
@Override
@ -287,15 +301,15 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
return executeRequest((ImplementNetworkVspCommand)cmd);
} else if (cmd instanceof ReserveVmInterfaceVspCommand) {
return executeRequest((ReserveVmInterfaceVspCommand)cmd);
} else if (cmd instanceof ReleaseVmVspCommand) {
return executeRequest((ReleaseVmVspCommand)cmd);
} else if (cmd instanceof DeallocateVmVspCommand) {
return executeRequest((DeallocateVmVspCommand)cmd);
} else if (cmd instanceof TrashNetworkVspCommand) {
return executeRequest((TrashNetworkVspCommand)cmd);
}
//Element commands
else if (cmd instanceof ApplyAclRuleVspCommand) {
else if (cmd instanceof ImplementVspCommand) {
return executeRequest((ImplementVspCommand)cmd);
} else if (cmd instanceof ApplyAclRuleVspCommand) {
return executeRequest((ApplyAclRuleVspCommand)cmd);
} else if (cmd instanceof ApplyStaticNatVspCommand) {
return executeRequest((ApplyStaticNatVspCommand)cmd);
@ -305,8 +319,20 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
//Sync Commands
else if (cmd instanceof SyncVspCommand) {
return executeRequest((SyncVspCommand)cmd);
} 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 SupportedApiVersionCommand) {
return executeRequest((SupportedApiVersionCommand)cmd);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Received unsupported command " + cmd.toString());
}
return Answer.createUnsupportedCommandAnswer(cmd);
}
@ -340,7 +366,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
return new VspResourceAnswer(cmd, resourceInfo, "Executed Issue Resource command");
}
return new VspResourceAnswer(cmd, false, cmd.getRequestType() + " is not yet supported");
} catch (Exception e) {
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new VspResourceAnswer(cmd, e);
}
}
@ -349,85 +376,98 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
try {
isNuageVspGuruLoaded();
_nuageVspGuruClient.implement(cmd.getNetworkDomainName(), cmd.getNetworkDomainPath(), cmd.getNetworkDomainUuid(), cmd.getNetworkAccountName(),
cmd.getNetworkAccountUuid(), cmd.getNetworkName(), cmd.getNetworkCidr(), cmd.getNetworkGateway(), cmd.getNetworkUuid(), cmd.isL3Network(), cmd.getVpcName(),
cmd.getVpcUuid(), cmd.isDefaultEgressPolicy(), cmd.getIpAddressRange());
return new ImplementNetworkVspAnswer(cmd, true, "Created Nuage VSP network mapping to " + cmd.getNetworkName());
} catch (Exception e) {
return new ImplementNetworkVspAnswer(cmd, e);
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);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
}
}
private Answer executeRequest(ReserveVmInterfaceVspCommand cmd) {
try {
isNuageVspGuruLoaded();
List<Map<String, String>> vmInterfaceInfo = _nuageVspGuruClient.reserve(cmd.getNicUuid(), cmd.getNicMacAddress(), cmd.getNetworkUuid(), cmd.isL3Network(),
cmd.getVpcUuid(), cmd.getNetworkDomainUuid(), cmd.getNetworksAccountUuid(), cmd.isDomainRouter(), cmd._getDomainRouterIp(), cmd._getVmInstanceName(),
cmd._getVmUuid());
return new ReserveVmInterfaceVspAnswer(cmd, vmInterfaceInfo, "Created NIC in VSP that maps to nicUuid" + cmd.getNicUuid());
} catch (Exception e) {
return new ReserveVmInterfaceVspAnswer(cmd, e);
}
}
private Answer executeRequest(ReleaseVmVspCommand cmd) {
try {
isNuageVspGuruLoaded();
_nuageVspGuruClient.release(cmd.getNetworkUuid(), cmd.getVmUuid(), cmd.getVmInstanceName());
return new ReleaseVmVspAnswer(cmd, true, "VM has been deleted from VSP.");
} catch (Exception e) {
return new ReleaseVmVspAnswer(cmd, e);
_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);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
}
}
private Answer executeRequest(DeallocateVmVspCommand cmd) {
try {
isNuageVspGuruLoaded();
_nuageVspGuruClient.deallocate(cmd.getNetworkUuid(), cmd.getNicFrmDdUuid(), cmd.getNicMacAddress(), cmd.getNicIp4Address(), cmd.isL3Network(), cmd.getVpcUuid(),
cmd.getNetworksDomainUuid(), cmd.getVmInstanceName(), cmd.getVmUuid());
return new DeallocateVmVspAnswer(cmd, true, "Deallocated VM from Nuage VSP.");
} catch (Exception e) {
return new DeallocateVmVspAnswer(cmd, e);
_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);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
}
}
private Answer executeRequest(TrashNetworkVspCommand cmd) {
try {
isNuageVspGuruLoaded();
_nuageVspGuruClient.trash(cmd.getDomainUuid(), cmd.getNetworkUuid(), cmd.isL3Network(), cmd.getVpcUuid());
return new TrashNetworkVspAnswer(cmd, true, "Deleted Nuage VSP network mapping to " + cmd.getNetworkUuid());
} catch (Exception e) {
return new TrashNetworkVspAnswer(cmd, e);
_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);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
}
}
private Answer executeRequest(ApplyStaticNatVspCommand cmd) {
try {
isNuageVspElementLoaded();
_nuageVspElementClient.applyStaticNats(cmd.getNetworkDomainUuid(), cmd.getVpcOrSubnetUuid(), cmd.isL3Network(), cmd.getStaticNatDetails());
return new ApplyStaticNatVspAnswer(cmd, true, "Applied Static NAT to VSP network mapping to " + cmd.getVpcOrSubnetUuid());
} catch (Exception e) {
return new ApplyStaticNatVspAnswer(cmd, e);
_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);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
}
}
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);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
}
}
private Answer executeRequest(ApplyAclRuleVspCommand cmd) {
try {
isNuageVspElementLoaded();
_nuageVspElementClient.applyAclRules(cmd.getNetworkUuid(), cmd.getNetworkDomainUuid(), cmd.getVpcOrSubnetUuid(), cmd.isL3Network(), cmd.getAclRules(), cmd.isVpc(),
cmd.getNetworkId());
return new ApplyAclRuleVspAnswer(cmd, true, "Applied ACL Rule to VSP network mapping to " + cmd.getVpcOrSubnetUuid());
} catch (Exception e) {
return new ApplyAclRuleVspAnswer(cmd, e);
_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);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
}
}
private Answer executeRequest(ShutDownVpcVspCommand cmd) {
try {
isNuageVspElementLoaded();
_nuageVspElementClient.shutDownVpc(cmd.getDomainUuid(), cmd.getVpcUuid());
return new ShutDownVpcVspAnswer(cmd, true, "Shutdown VPC " + cmd.getVpcUuid());
} catch (Exception e) {
return new ShutDownVpcVspAnswer(cmd, e);
_nuageVspElementClient.shutdownVpc(cmd.getDomainUuid(), cmd.getVpcUuid(), cmd.getDomainTemplateName());
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);
return new Answer(cmd, e);
}
}
@ -435,33 +475,248 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
try {
isNuageVspSyncLoaded();
_nuageVspSyncClient.syncWithNuageVsp(cmd.getNuageVspEntity());
return new SyncVspAnswer(cmd, true, "Synced " + cmd.getNuageVspEntity() + " in VSP");
} catch (Exception e) {
return new SyncVspAnswer(cmd, e);
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);
}
}
protected void isNuageVspApiLoaded() throws Exception {
private Answer executeRequest(SyncNuageVspCmsIdCommand cmd) {
try {
isNuageVspManagerLoaded();
if (cmd.getSyncType() == SyncType.AUDIT || cmd.getSyncType() == SyncType.AUDIT_ONLY) {
Pair<Boolean, String> answer = _nuageVspManagerClient.auditNuageVspCmsId(cmd.getNuageVspCmsId(), cmd.getSyncType() == SyncType.AUDIT_ONLY);
return new SyncNuageVspCmsIdAnswer(answer.getLeft(), answer.getRight(), cmd.getSyncType());
} else if (cmd.getSyncType() == SyncType.REGISTER) {
String registeredNuageVspCmsId = _nuageVspManagerClient.registerNuageVspCmsId();
return new SyncNuageVspCmsIdAnswer(StringUtils.isNotBlank(registeredNuageVspCmsId), registeredNuageVspCmsId, cmd.getSyncType());
} else {
boolean success = _nuageVspManagerClient.unregisterNuageVspCmsId(cmd.getNuageVspCmsId());
return new SyncNuageVspCmsIdAnswer(success, cmd.getNuageVspCmsId(), cmd.getSyncType());
}
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new SyncNuageVspCmsIdAnswer(false, null, cmd.getSyncType());
}
}
private Answer executeRequest(SyncDomainCommand cmd) {
try {
isNuageVspManagerLoaded();
boolean success = _nuageVspManagerClient.syncDomainWithNuageVsp(cmd.getDomainUuid(), cmd.getDomainName(), cmd.getDomainPath(), cmd.isToAdd(), cmd.isToRemove());
return new SyncDomainAnswer(success);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new SyncDomainAnswer(false);
}
}
private Answer executeRequest(GetClientDefaultsCommand cmd) {
try {
isNuageVspManagerLoaded();
Map<String, Object> clientDefaults = _nuageVspManagerClient.getClientDefaults();
return new GetClientDefaultsAnswer(cmd, clientDefaults);
} catch (ExecutionException | ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new GetClientDefaultsAnswer(cmd, e);
}
}
private Answer executeRequest(SupportedApiVersionCommand cmd) {
try {
isNuageVspManagerLoaded();
boolean supported = _nuageVspManagerClient.isSupportedApiVersion(cmd.getApiVersion());
return new Answer(cmd, supported, "Check if API version " + cmd.getApiVersion() + " is supported");
} catch (ConfigurationException e) {
s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
return new Answer(cmd, e);
}
}
protected void isNuageVspApiLoaded() throws ConfigurationException {
if (!_isNuageVspClientLoaded || _nuageVspApiClient == null) {
throw new Exception(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
throw new ConfigurationException(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
}
}
protected void isNuageVspGuruLoaded() throws Exception {
protected void isNuageVspGuruLoaded() throws ConfigurationException {
if (!_isNuageVspClientLoaded || _nuageVspGuruClient == null) {
throw new Exception(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
throw new ConfigurationException(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
}
}
protected void isNuageVspElementLoaded() throws Exception {
protected void isNuageVspElementLoaded() throws ConfigurationException {
if (!_isNuageVspClientLoaded || _nuageVspElementClient == null) {
throw new Exception(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
throw new ConfigurationException(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
}
}
protected void isNuageVspSyncLoaded() throws Exception {
protected void isNuageVspSyncLoaded() throws ConfigurationException {
if (!_isNuageVspClientLoaded || _nuageVspSyncClient == null) {
throw new Exception(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
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);
}
}
public static class Configuration {
private String _name;
private String _guid;
private String _zoneId;
private String _hostName;
private String _cmsUser;
private String _cmsUserPassword;
private String _port;
private String _apiVersion;
private String _apiRelativePath;
private String _retryCount;
private String _retryInterval;
private String _nuageVspCmsId;
public String name() {
return this._name;
}
public Configuration name(String name) {
this._name = name;
return this;
}
public String guid() {
return this._guid;
}
public Configuration guid(String guid) {
this._guid = guid;
return this;
}
public String zoneId() {
return this._zoneId;
}
public Configuration zoneId(String zoneId) {
this._zoneId = zoneId;
return this;
}
public String hostName() {
return this._hostName;
}
public Configuration hostName(String hostName) {
this._hostName = hostName;
return this;
}
public String cmsUser() {
return this._cmsUser;
}
public Configuration cmsUser(String cmsUser) {
this._cmsUser = cmsUser;
return this;
}
public String cmsUserPassword() {
return this._cmsUserPassword;
}
public Configuration cmsUserPassword(String cmsUserPassword) {
this._cmsUserPassword = cmsUserPassword;
return this;
}
public String port() {
return this._port;
}
public Configuration port(String port) {
this._port = port;
return this;
}
public String apiVersion() {
return this._apiVersion;
}
public Configuration apiVersion(String apiVersion) {
this._apiVersion = apiVersion;
return this;
}
public String apiRelativePath() {
return this._apiRelativePath;
}
public Configuration apiRelativePath(String apiRelativePath) {
this._apiRelativePath = apiRelativePath;
return this;
}
public String retryCount() {
return this._retryCount;
}
public Configuration retryCount(String retryCount) {
this._retryCount = retryCount;
return this;
}
public String retryInterval() {
return this._retryInterval;
}
public Configuration retryInterval(String retryInterval) {
this._retryInterval = retryInterval;
return this;
}
public String nuageVspCmsId() {
return this._nuageVspCmsId;
}
public Configuration nuageVspCmsId(String nuageVspCmsId) {
this._nuageVspCmsId = nuageVspCmsId;
return this;
}
public Map<String, String> build() {
return new HashMap<String, String>() {{
if (_name != null) put(NAME, _name);
if (_guid != null) put(GUID, _guid);
if (_zoneId != null) put(ZONE_ID, _zoneId);
if (_hostName != null) put(HOST_NAME, _hostName);
if (_cmsUser != null) put(CMS_USER, _cmsUser);
if (_cmsUserPassword != null) put(CMS_USER_PASSWORD, _cmsUserPassword);
if (_port != null) put(PORT, _port);
if (_apiVersion != null) put(API_VERSION, _apiVersion);
if (_apiRelativePath != null) put(API_RELATIVE_PATH, _apiRelativePath);
if (_retryCount != null) put(RETRY_COUNT, _retryCount);
if (_retryInterval != null) put(RETRY_INTERVAL, _retryInterval);
if (_nuageVspCmsId != null) put(NUAGE_VSP_CMS_ID, _nuageVspCmsId);
}};
}
public static Configuration fromConfiguration(Map<String, String> configuration) {
return new Configuration()
.name(configuration.get(NAME))
.guid(configuration.get(GUID))
.zoneId(configuration.get(ZONE_ID))
.hostName(configuration.get(HOST_NAME))
.cmsUser(configuration.get(CMS_USER))
.cmsUserPassword(configuration.get(CMS_USER_PASSWORD))
.port(configuration.get(PORT))
.apiVersion(configuration.get(API_VERSION))
.apiRelativePath(configuration.get(API_RELATIVE_PATH))
.retryCount(configuration.get(RETRY_COUNT))
.retryInterval(configuration.get(RETRY_INTERVAL))
.nuageVspCmsId(configuration.get(NUAGE_VSP_CMS_ID));
}
}
}

View File

@ -19,20 +19,18 @@
package com.cloud.network.sync;
import java.util.List;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.sync.SyncVspAnswer;
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 {
@ -52,21 +50,16 @@ public class NuageVspSyncImpl implements NuageVspSync {
//entities
List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
try {
HostVO nuageVspHost = _hostDao.findById(nuageVspDevice.getHostId());
_hostDao.loadDetails(nuageVspHost);
SyncVspCommand cmd = new SyncVspCommand(nuageVspEntity);
SyncVspAnswer answer = (SyncVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
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());
}
}
} catch (Exception e) {
s_logger.warn("Failed to clean up " + nuageVspEntity + " in Vsp " + e.getMessage());
}
}
}
}

View File

@ -0,0 +1,40 @@
//
// 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.network.Network;
import com.cloud.network.manager.NuageVspManager;
import com.cloud.offering.NetworkOffering;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
public class NuageVspUtil {
public static String getPreConfiguredDomainTemplateName(ConfigurationDao configDao, Network network, NetworkOffering networkOffering) {
String configKey;
if (network.getVpcId() != null) {
configKey = NuageVspManager.NuageVspVpcDomainTemplateName.key();
} else if (networkOffering.getGuestType() == Network.GuestType.Shared) {
configKey = NuageVspManager.NuageVspSharedNetworkDomainTemplateName.key();
} else {
configKey = NuageVspManager.NuageVspIsolatedNetworkDomainTemplateName.key();
}
return configDao.getValue(configKey);
}
}

View File

@ -19,28 +19,101 @@
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 org.apache.log4j.Logger;
import javax.naming.ConfigurationException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
public class NuageVspPluginClientLoader {
private static NuageVspPluginClientLoader nuageVspPluginClientClassloader;
private ClassLoader loader = null;
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(String nuagePluginClientJarLocation) {
try {
loader = URLClassLoader.newInstance(new URL[] {new URL("jar:file:" + nuagePluginClientJarLocation + "!/")},
_loader = URLClassLoader.newInstance(new URL[] {new URL("jar:file:" + nuagePluginClientJarLocation + "!/")},
getClass().getClassLoader());
} catch (MalformedURLException e) {
e.printStackTrace();
throw new IllegalArgumentException(e);
}
}
public static ClassLoader getClassLoader(String nuagePluginClientJarLocation) {
if (nuageVspPluginClientClassloader == null) {
nuageVspPluginClientClassloader = new NuageVspPluginClientLoader(nuagePluginClientJarLocation);
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);
return nuageVspPluginClientClassloader;
}
return nuageVspPluginClientClassloader.loader;
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");
}
}
public NuageVspApiClient getNuageVspApiClient() {
return _nuageVspApiClient;
}
public NuageVspElementClient getNuageVspElementClient() {
return _nuageVspElementClient;
}
public NuageVspGuruClient getNuageVspGuruClient() {
return _nuageVspGuruClient;
}
public NuageVspManagerClient getNuageVspManagerClient() {
return _nuageVspManagerClient;
}
public NuageVspSyncClient getNuageVspSyncClient() {
return _nuageVspSyncClient;
}
}

View File

@ -19,12 +19,14 @@
package net.nuage.vsp.acs.client;
import java.util.concurrent.ExecutionException;
public interface NuageVspApiClient {
public void login() throws Exception;
void login() throws ExecutionException;
public void setNuageVspHost(String restRelativePath, String[] cmsUserInfo, int noofRetry, int retryInterval);
void setNuageVspHost(String restRelativePath, String[] cmsUserInfo, int noofRetry, int retryInterval, String nuageVspCmsId);
public String executeRestApi(String method, String resource, String resourceId, String childResource, Object entityDetails, String resourceFilter, String proxyUserUuid,
String proxyUserDomainuuid) throws Exception;
String executeRestApi(String method, String resource, String resourceId, String childResource, Object entityDetails, String resourceFilter, String proxyUserUuid,
String proxyUserDomainuuid) throws ExecutionException;
}

View File

@ -21,16 +21,22 @@ package net.nuage.vsp.acs.client;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
public interface NuageVspElementClient {
public void applyStaticNats(String networkDomainUuid, String vpcOrSubnetUuid, boolean isL3Network, List<Map<String, Object>> staticNatDetails) throws Exception;
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;
public void applyAclRules(String networkUuid, String networkDomainUuid, String vpcOrSubnetUuid, boolean isL3Network, List<Map<String, Object>> aclRules, boolean isVpc, long networkId)
throws Exception;
void applyStaticNats(String networkDomainUuid, String networkUuid, String vpcOrSubnetUuid, boolean isL3Network, boolean isVpc,
List<Map<String, Object>> staticNatDetails) throws ExecutionException;
public void shutDownVpc(String domainUuid, String vpcUuid) throws Exception;
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;
public <C extends NuageVspApiClient> void setNuageVspApiClient(NuageVspApiClient nuageVspApiClient);
void shutdownVpc(String domainUuid, String vpcUuid, String domainTemplateName) throws ExecutionException;
<C extends NuageVspApiClient> void setNuageVspApiClient(NuageVspApiClient nuageVspApiClient);
}

View File

@ -21,24 +21,23 @@ package net.nuage.vsp.acs.client;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
public interface NuageVspGuruClient {
public void implement(String networkDomainName, String networkDomainPath, String networkDomainUuid, String networkAccountName, String networkAccountUuid, String networkName,
String networkCidr, String networkGateway, String networkUuid, boolean isL3Network, String vpcName, String vpcUuid, boolean defaultEgressPolicy,
Collection<String> ipAddressRange) throws Exception;
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;
public List<Map<String, String>> reserve(String nicUuid, String nicMacAddress, String networkUuid, boolean isL3Network, String vpcUuid, String networkDomainUuid,
String networksAccountUuid, boolean isDomainRouter, String domainRouterIp, String vmInstanceName, String vmUuid) throws Exception;
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;
public void release(String networkUuid, String vmUuid, String vmInstanceName) throws Exception;
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;
public void deallocate(String networkUuid, String nicFrmDdUuid, String nicMacAddress, String nicIp4Address, boolean isL3Network, String vpcUuid, String networksDomainUuid,
String vmInstanceName, String vmUuid) throws Exception;
void trash(String domainUuid, String networkUuid, boolean isL3Network, boolean isSharedNetwork, String vpcUuid, String domainTemplateName) throws ExecutionException;
public void trash(String domainUuid, String networkUuid, boolean isL3Network, String vpcUuid) throws Exception;
public void setNuageVspApiClient(NuageVspApiClient nuageVspApiClient);
void setNuageVspApiClient(NuageVspApiClient nuageVspApiClient);
}

View File

@ -17,28 +17,26 @@
// under the License.
//
package com.cloud.agent.api.guru;
package net.nuage.vsp.acs.client;
import org.apache.commons.lang3.tuple.Pair;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
public interface NuageVspManagerClient {
public class ReserveVmInterfaceVspAnswer extends Answer {
Pair<Boolean, String> auditNuageVspCmsId(String nuageVspCmsId, boolean auditOnly) throws ExecutionException;
public List<Map<String, String>> _interfaceDetails;
String registerNuageVspCmsId() throws ExecutionException;
public ReserveVmInterfaceVspAnswer(Command cmd, List<Map<String, String>> interfaceDetails, String details) {
super(cmd, true, details);
this._interfaceDetails = interfaceDetails;
}
boolean unregisterNuageVspCmsId(String nuageVspCmsId) throws ExecutionException;
public ReserveVmInterfaceVspAnswer(Command cmd, Exception e) {
super(cmd, e);
}
boolean isSupportedApiVersion(String version);
public List<Map<String, String>> getInterfaceDetails() {
return this._interfaceDetails;
}
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

@ -19,9 +19,11 @@
package net.nuage.vsp.acs.client;
import java.util.concurrent.ExecutionException;
public interface NuageVspSyncClient {
public void syncWithNuageVsp(String nuageVspEntity) throws Exception;
void syncWithNuageVsp(String nuageVspEntity) throws ExecutionException;
public void setNuageVspApiClient(NuageVspApiClient nuageVspApiClient);
void setNuageVspApiClient(NuageVspApiClient nuageVspApiClient);
}

View File

@ -0,0 +1,151 @@
//
// 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;
import com.cloud.agent.api.element.ApplyAclRuleVspCommand;
import com.cloud.agent.api.element.ApplyStaticNatVspCommand;
import com.cloud.agent.api.element.ImplementVspCommand;
import com.cloud.agent.api.element.ShutDownVpcVspCommand;
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.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();
ApplyStaticNatVspCommand applyStaticNatVspCommand = fillBuilderObject(new ApplyStaticNatVspCommand.Builder()).build();
ApplyStaticNatVspCommand otherApplyStaticNatVspCommand = fillBuilderObject(new ApplyStaticNatVspCommand.Builder()).build();
ImplementVspCommand implementVspCommand = fillBuilderObject(new ImplementVspCommand.Builder()).build();
ImplementVspCommand otherImplementVspCommand = fillBuilderObject(new ImplementVspCommand.Builder()).build();
ShutDownVpcVspCommand shutDownVpcVspCommand = fillBuilderObject(new ShutDownVpcVspCommand.Builder()).build();
ShutDownVpcVspCommand otherShutDownVpcVspCommand = fillBuilderObject(new ShutDownVpcVspCommand.Builder()).build();
DeallocateVmVspCommand deallocateVmVspCommand = fillBuilderObject(new DeallocateVmVspCommand.Builder()).build();
DeallocateVmVspCommand otherDeallocateVmVspCommand = fillBuilderObject(new DeallocateVmVspCommand.Builder()).build();
ImplementNetworkVspCommand implementNetworkVspCommand = fillBuilderObject(new ImplementNetworkVspCommand.Builder()).build();
ImplementNetworkVspCommand otherImplementNetworkVspCommand = fillBuilderObject(new ImplementNetworkVspCommand.Builder()).build();
ReserveVmInterfaceVspCommand reserveVmInterfaceVspCommand = fillBuilderObject(new ReserveVmInterfaceVspCommand.Builder()).build();
ReserveVmInterfaceVspCommand otherReserveVmInterfaceVspCommand = fillBuilderObject(new ReserveVmInterfaceVspCommand.Builder()).build();
TrashNetworkVspCommand trashNetworkVspCommand = fillBuilderObject(new TrashNetworkVspCommand.Builder()).build();
TrashNetworkVspCommand otherTrashNetworkVspCommand = fillBuilderObject(new TrashNetworkVspCommand.Builder()).build();
SupportedApiVersionCommand supportedApiVersionCommand = new SupportedApiVersionCommand("3.2");
SupportedApiVersionCommand otherSupportedApiVersionCommand = new SupportedApiVersionCommand("3.2");
SyncDomainCommand syncDomainCommand = fillObject(SyncDomainCommand.class);
SyncDomainCommand otherSyncDomainCommand = fillObject(SyncDomainCommand.class);
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)
.addEqualityGroup(implementVspCommand, otherImplementVspCommand)
.addEqualityGroup(shutDownVpcVspCommand, otherShutDownVpcVspCommand)
.addEqualityGroup(deallocateVmVspCommand, otherDeallocateVmVspCommand)
.addEqualityGroup(implementNetworkVspCommand, otherImplementNetworkVspCommand)
.addEqualityGroup(reserveVmInterfaceVspCommand, otherReserveVmInterfaceVspCommand)
.addEqualityGroup(trashNetworkVspCommand, otherTrashNetworkVspCommand)
.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];
for (int i = 0; i < constructor.getParameterTypes().length; i++) {
Class constructorArgType = constructor.getParameterTypes()[i];
if (isNumericType(constructorArgType)) {
constructorArgs[i] = constructorArgType.getName().length();
} else if (String.class.isAssignableFrom(constructorArgType)) {
constructorArgs[i] = constructorArgType.getName();
} else if (Boolean.class.isAssignableFrom(constructorArgType) || boolean.class.isAssignableFrom(constructorArgType)) {
constructorArgs[i] = constructorArgType.getName().length() % 2 == 0;
} else if (Map.class.isAssignableFrom(constructorArgType)) {
constructorArgs[i] = Maps.newHashMap();
} else {
constructorArgs[i] = null;
}
}
return (T) constructor.newInstance(constructorArgs);
}
private boolean isNumericType(Class type) {
return Number.class.isAssignableFrom(type) || int.class.isAssignableFrom(type) || long.class.isAssignableFrom(type);
}
}

View File

@ -19,35 +19,10 @@
package com.cloud.network.element;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.element.ApplyAclRuleVspAnswer;
import com.cloud.agent.api.element.ApplyStaticNatVspAnswer;
import com.cloud.deploy.DeployDestination;
import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.exception.CloudException;
@ -64,11 +39,20 @@ import com.cloud.network.NetworkModel;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.NuageVspDeviceVO;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.dao.FirewallRulesDao;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.network.dao.NetworkServiceMapDao;
import com.cloud.network.dao.NuageVspDao;
import com.cloud.network.dao.PhysicalNetworkDao;
import com.cloud.network.dao.PhysicalNetworkVO;
import com.cloud.network.manager.NuageVspManager;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.FirewallRuleVO;
import com.cloud.network.rules.StaticNat;
import com.cloud.network.vpc.NetworkACLItem;
import com.cloud.network.vpc.Vpc;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
@ -76,6 +60,31 @@ import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.resource.ResourceManager;
import com.cloud.user.Account;
import com.cloud.vm.ReservationContext;
import com.google.common.collect.Lists;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
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;
import java.util.Arrays;
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;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class NuageVspElementTest {
@ -90,8 +99,13 @@ public class NuageVspElementTest {
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);
Answer<Object> genericAnswer = new Answer<Object>() {
org.mockito.stubbing.Answer<Object> genericAnswer = new org.mockito.stubbing.Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
return null;
}
@ -108,15 +122,23 @@ public class NuageVspElementTest {
element._ntwkOfferingSrvcDao = ntwkOfferingSrvcDao;
element._domainDao = domainDao;
element._ntwkOfferingDao = ntwkOfferingDao;
element._configDao = configDao;
element._nuageVspManager = nuageVspManager;
element._firewallRulesDao = firewallRulesDao;
element._ipAddressDao = ipAddressDao;
element._physicalNetworkDao = physNetDao;
// 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");
element.configure("NuageVspTestElement", Collections.<String, Object> emptyMap());
}
@Test
public void testCcanHandle() {
public void testCanHandle() {
final Network net = mock(Network.class);
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vsp);
when(net.getId()).thenReturn(NETWORK_ID);
@ -150,7 +172,10 @@ public class NuageVspElementTest {
final Network network = mock(Network.class);
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vsp);
when(network.getId()).thenReturn(NETWORK_ID);
when(network.getVpcId()).thenReturn(null);
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);
@ -161,14 +186,27 @@ public class NuageVspElementTest {
DeployDestination deployDest = mock(DeployDestination.class);
final Domain dom = mock(Domain.class);
final DomainVO dom = mock(DomainVO.class);
when(dom.getName()).thenReturn("domain");
when(domainDao.findById(NETWORK_ID)).thenReturn(dom);
final Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
final ReservationContext context = mock(ReservationContext.class);
when(context.getDomain()).thenReturn(dom);
when(context.getAccount()).thenReturn(acc);
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(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));
}
@ -215,7 +253,7 @@ public class NuageVspElementTest {
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
when(domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
final ApplyStaticNatVspAnswer answer = mock(ApplyStaticNatVspAnswer.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>()));
@ -244,7 +282,7 @@ public class NuageVspElementTest {
when(domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
final ApplyAclRuleVspAnswer answer = mock(ApplyAclRuleVspAnswer.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>()));
@ -272,9 +310,44 @@ public class NuageVspElementTest {
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
when(domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
final ApplyAclRuleVspAnswer answer = mock(ApplyAclRuleVspAnswer.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>()));
}
@Test
public void testShutdownVpc() throws Exception {
final Vpc vpc = mock(Vpc.class);
when(vpc.getUuid()).thenReturn("aaaaaa");
when(vpc.getState()).thenReturn(Vpc.State.Inactive);
when(vpc.getDomainId()).thenReturn(NETWORK_ID);
when(vpc.getZoneId()).thenReturn(NETWORK_ID);
final DomainVO dom = mock(DomainVO.class);
when(dom.getName()).thenReturn("domain");
when(domainDao.findById(NETWORK_ID)).thenReturn(dom);
final Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
final ReservationContext context = mock(ReservationContext.class);
when(context.getDomain()).thenReturn(dom);
when(context.getAccount()).thenReturn(acc);
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));
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);
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));
}
}

View File

@ -19,29 +19,9 @@
package com.cloud.network.guru;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.junit.Before;
import org.junit.Test;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.guru.ImplementNetworkVspAnswer;
import com.cloud.agent.api.guru.ReleaseVmVspAnswer;
import com.cloud.agent.api.guru.ReserveVmInterfaceVspAnswer;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO;
@ -63,11 +43,13 @@ import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.Mode;
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.NetworkVO;
import com.cloud.network.dao.NuageVspDao;
import com.cloud.network.dao.PhysicalNetworkDao;
import com.cloud.network.dao.PhysicalNetworkVO;
import com.cloud.network.manager.NuageVspManager;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
@ -79,9 +61,28 @@ import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
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;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class NuageVspGuestNetworkGuruTest {
private static final long NETWORK_ID = 42L;
@ -98,6 +99,9 @@ public class NuageVspGuestNetworkGuruTest {
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);
NetworkDao netdao = mock(NetworkDao.class);
NuageVspGuestNetworkGuru guru;
@ -105,7 +109,7 @@ public class NuageVspGuestNetworkGuruTest {
@Before
public void setUp() {
guru = new NuageVspGuestNetworkGuru();
((GuestNetworkGuru)guru)._physicalNetworkDao = physnetdao;
guru._physicalNetworkDao = physnetdao;
guru._physicalNetworkDao = physnetdao;
guru._nuageVspDao = nuageVspDao;
guru._dcDao = dcdao;
@ -119,12 +123,19 @@ public class NuageVspGuestNetworkGuruTest {
guru._domainDao = domainDao;
guru._nicDao = nicDao;
guru._ntwkOfferingDao = ntwkOfferDao;
guru._configDao = configDao;
guru._ipAddressDao = ipAddressDao;
guru._nuageVspManager = nuageVspManager;
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(configDao.getValue(NuageVspIsolatedNetworkDomainTemplateName.key())).thenReturn("IsolatedDomainTemplate");
when(configDao.getValue(NuageVspVpcDomainTemplateName.key())).thenReturn("VpcDomainTemplate");
when(configDao.getValue(NuageVspSharedNetworkDomainTemplateName.key())).thenReturn("SharedDomainTemplate");
}
@Test
@ -146,10 +157,10 @@ public class NuageVspGuestNetworkGuruTest {
when(offering.getTrafficType()).thenReturn(TrafficType.Management);
assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
// Not supported: GuestType Shared
// Supported: GuestType Shared
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Shared);
assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
assertTrue(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
// Not supported: Basic networking
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
@ -236,7 +247,8 @@ public class NuageVspGuestNetworkGuruTest {
@Test
public void testReserve() throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, URISyntaxException {
final Network network = mock(Network.class);
final NetworkVO network = mock(NetworkVO.class);
when(network.getId()).thenReturn(NETWORK_ID);
when(network.getUuid()).thenReturn("aaaaaa");
when(network.getDataCenterId()).thenReturn(NETWORK_ID);
when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
@ -262,10 +274,15 @@ public class NuageVspGuestNetworkGuruTest {
when(nicvo.getUuid()).thenReturn("aaaa-fffff");
when(nicDao.findById(NETWORK_ID)).thenReturn(nicvo);
final VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
final VirtualMachine vm = mock(VirtualMachine.class);
when(vm.getId()).thenReturn(NETWORK_ID);
when(vm.getType()).thenReturn(VirtualMachine.Type.User);
when(vm.getInstanceName()).thenReturn("");
when(vm.getUuid()).thenReturn("aaaa-bbbbb");
final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
when(vmProfile.getType()).thenReturn(VirtualMachine.Type.User);
when(vmProfile.getInstanceName()).thenReturn("");
when(vmProfile.getUuid()).thenReturn("aaaa-bbbbb");
when(vmProfile.getVirtualMachine()).thenReturn(vm);
NicProfile nicProfile = mock(NicProfile.class);
when(nicProfile.getUuid()).thenReturn("aaa-bbbb");
@ -283,51 +300,20 @@ public class NuageVspGuestNetworkGuruTest {
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));
final ReserveVmInterfaceVspAnswer answer = mock(ReserveVmInterfaceVspAnswer.class);
when(answer.getResult()).thenReturn(true);
when(answer.getInterfaceDetails()).thenReturn(new ArrayList<Map<String, String>>());
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
guru.reserve(nicProfile, network, vm, mock(DeployDestination.class), mock(ReservationContext.class));
}
@Test
public void testRelease() {
final NicProfile nicProfile = mock(NicProfile.class);
when(nicProfile.getNetworkId()).thenReturn(NETWORK_ID);
final NetworkVO network = mock(NetworkVO.class);
when(network.getUuid()).thenReturn("aaaaaa-ffffff");
when(network.getName()).thenReturn("aaaaaa");
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(networkDao.findById(NETWORK_ID)).thenReturn(network);
final VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
when(vm.getType()).thenReturn(VirtualMachine.Type.User);
when(vm.getInstanceName()).thenReturn("");
when(vm.getUuid()).thenReturn("aaaa-bbbbb");
final VirtualMachine virtualMachine = mock(VirtualMachine.class);
when(vm.getVirtualMachine()).thenReturn(virtualMachine);
when(virtualMachine.getState()).thenReturn(State.Stopping);
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);
final ReleaseVmVspAnswer answer = mock(ReleaseVmVspAnswer.class);
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
guru.release(nicProfile, vm, "aaaaa-fffff");
guru.reserve(nicProfile, network, vmProfile, mock(DeployDestination.class), mock(ReservationContext.class));
}
@Test
public void testImplementNetwork() throws URISyntaxException, InsufficientVirtualNetworkCapacityException {
final Network network = mock(Network.class);
final NetworkVO network = mock(NetworkVO.class);
when(network.getId()).thenReturn(NETWORK_ID);
when(network.getUuid()).thenReturn("aaaaaa");
when(network.getDataCenterId()).thenReturn(NETWORK_ID);
@ -371,8 +357,11 @@ public class NuageVspGuestNetworkGuruTest {
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>());
final ImplementNetworkVspAnswer answer = mock(ImplementNetworkVspAnswer.class);
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
@ -383,4 +372,95 @@ public class NuageVspGuestNetworkGuruTest {
guru.implement(network, offering, deployDest, reserveContext);
}
@Test
public void testDeallocate() throws Exception {
final NetworkVO network = mock(NetworkVO.class);
when(network.getId()).thenReturn(NETWORK_ID);
when(network.getUuid()).thenReturn("aaaaaa");
when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
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);
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);
final DomainVO domain = mock(DomainVO.class);
when(domain.getUuid()).thenReturn("aaaaaa");
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);
final NicProfile nicProfile = mock(NicProfile.class);
when(nicProfile.getId()).thenReturn(NETWORK_ID);
when(nicProfile.getIPv4Address()).thenReturn("10.10.10.10");
when(nicProfile.getMacAddress()).thenReturn("c8:60:00:56:e5:58");
final VirtualMachine vm = mock(VirtualMachine.class);
when(vm.getType()).thenReturn(VirtualMachine.Type.User);
when(vm.getState()).thenReturn(VirtualMachine.State.Expunging);
final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
when(vmProfile.getUuid()).thenReturn("aaaaaa");
when(vmProfile.getInstanceName()).thenReturn("Test-VM");
when(vmProfile.getVirtualMachine()).thenReturn(vm);
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);
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
guru.deallocate(network, nicProfile, vmProfile);
}
@Test
public void testTrash() throws Exception {
final NetworkVO network = mock(NetworkVO.class);
when(network.getId()).thenReturn(NETWORK_ID);
when(network.getUuid()).thenReturn("aaaaaa");
when(network.getName()).thenReturn("trash");
when(network.getDomainId()).thenReturn(NETWORK_ID);
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);
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);
final DomainVO domain = mock(DomainVO.class);
when(domain.getUuid()).thenReturn("aaaaaa");
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>());
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
assertTrue(guru.trash(network, offering));
}
}

View File

@ -19,16 +19,9 @@
package com.cloud.network.manager;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import javax.naming.ConfigurationException;
import org.junit.Before;
import org.junit.Test;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer;
import com.cloud.api.commands.DeleteNuageVspDeviceCmd;
import com.cloud.api.commands.ListNuageVspDevicesCmd;
import com.cloud.host.HostVO;
@ -42,6 +35,18 @@ import com.cloud.network.dao.PhysicalNetworkDao;
import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
import com.cloud.network.dao.PhysicalNetworkVO;
import com.cloud.resource.ResourceManager;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import org.junit.Before;
import org.junit.Test;
import javax.naming.ConfigurationException;
import java.util.ArrayList;
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 NuageVspManagerTest {
private static final long NETWORK_ID = 42L;
@ -53,6 +58,8 @@ public class NuageVspManagerTest {
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;
@ -67,6 +74,8 @@ public class NuageVspManagerTest {
manager._nuageVspDao = nuageVspDao;
manager._networkDao = networkDao;
manager._hostDao = hostDao;
manager._agentMgr = agentManager;
manager._configDao = configDao;
}
@Test
@ -91,6 +100,14 @@ public class NuageVspManagerTest {
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);
final SyncNuageVspCmsIdAnswer answer = mock(SyncNuageVspCmsIdAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
manager.deleteNuageVspDevice(cmd);
}

View File

@ -19,46 +19,35 @@
package com.cloud.network.resource;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.PingCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.element.ApplyAclRuleVspCommand;
import com.cloud.agent.api.element.ApplyStaticNatVspCommand;
import com.cloud.agent.api.element.ShutDownVpcVspCommand;
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.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 org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import com.cloud.agent.api.PingCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.element.ApplyAclRuleVspAnswer;
import com.cloud.agent.api.element.ApplyAclRuleVspCommand;
import com.cloud.agent.api.element.ApplyStaticNatVspAnswer;
import com.cloud.agent.api.element.ApplyStaticNatVspCommand;
import com.cloud.agent.api.element.ShutDownVpcVspAnswer;
import com.cloud.agent.api.element.ShutDownVpcVspCommand;
import com.cloud.agent.api.guru.DeallocateVmVspAnswer;
import com.cloud.agent.api.guru.DeallocateVmVspCommand;
import com.cloud.agent.api.guru.ImplementNetworkVspAnswer;
import com.cloud.agent.api.guru.ImplementNetworkVspCommand;
import com.cloud.agent.api.guru.ReleaseVmVspAnswer;
import com.cloud.agent.api.guru.ReleaseVmVspCommand;
import com.cloud.agent.api.guru.ReserveVmInterfaceVspAnswer;
import com.cloud.agent.api.guru.ReserveVmInterfaceVspCommand;
import com.cloud.agent.api.guru.TrashNetworkVspAnswer;
import com.cloud.agent.api.guru.TrashNetworkVspCommand;
import com.cloud.agent.api.sync.SyncVspAnswer;
import com.cloud.agent.api.sync.SyncVspCommand;
import com.cloud.host.Host;
import javax.naming.ConfigurationException;
import java.util.ArrayList;
import java.util.Collections;
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;
@ -66,9 +55,10 @@ public class NuageVspResourceTest {
NuageVspElementClient _mockNuageVspElementClient = mock(NuageVspElementClient.class);
NuageVspGuruClient _mockNuageVspGuruClient = mock(NuageVspGuruClient.class);
NuageVspSyncClient _mockNuageVspSyncClient = mock(NuageVspSyncClient.class);
Map<String, Object> _parameters;
NuageVspResource.Configuration _resourceConfiguration;
Map<String, Object> _hostDetails;
Answer<Object> genericAnswer = new Answer<Object>() {
org.mockito.stubbing.Answer<Object> genericAnswer = new org.mockito.stubbing.Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
return null;
}
@ -88,34 +78,36 @@ public class NuageVspResourceTest {
}
protected void isNuageVspApiLoaded() throws Exception {
protected void isNuageVspApiLoaded() throws ConfigurationException {
}
protected void isNuageVspGuruLoaded() throws Exception {
protected void isNuageVspGuruLoaded() throws ConfigurationException {
}
protected void isNuageVspElementLoaded() throws Exception {
protected void isNuageVspElementLoaded() throws ConfigurationException {
}
protected void isNuageVspSyncLoaded() throws Exception {
protected void isNuageVspSyncLoaded() throws ConfigurationException {
}
protected void login() throws Exception {
protected void login() throws ConfigurationException {
}
};
_parameters = new HashMap<String, Object>();
_parameters.put("name", "nuagevsptestdevice");
_parameters.put("guid", "aaaaa-bbbbb-ccccc");
_parameters.put("zoneId", "blublub");
_parameters.put("hostname", "nuagevsd");
_parameters.put("cmsuser", "cmsuser");
_parameters.put("cmsuserpass", "cmsuserpass");
_parameters.put("port", "8443");
_parameters.put("apirelativepath", "nuage/api/v1_0");
_parameters.put("retrycount", "3");
_parameters.put("retryinterval", "3");
_resourceConfiguration = new NuageVspResource.Configuration()
.name("nuagevsptestdevice")
.guid("aaaaa-bbbbb-ccccc")
.zoneId("blublub")
.hostName("nuagevsd")
.cmsUser("cmsuser")
.cmsUserPassword("cmsuserpass")
.port("8443")
.apiVersion("v3_2")
.apiRelativePath("nuage/api/v3_2")
.retryCount("3")
.retryInterval("3");
_hostDetails = Maps.<String, Object>newHashMap(_resourceConfiguration.build());
}
@Test(expected = Exception.class)
@ -125,7 +117,7 @@ public class NuageVspResourceTest {
@Test
public void resourceConfigure() throws Exception {
_resource.configure("NuageVspResource", _parameters);
_resource.configure("NuageVspResource", _hostDetails);
assertTrue("nuagevsptestdevice".equals(_resource.getName()));
assertTrue(_resource.getType() == Host.Type.L2Networking);
@ -133,7 +125,7 @@ public class NuageVspResourceTest {
@Test
public void testInitialization() throws Exception {
_resource.configure("NuageVspResource", _parameters);
_resource.configure("NuageVspResource", _hostDetails);
StartupCommand[] sc = _resource.initialize();
assertTrue(sc.length == 1);
@ -144,7 +136,7 @@ public class NuageVspResourceTest {
@Test
public void testPingCommandStatus() throws Exception {
_resource.configure("NuageVspResource", _parameters);
_resource.configure("NuageVspResource", _hostDetails);
PingCommand ping = _resource.getCurrentStatus(42);
assertTrue(ping != null);
@ -154,99 +146,102 @@ public class NuageVspResourceTest {
@Test
public void testImplementNetworkVspCommand() throws Exception {
_resource.configure("NuageVspResource", _parameters);
_resource.configure("NuageVspResource", _hostDetails);
ImplementNetworkVspCommand impNtwkCmd = new ImplementNetworkVspCommand("networkDomainName", "networkDomainPath", "networkDomainUuid", "networkAccountName",
"networkAccountUuid", "networkName", "networkCidr", "networkGateway", "networkUuid", true, "vpcName", "vpcUuid", true, new ArrayList<String>());
doAnswer(genericAnswer).when(_mockNuageVspGuruClient).implement("networkDomainName", "networkDomainPath", "networkDomainUuid", "networkAccountName", "networkAccountUuid",
"networkName", "networkCidr", "networkGateway", "networkUuid", true, "vpcName", "vpcUuid", true, new ArrayList<String>());
ImplementNetworkVspAnswer implNtwkAns = (ImplementNetworkVspAnswer)_resource.executeRequest(impNtwkCmd);
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());
assertTrue(implNtwkAns.getResult());
}
@Test
public void testReserveVmInterfaceVspCommand() throws Exception {
_resource.configure("NuageVspResource", _parameters);
_resource.configure("NuageVspResource", _hostDetails);
ReserveVmInterfaceVspCommand rsrvVmInfCmd = new ReserveVmInterfaceVspCommand("nicUuid", "nicMacAddress", "networkUuid", true, "vpcUuid", "networkDomainUuid",
"networksAccountUuid", false, "domainRouterIp", "vmInstanceName", "vmUuid", "vmUserName", "vmUserDomainName");
doAnswer(genericAnswer).when(_mockNuageVspGuruClient).reserve("nicUuid", "nicMacAddress", "networkUuid", true, "vpcUuid", "networkDomainUuid", "networksAccountUuid",
false, "domainRouterIp", "vmInstanceName", "vmUuid");
ReserveVmInterfaceVspAnswer rsrvVmInfAns = (ReserveVmInterfaceVspAnswer)_resource.executeRequest(rsrvVmInfCmd);
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());
assertTrue(rsrvVmInfAns.getResult());
}
@Test
public void testReleaseVmVspCommand() throws Exception {
_resource.configure("NuageVspResource", _parameters);
ReleaseVmVspCommand releaseVmCmd = new ReleaseVmVspCommand("networkUuid", "vmUuid", "vmInstanceName");
doAnswer(genericAnswer).when(_mockNuageVspGuruClient).release("networkUuid", "vmUuid", "vmInstanceName");
ReleaseVmVspAnswer releaseVmAns = (ReleaseVmVspAnswer)_resource.executeRequest(releaseVmCmd);
assertTrue(releaseVmAns.getResult());
}
@Test
public void testDeallocateVmVspCommand() throws Exception {
_resource.configure("NuageVspResource", _parameters);
_resource.configure("NuageVspResource", _hostDetails);
DeallocateVmVspCommand dellocateVmCmd = new DeallocateVmVspCommand("networkUuid", "nicFrmDdUuid", "nicMacAddress", "nicIp4Address", true, "vpcUuid", "networksDomainUuid",
"vmInstanceName", "vmUuid");
doAnswer(genericAnswer).when(_mockNuageVspGuruClient).deallocate("networkUuid", "nicFrmDdUuid", "nicMacAddress", "nicIp4Address", true, "vpcUuid", "networksDomainUuid",
"vmInstanceName", "vmUuid");
DeallocateVmVspAnswer dellocateVmAns = (DeallocateVmVspAnswer)_resource.executeRequest(dellocateVmCmd);
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());
assertTrue(dellocateVmAns.getResult());
}
@Test
public void testTrashNetworkVspCommand() throws Exception {
_resource.configure("NuageVspResource", _parameters);
_resource.configure("NuageVspResource", _hostDetails);
TrashNetworkVspCommand trashNtwkCmd = new TrashNetworkVspCommand("domainUuid", "networkUuid", true, "vpcUuid");
doAnswer(genericAnswer).when(_mockNuageVspGuruClient).trash("domainUuid", "networkUuid", true, "vpcUuid");
TrashNetworkVspAnswer trashNtwkAns = (TrashNetworkVspAnswer)_resource.executeRequest(trashNtwkCmd);
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());
assertTrue(trashNtwkAns.getResult());
}
@Test
public void testApplyStaticNatVspCommand() throws Exception {
_resource.configure("NuageVspResource", _parameters);
_resource.configure("NuageVspResource", _hostDetails);
ApplyStaticNatVspCommand applyNatCmd = new ApplyStaticNatVspCommand("networkDomainUuid", "vpcOrSubnetUuid", true, new ArrayList<Map<String, Object>>());
doAnswer(genericAnswer).when(_mockNuageVspElementClient).applyStaticNats("networkDomainUuid", "vpcOrSubnetUuid", true, new ArrayList<Map<String, Object>>());
ApplyStaticNatVspAnswer applyNatAns = (ApplyStaticNatVspAnswer)_resource.executeRequest(applyNatCmd);
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());
assertTrue(applyNatAns.getResult());
}
@Test
public void testApplyAclRuleVspCommand() throws Exception {
_resource.configure("NuageVspResource", _parameters);
_resource.configure("NuageVspResource", _hostDetails);
ApplyAclRuleVspCommand applyAclCmd = new ApplyAclRuleVspCommand("networkUuid", "networkDomainUuid", "vpcOrSubnetUuid", true, new ArrayList<Map<String, Object>>(), false,
100);
doAnswer(genericAnswer).when(_mockNuageVspElementClient).applyAclRules("networkUuid", "networkDomainUuid", "vpcOrSubnetUuid", true, new ArrayList<Map<String, Object>>(),
false, 100);
ApplyAclRuleVspAnswer applyAclAns = (ApplyAclRuleVspAnswer)_resource.executeRequest(applyAclCmd);
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());
assertTrue(applyAclAns.getResult());
}
@Test
public void testShutDownVpcVspCommand() throws Exception {
_resource.configure("NuageVspResource", _parameters);
_resource.configure("NuageVspResource", _hostDetails);
ShutDownVpcVspCommand shutVpcCmd = new ShutDownVpcVspCommand("domainUuid", "vpcUuid");
doAnswer(genericAnswer).when(_mockNuageVspElementClient).shutDownVpc("domainUuid", "vpcUuid");
ShutDownVpcVspAnswer shutVpcAns = (ShutDownVpcVspAnswer)_resource.executeRequest(shutVpcCmd);
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", _parameters);
_resource.configure("NuageVspResource", _hostDetails);
SyncVspCommand shutVpcCmd = new SyncVspCommand("nuageVspEntity");
doAnswer(genericAnswer).when(_mockNuageVspSyncClient).syncWithNuageVsp("nuageVspEntity");
SyncVspAnswer shutVpcAns = (SyncVspAnswer)_resource.executeRequest(shutVpcCmd);
Answer shutVpcAns = _resource.executeRequest(shutVpcCmd);
assertTrue(shutVpcAns.getResult());
}
}

View File

@ -19,23 +19,22 @@
package com.cloud.network.sync;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.sync.SyncVspAnswer;
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;
@ -64,7 +63,7 @@ public class NuageVspSyncTest {
when(host.getId()).thenReturn(NETWORK_ID);
when(hostDao.findById(NETWORK_ID)).thenReturn(host);
final SyncVspAnswer answer = mock(SyncVspAnswer.class);
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(agentManager.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);

View File

@ -4602,10 +4602,11 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati
@Override
public boolean isOfferingForVpc(final NetworkOffering offering) {
final boolean vpcProvider = _ntwkOffServiceMapDao.isProviderForNetworkOffering(offering.getId(), Provider.VPCVirtualRouter) ||
_ntwkOffServiceMapDao.isProviderForNetworkOffering(offering.getId(), Provider.JuniperContrailVpcRouter) ||
_ntwkOffServiceMapDao.getDistinctProviders(offering.getId()).contains(Provider.NuageVsp.getName());
_ntwkOffServiceMapDao.isProviderForNetworkOffering(offering.getId(), Provider.JuniperContrailVpcRouter);
final boolean nuageVpcProvider = _ntwkOffServiceMapDao.getDistinctProviders(offering.getId()).contains(Provider.NuageVsp.getName())
&& offering.getIsPersistent();
return vpcProvider;
return vpcProvider || nuageVpcProvider;
}
@Override

View File

@ -21,6 +21,7 @@ import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.log4j.Logger;
@ -98,6 +99,8 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
NicDao _nicDao;
@Inject
IpAddressManager _ipAddrMgr;
@Inject
NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao;
private static final TrafficType[] TrafficTypes = {TrafficType.Guest};
@ -118,7 +121,8 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
// this guru handles only Guest networks in Advance zone with source nat service disabled
if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && offering.getGuestType() == GuestType.Shared) {
if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && offering.getGuestType() == GuestType.Shared
&& !_ntwkOfferingSrvcDao.isProviderForNetworkOffering(offering.getId(), Network.Provider.NuageVsp)) {
return true;
} else {
s_logger.trace("We only take care of Guest networks of type " + GuestType.Shared);

View File

@ -23,7 +23,11 @@ from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackAPI import (listPhysicalNetworks,
listNetworkServiceProviders,
addNetworkServiceProvider,
addNuageVspDevice)
deleteNetworkServiceProvider,
deleteNuageVspDevice,
updateNetworkServiceProvider,
addNuageVspDevice,
destroyVirtualMachine)
from marvin.lib.utils import (cleanup_resources)
from marvin.lib.base import (Account,
VirtualMachine,
@ -34,6 +38,9 @@ from marvin.lib.common import (get_domain,
get_zone,
get_template)
import logging
import unittest
class Services:
@ -41,12 +48,13 @@ class Services:
"""
def __init__(self):
print "in __init__"
self.services = {
"account": {
"email": "cloudstack@cloudmonkey.com",
"firstname": "cloudstack",
"lastname": "bob",
"username": "bobbuilder",
"username": "admin",
"password": "password",
},
"service_offering": {
@ -61,17 +69,17 @@ class Services:
"username": "root",
"password": "password",
"ssh_port": 22,
"hypervisor": 'XenServer',
"hypervisor": 'KVM',
"privateport": 22,
"publicport": 22,
"protocol": 'TCP',
},
"nuage_vsp_device": {
"hostname": '192.168.0.7',
"username": 'testusername',
"password": 'testpassword',
"hostname": '172.31.222.162',
"username": 'cloudstackuser1',
"password": 'cloudstackuser1',
"port": '8443',
"apiversion": 'v1_0',
"apiversion": 'v3_2',
"retrycount": '4',
"retryinterval": '60'
},
@ -92,12 +100,15 @@ class Services:
"SourceNat": 'NuageVsp',
"Firewall": 'NuageVsp'
},
"serviceCapabilityList": {
"SourceNat": {"SupportedSourceNatTypes": "perzone"},
}
},
"network": {
"name": "nuage",
"displaytext": "nuage",
},
"ostype": 'CentOS 5.3 (64-bit)',
"ostype": 'CentOS 5.5 (64-bit)',
"sleep": 60,
"timeout": 10
}
@ -107,6 +118,7 @@ class TestNuageVsp(cloudstackTestCase):
@classmethod
def setUpClass(cls):
print "In setup class"
cls._cleanup = []
cls.testClient = super(TestNuageVsp, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient()
@ -125,10 +137,14 @@ class TestNuageVsp(cloudstackTestCase):
try:
resp = listPhysicalNetworks.listPhysicalNetworksCmd()
print "in cls.setupClass- resp: %s" % resp
resp.zoneid = cls.zone.id
physical_networks = cls.api_client.listPhysicalNetworks(resp)
if isinstance(physical_networks, list):
physical_network = physical_networks[0]
for pn in physical_networks:
if pn.isolationmethods=='VSP':
physical_network = pn
#if isinstance(physical_networks, list):
# physical_network = physical_networks[1]
resp = listNetworkServiceProviders.listNetworkServiceProvidersCmd()
resp.name = 'NuageVsp'
resp.physicalnetworkid = physical_network.id
@ -141,11 +157,17 @@ class TestNuageVsp(cloudstackTestCase):
resp_add_nsp.name = 'NuageVsp'
resp_add_nsp.physicalnetworkid = physical_network.id
cls.api_client.addNetworkServiceProvider(resp_add_nsp)
#Get NSP ID
nw_service_providers = cls.api_client.listNetworkServiceProviders(
resp)
cls.debug("NuageVsp NSP ID: %s" % nw_service_providers[0].id)
resp_add_device = addNuageVspDevice.addNuageVspDeviceCmd()
resp_add_device.physicalnetworkid = physical_network.id
resp_add_device.username = cls.nuage_services["username"]
resp_add_device.password = cls.nuage_services["password"]
resp_add_device.hostname = cls.nuage_services["hostname"]
resp_add_device.port = cls.nuage_services["port"]
resp_add_device.apiversion = cls.nuage_services[
"apiversion"]
resp_add_device.retrycount = cls.nuage_services[
@ -154,6 +176,13 @@ class TestNuageVsp(cloudstackTestCase):
"retryinterval"]
cls.nuage = cls.api_client.addNuageVspDevice(
resp_add_device)
#Enable NuageVsp NSP
cls.debug("NuageVsp NSP ID : %s" % nw_service_providers[0].id)
resp_up_nsp = \
updateNetworkServiceProvider.updateNetworkServiceProviderCmd()
resp_up_nsp.id = nw_service_providers[0].id
resp_up_nsp.state = 'Enabled'
cls.api_client.updateNetworkServiceProvider(resp_up_nsp)
cls.network_offering = NetworkOffering.create(
cls.api_client,
@ -172,7 +201,7 @@ class TestNuageVsp(cloudstackTestCase):
cls._cleanup.append(cls.service_offering)
except Exception as e:
cls.tearDownClass()
raise Exception("Warning: Exception in setUpClass: %s" % e)
raise unittest.SkipTest("Unable to add VSP device")
return
@classmethod
@ -183,6 +212,7 @@ class TestNuageVsp(cloudstackTestCase):
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
@ -195,6 +225,7 @@ class TestNuageVsp(cloudstackTestCase):
self.cleanup = [self.account]
return
def tearDown(self):
try:
self.debug("Cleaning up the resources")
@ -204,7 +235,7 @@ class TestNuageVsp(cloudstackTestCase):
raise Exception("Warning: Exception during cleanup : %s" % e)
return
@attr(tags=["invalid"])
@attr(tags=["advanced"])
def test_network_vsp(self):
"""Test nuage Network and VM Creation
"""
@ -217,7 +248,9 @@ class TestNuageVsp(cloudstackTestCase):
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering.id,
zoneid=self.zone.id
zoneid=self.zone.id,
gateway = "10.1.1.1",
netmask = '255.255.255.0'
)
self.debug("Created network with ID: %s" % self.network.id)
@ -292,7 +325,7 @@ class TestNuageVsp(cloudstackTestCase):
VirtualMachine.delete(virtual_machine_1, self.apiclient, expunge=True)
# Deleting a single VM
# # Deleting a single VM
VirtualMachine.delete(virtual_machine_2, self.apiclient, expunge=True)
# Delete Network

View File

@ -0,0 +1,295 @@
# 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.
""" Tests for NuageNetwork VPC
"""
#Import Local Modules
from marvin.cloudstackTestCase import cloudstackTestCase, unittest
from marvin.lib.utils import (cleanup_resources)
from marvin.cloudstackAPI import (listPhysicalNetworks,
listNetworkServiceProviders,
addNetworkServiceProvider,
updateNetworkServiceProvider,
addNuageVspDevice,
destroyVirtualMachine)
from marvin.lib.base import (VirtualMachine,
ServiceOffering,
Account,
NetworkOffering,
Network,
VPC,
VpcOffering,
NetworkACL,
NetworkACLList)
from marvin.lib.common import (get_zone,
get_domain,
get_template,
wait_for_cleanup,
list_networks)
from nose.plugins.attrib import attr
class Services:
"""Test NuageVsp plugin
"""
def __init__(self):
self.services = {
"account": {
"email": "cloudstack@cloudmonkey.com",
"firstname": "cloudstack",
"lastname": "bob",
"username": "admin",
"password": "password",
},
"service_offering": {
"name": "Tiny Instance",
"displaytext": "Tiny Instance",
"cpunumber": 1,
"cpuspeed": 100, # in MHz
"memory": 128, # In MBs
},
"virtual_machine": {
"displayname": "TestVM",
"username": "root",
"password": "password",
"ssh_port": 22,
"hypervisor": 'KVM',
"privateport": 22,
"publicport": 22,
"protocol": 'TCP',
},
"nuage_vsp_device": {
#"hostname": '192.168.0.7',
#"hostname": '10.31.43.226',
"hostname": '172.31.222.162',
"username": 'cloudstackuser1',
"password": 'cloudstackuser1',
"port": '8443',
"apiversion": 'v3_2',
"retrycount": '4',
"retryinterval": '60'
},
# services supported by Nuage for VPC networks.
"vpc_network_offering": {
"name": 'nuage_vpc_marvin',
"displaytext": 'nuage_vpc_marvin',
"guestiptype": 'Isolated',
"supportedservices": 'UserData,Dhcp,SourceNat,StaticNat,NetworkACL,Connectivity',
"traffictype": 'GUEST',
"useVpc": 'on',
"serviceProviderList": {
"Dhcp": "NuageVsp",
"SourceNat": "NuageVsp",
"StaticNat": "NuageVsp",
"NetworkACL": "NuageVsp",
"UserData": "VpcVirtualRouter",
"Connectivity": "NuageVsp"
},
"serviceCapabilityList": {
"SourceNat": {"SupportedSourceNatTypes": "perzone"}
}
},
"vpc": {
"name": "vpc-networkacl-nuage",
"displaytext": "vpc-networkacl-nuage",
"cidr": '10.1.0.0/16'
},
"vpcnetwork": {
"name": "nuagevpcnetwork",
"displaytext": "nuagevpcnetwork",
"netmask": '255.255.255.128'
},
"ostype": 'CentOS 5.5 (64-bit)',
"sleep": 60,
"timeout": 10
}
class TestVpcNetworkNuage(cloudstackTestCase):
@classmethod
def setUpClass(cls):
cls._cleanup = []
cls.testClient = super(TestVpcNetworkNuage, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient()
cls.services = Services().services
# Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
cls.template = get_template(
cls.api_client,
cls.zone.id,
cls.services["ostype"]
)
# nuage vsp device brings the Nuage virtual service platform into play
cls.nuage_services = cls.services["nuage_vsp_device"]
try:
resp = listPhysicalNetworks.listPhysicalNetworksCmd()
print "in cls.setupClass- resp: %s" % resp
resp.zoneid = cls.zone.id
physical_networks = cls.api_client.listPhysicalNetworks(resp)
for pn in physical_networks:
if pn.isolationmethods=='VSP':
physical_network = pn
#if isinstance(physical_networks, list):
# physical_network = physical_networks[1]
resp = listNetworkServiceProviders.listNetworkServiceProvidersCmd()
resp.name = 'NuageVsp'
resp.physicalnetworkid = physical_network.id
nw_service_providers = cls.api_client.listNetworkServiceProviders(
resp)
if not isinstance(nw_service_providers, list):
# create network service provider and add nuage vsp device
resp_add_nsp = \
addNetworkServiceProvider.addNetworkServiceProviderCmd()
resp_add_nsp.name = 'NuageVsp'
resp_add_nsp.physicalnetworkid = physical_network.id
cls.api_client.addNetworkServiceProvider(resp_add_nsp)
#Get NSP ID
nw_service_providers = cls.api_client.listNetworkServiceProviders(
resp)
cls.debug("NuageVsp NSP ID: %s" % nw_service_providers[0].id)
resp_add_device = addNuageVspDevice.addNuageVspDeviceCmd()
resp_add_device.physicalnetworkid = physical_network.id
resp_add_device.username = cls.nuage_services["username"]
resp_add_device.password = cls.nuage_services["password"]
resp_add_device.hostname = cls.nuage_services["hostname"]
resp_add_device.port = cls.nuage_services["port"]
resp_add_device.apiversion = cls.nuage_services[
"apiversion"]
resp_add_device.retrycount = cls.nuage_services[
"retrycount"]
resp_add_device.retryinterval = cls.nuage_services[
"retryinterval"]
cls.nuage = cls.api_client.addNuageVspDevice(
resp_add_device)
#Enable NuageVsp NSP
cls.debug("NuageVsp NSP ID : %s" % nw_service_providers[0].id)
resp_up_nsp = \
updateNetworkServiceProvider.updateNetworkServiceProviderCmd()
resp_up_nsp.id = nw_service_providers[0].id
resp_up_nsp.state = 'Enabled'
cls.api_client.updateNetworkServiceProvider(resp_up_nsp)
cls.network_offering = NetworkOffering.create(
cls.api_client,
cls.services["vpc_network_offering"],
conservemode=False
)
cls._cleanup.append(cls.network_offering)
cls.network_offering.update(cls.api_client, state='Enabled')
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["virtual_machine"]["template"] = cls.template.id
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offering"]
)
cls._cleanup.append(cls.service_offering)
except Exception as e:
cls.tearDownClass()
raise unittest.SkipTest("Unable to add VSP device")
return
@attr(tags=["advanced"])
def test_vpcnetwork_nuage(self):
"""Test network VPC for Nuage"""
# 1) Create VPC with Nuage VPC offering
vpcOffering = VpcOffering.list(self.apiclient,name="Nuage VSP VPC offering")
self.assert_(vpcOffering is not None and len(vpcOffering)>0, "Nuage VPC offering not found")
vpc = VPC.create(
apiclient=self.apiclient,
services=self.services["vpc"],
networkDomain="vpc.networkacl",
vpcofferingid=vpcOffering[0].id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.account.domainid
)
self.assert_(vpc is not None, "VPC creation failed")
# 2) Create ACL
aclgroup = NetworkACLList.create(apiclient=self.apiclient, services={}, name="acl", description="acl", vpcid=vpc.id)
self.assertIsNotNone(aclgroup, "Failed to create NetworkACL list")
self.debug("Created a network ACL list %s" % aclgroup.name)
# 3) Create ACL Item
aclitem = NetworkACL.create(apiclient=self.apiclient, services={},
protocol="TCP", number="10", action="Deny", aclid=aclgroup.id, cidrlist=["0.0.0.0/0"])
self.assertIsNotNone(aclitem, "Network failed to aclItem")
self.debug("Added a network ACL %s to ACL list %s" % (aclitem.id, aclgroup.name))
# 4) Create network with ACL
nwNuage = Network.create(
self.apiclient,
self.services["vpcnetwork"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering.id,
zoneid=self.zone.id,
vpcid=vpc.id,
aclid=aclgroup.id,
gateway='10.1.0.1'
)
self.debug("Network %s created in VPC %s" %(nwNuage.id, vpc.id))
# 5) Deploy a vm
vm = VirtualMachine.create(
self.apiclient,
self.services["virtual_machine"],
accountid=self.account.name,
domainid=self.account.domainid,
serviceofferingid=self.service_offering.id,
networkids=[str(nwNuage.id)]
)
self.assert_(vm is not None, "VM failed to deploy")
self.assert_(vm.state == 'Running', "VM is not running")
self.debug("VM %s deployed in VPC %s" %(vm.id, vpc.id))
@classmethod
def tearDownClass(cls):
try:
cleanup_resources(cls.api_client, cls._cleanup)
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return
def setUp(self):
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
self.account = Account.create(
self.apiclient,
self.services["account"],
admin=True,
domainid=self.domain.id
)
self.cleanup = [self.account]
return
def tearDown(self):
try:
self.debug("Cleaning up the resources")
cleanup_resources(self.apiclient, self.cleanup)
self.debug("Cleanup complete!")
except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e)
return