use of com.cloud.network.vpc.Vpc in project cloudstack by apache.
the class ApiResponseHelper method createNetworkACLResponse.
@Override
public NetworkACLResponse createNetworkACLResponse(NetworkACL networkACL) {
NetworkACLResponse response = new NetworkACLResponse();
response.setId(networkACL.getUuid());
response.setName(networkACL.getName());
response.setDescription(networkACL.getDescription());
response.setForDisplay(networkACL.isDisplay());
Vpc vpc = ApiDBUtils.findVpcById(networkACL.getVpcId());
if (vpc != null) {
response.setVpcId(vpc.getUuid());
}
response.setObjectName("networkacllist");
return response;
}
use of com.cloud.network.vpc.Vpc in project cloudstack by apache.
the class GuestNetworkGuru method allocate.
@Override
public NicProfile allocate(final Network network, NicProfile nic, final VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
assert network.getTrafficType() == TrafficType.Guest : "Look at my name! Why are you calling" + " me when the traffic type is : " + network.getTrafficType();
if (nic == null) {
nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
}
final DataCenter dc = _dcDao.findById(network.getDataCenterId());
if (nic.getIPv4Address() == null) {
nic.setBroadcastUri(network.getBroadcastUri());
nic.setIsolationUri(network.getBroadcastUri());
nic.setIPv4Gateway(network.getGateway());
String guestIp = null;
if (network.getSpecifyIpRanges()) {
_ipAddrMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIPv4(), null);
} else {
//if Vm is router vm and source nat is enabled in the network, set ip4 to the network gateway
boolean isGateway = false;
if (vm.getVirtualMachine().getType() == VirtualMachine.Type.DomainRouter) {
if (network.getVpcId() != null) {
final Vpc vpc = _vpcDao.findById(network.getVpcId());
// Redundant Networks need a guest IP that is not the same as the gateway IP.
if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.VPCVirtualRouter) && !vpc.isRedundant()) {
isGateway = true;
}
} else {
if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.VirtualRouter)) {
isGateway = true;
}
}
}
if (isGateway) {
guestIp = network.getGateway();
} else {
guestIp = _ipAddrMgr.acquireGuestIpAddress(network, nic.getRequestedIPv4());
if (guestIp == null) {
throw new InsufficientVirtualNetworkCapacityException("Unable to acquire Guest IP" + " address for network " + network, DataCenter.class, dc.getId());
}
}
nic.setIPv4Address(guestIp);
nic.setIPv4Netmask(NetUtils.cidr2Netmask(network.getCidr()));
nic.setIPv4Dns1(dc.getDns1());
nic.setIPv4Dns2(dc.getDns2());
nic.setFormat(AddressFormat.Ip4);
}
}
nic.setReservationStrategy(ReservationStrategy.Start);
if (nic.getMacAddress() == null) {
nic.setMacAddress(_networkModel.getNextAvailableMacAddressInNetwork(network.getId()));
if (nic.getMacAddress() == null) {
throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses", Network.class, network.getId());
}
}
return nic;
}
use of com.cloud.network.vpc.Vpc in project cloudstack by apache.
the class BigSwitchBcfGuestNetworkGuru method prepareMigration.
@Override
public boolean prepareMigration(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) {
bcfUtilsInit();
// get arguments for CreateBcfAttachmentCommand
// determine whether this is VPC network or stand-alone network
Vpc vpc = null;
if (network.getVpcId() != null) {
vpc = _vpcDao.acquireInLockTable(network.getVpcId());
}
String networkId = network.getUuid();
String tenantId;
String tenantName;
if (vpc != null) {
tenantId = vpc.getUuid();
tenantName = vpc.getName();
boolean released = _vpcDao.releaseFromLockTable(vpc.getId());
s_logger.debug("BCF guru release lock vpc id: " + vpc.getId() + " released? " + released);
} else {
// use network id in CS as tenant in BSN
// use network uuid as tenant id for non-VPC networks
tenantId = networkId;
tenantName = network.getName();
}
String hostname = dest.getHost().getName();
long zoneId = network.getDataCenterId();
String vmwareVswitchLabel = _networkModel.getDefaultGuestTrafficLabel(zoneId, HypervisorType.VMware);
String[] labelArray = null;
String vswitchName = null;
if (vmwareVswitchLabel != null) {
labelArray = vmwareVswitchLabel.split(",");
vswitchName = labelArray[0];
}
// hypervisor type:
// kvm: ivs port name
// vmware: specific portgroup naming convention
String pgName = "";
if (dest.getHost().getHypervisorType() == HypervisorType.KVM) {
pgName = hostname;
} else if (dest.getHost().getHypervisorType() == HypervisorType.VMware) {
pgName = hostname + "-" + vswitchName;
}
String nicId = nic.getUuid();
Integer vlan = Integer.valueOf(BroadcastDomainType.getValue(nic.getIsolationUri()));
String ipv4 = nic.getIPv4Address();
String mac = nic.getMacAddress();
CreateBcfAttachmentCommand cmd = new CreateBcfAttachmentCommand(tenantId, tenantName, networkId, pgName, nicId, vlan, ipv4, mac);
_bcfUtils.sendBcfCommandWithNetworkSyncCheck(cmd, network);
return true;
}
use of com.cloud.network.vpc.Vpc in project cloudstack by apache.
the class NuageVspElementTest method testShutdownVpc.
@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);
when(vpc.getId()).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(_physicalNetworkDao.listByZone(NETWORK_ID)).thenReturn(Lists.newArrayList(physNet));
final HostVO host = mock(HostVO.class);
when(host.getId()).thenReturn(NETWORK_ID);
final NuageVspDeviceVO nuageVspDevice = mock(NuageVspDeviceVO.class);
when(nuageVspDevice.getHostId()).thenReturn(NETWORK_ID);
when(_nuageVspDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Lists.newArrayList(nuageVspDevice));
when(_hostDao.findById(NETWORK_ID)).thenReturn(host);
when(_nuageVspManager.getNuageVspHost(NETWORK_ID)).thenReturn(host);
DomainRouterVO domainRouter = mock(DomainRouterVO.class);
when(domainRouter.getUuid()).thenReturn("aaaaaa");
when(_domainRouterDao.listByVpcId(NETWORK_ID)).thenReturn(Lists.newArrayList(domainRouter));
final Answer answer = mock(Answer.class);
when(answer.getResult()).thenReturn(true);
when(_agentManager.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
assertTrue(_nuageVspElement.shutdownVpc(vpc, context));
}
use of com.cloud.network.vpc.Vpc in project cloudstack by apache.
the class CreateNetworkACLListCmd method getEntityOwnerId.
@Override
public long getEntityOwnerId() {
Vpc vpc = _entityMgr.findById(Vpc.class, getVpcId());
if (vpc == null) {
throw new InvalidParameterValueException("Invalid vpcId is given");
}
Account account = _accountService.getAccount(vpc.getAccountId());
return account.getId();
}
Aggregations