Search in sources :

Example 1 with Network

use of com.cloud.network.Network in project CloudStack-archive by CloudStack-extras.

the class UpdateNetworkCmd method execute.

@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException {
    User callerUser = _accountService.getActiveUser(UserContext.current().getCallerUserId());
    Account callerAccount = _accountService.getActiveAccountById(callerUser.getAccountId());
    Network result = _networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount, callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr());
    if (result != null) {
        NetworkResponse response = _responseGenerator.createNetworkResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update network");
    }
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) ServerApiException(com.cloud.api.ServerApiException) Network(com.cloud.network.Network) NetworkResponse(com.cloud.api.response.NetworkResponse)

Example 2 with Network

use of com.cloud.network.Network in project CloudStack-archive by CloudStack-extras.

the class ListNetworksCmd method execute.

@Override
public void execute() {
    List<? extends Network> networks = _networkService.searchForNetworks(this);
    ListResponse<NetworkResponse> response = new ListResponse<NetworkResponse>();
    List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();
    for (Network network : networks) {
        NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(network);
        networkResponses.add(networkResponse);
    }
    response.setResponses(networkResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) Network(com.cloud.network.Network) NetworkResponse(com.cloud.api.response.NetworkResponse) ArrayList(java.util.ArrayList)

Example 3 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class CiscoVnmcElementTest method applyPRulesTest.

@Test
public void applyPRulesTest() throws ResourceUnavailableException {
    URI uri = URI.create("vlan://123");
    Network network = mock(Network.class);
    when(network.getId()).thenReturn(1L);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
    when(network.getDataCenterId()).thenReturn(1L);
    when(network.getBroadcastUri()).thenReturn(uri);
    when(network.getCidr()).thenReturn("1.1.1.0/24");
    when(network.getState()).thenReturn(Network.State.Implemented);
    Ip ip = mock(Ip.class);
    when(ip.addr()).thenReturn("1.2.3.4");
    IpAddress ipAddress = mock(IpAddress.class);
    when(ipAddress.getAddress()).thenReturn(ip);
    when(ipAddress.getVlanId()).thenReturn(1L);
    when(_networkModel.getIp(anyLong())).thenReturn(ipAddress);
    when(_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.PortForwarding, Provider.CiscoVnmc)).thenReturn(true);
    List<CiscoVnmcControllerVO> devices = new ArrayList<CiscoVnmcControllerVO>();
    devices.add(mock(CiscoVnmcControllerVO.class));
    when(_ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(devices);
    when(_networkAsa1000vMapDao.findByNetworkId(network.getId())).thenReturn(mock(NetworkAsa1000vMapVO.class));
    HostVO hostVO = mock(HostVO.class);
    when(hostVO.getId()).thenReturn(1L);
    when(_hostDao.findById(anyLong())).thenReturn(hostVO);
    VlanVO vlanVO = mock(VlanVO.class);
    when(vlanVO.getVlanTag()).thenReturn(null);
    when(_vlanDao.findById(anyLong())).thenReturn(vlanVO);
    PortForwardingRule rule = mock(PortForwardingRule.class);
    when(rule.getSourceIpAddressId()).thenReturn(1L);
    when(rule.getDestinationIpAddress()).thenReturn(ip);
    List<PortForwardingRule> rules = new ArrayList<PortForwardingRule>();
    rules.add(rule);
    Answer answer = mock(Answer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentMgr.easySend(anyLong(), any(SetPortForwardingRulesCommand.class))).thenReturn(answer);
    assertTrue(_element.applyPFRules(network, rules));
}
Also used : Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) URI(java.net.URI) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) Network(com.cloud.network.Network) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO) IpAddress(com.cloud.network.IpAddress) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) VlanVO(com.cloud.dc.VlanVO) Test(org.junit.Test)

Example 4 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class CiscoVnmcElementTest method implementTest.

@Test
public void implementTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    URI uri = URI.create("vlan://123");
    Network network = mock(Network.class);
    when(network.getId()).thenReturn(1L);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
    when(network.getDataCenterId()).thenReturn(1L);
    when(network.getGateway()).thenReturn("1.1.1.1");
    when(network.getBroadcastUri()).thenReturn(uri);
    when(network.getCidr()).thenReturn("1.1.1.0/24");
    NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(1L);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    DeployDestination dest = mock(DeployDestination.class);
    Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("d1");
    Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("a1");
    ReservationContext context = mock(ReservationContext.class);
    when(context.getDomain()).thenReturn(dom);
    when(context.getAccount()).thenReturn(acc);
    DataCenter dc = mock(DataCenter.class);
    when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
    when(_entityMgr.findById(DataCenter.class, network.getDataCenterId())).thenReturn(dc);
    List<CiscoVnmcControllerVO> devices = new ArrayList<CiscoVnmcControllerVO>();
    devices.add(mock(CiscoVnmcControllerVO.class));
    when(_ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(devices);
    CiscoAsa1000vDeviceVO asaVO = mock(CiscoAsa1000vDeviceVO.class);
    when(asaVO.getInPortProfile()).thenReturn("foo");
    when(asaVO.getManagementIp()).thenReturn("1.2.3.4");
    List<CiscoAsa1000vDeviceVO> asaList = new ArrayList<CiscoAsa1000vDeviceVO>();
    asaList.add(asaVO);
    when(_ciscoAsa1000vDao.listByPhysicalNetwork(network.getPhysicalNetworkId())).thenReturn(asaList);
    when(_networkAsa1000vMapDao.findByNetworkId(network.getId())).thenReturn(mock(NetworkAsa1000vMapVO.class));
    when(_networkAsa1000vMapDao.findByAsa1000vId(anyLong())).thenReturn(null);
    when(_networkAsa1000vMapDao.persist(any(NetworkAsa1000vMapVO.class))).thenReturn(mock(NetworkAsa1000vMapVO.class));
    when(_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.CiscoVnmc)).thenReturn(true);
    ClusterVSMMapVO clusterVsmMap = mock(ClusterVSMMapVO.class);
    when(_clusterVsmMapDao.findByClusterId(anyLong())).thenReturn(clusterVsmMap);
    CiscoNexusVSMDeviceVO vsmDevice = mock(CiscoNexusVSMDeviceVO.class);
    when(vsmDevice.getUserName()).thenReturn("foo");
    when(vsmDevice.getPassword()).thenReturn("bar");
    when(vsmDevice.getipaddr()).thenReturn("1.2.3.4");
    when(_vsmDeviceDao.findById(anyLong())).thenReturn(vsmDevice);
    HostVO hostVO = mock(HostVO.class);
    when(hostVO.getId()).thenReturn(1L);
    when(_hostDao.findById(anyLong())).thenReturn(hostVO);
    Ip ip = mock(Ip.class);
    when(ip.addr()).thenReturn("1.2.3.4");
    PublicIp publicIp = mock(PublicIp.class);
    when(publicIp.getAddress()).thenReturn(ip);
    when(publicIp.getState()).thenReturn(IpAddress.State.Releasing);
    when(publicIp.getAccountId()).thenReturn(1L);
    when(publicIp.isSourceNat()).thenReturn(true);
    when(publicIp.getVlanTag()).thenReturn("123");
    when(publicIp.getGateway()).thenReturn("1.1.1.1");
    when(publicIp.getNetmask()).thenReturn("1.1.1.1");
    when(publicIp.getMacAddress()).thenReturn(null);
    when(publicIp.isOneToOneNat()).thenReturn(true);
    when(_ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(acc, network)).thenReturn(publicIp);
    VlanVO vlanVO = mock(VlanVO.class);
    when(vlanVO.getVlanGateway()).thenReturn("1.1.1.1");
    List<VlanVO> vlanVOList = new ArrayList<VlanVO>();
    when(_vlanDao.listVlansByPhysicalNetworkId(network.getPhysicalNetworkId())).thenReturn(vlanVOList);
    Answer answer = mock(Answer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentMgr.easySend(anyLong(), any(CreateLogicalEdgeFirewallCommand.class))).thenReturn(answer);
    when(_agentMgr.easySend(anyLong(), any(ConfigureNexusVsmForAsaCommand.class))).thenReturn(answer);
    when(_agentMgr.easySend(anyLong(), any(SetSourceNatCommand.class))).thenReturn(answer);
    when(_agentMgr.easySend(anyLong(), any(AssociateAsaWithLogicalEdgeFirewallCommand.class))).thenReturn(answer);
    assertTrue(_element.implement(network, offering, dest, context));
}
Also used : Account(com.cloud.user.Account) ClusterVSMMapVO(com.cloud.dc.ClusterVSMMapVO) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) ArrayList(java.util.ArrayList) AssociateAsaWithLogicalEdgeFirewallCommand(com.cloud.agent.api.AssociateAsaWithLogicalEdgeFirewallCommand) SetSourceNatCommand(com.cloud.agent.api.routing.SetSourceNatCommand) URI(java.net.URI) ReservationContext(com.cloud.vm.ReservationContext) Network(com.cloud.network.Network) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) VlanVO(com.cloud.dc.VlanVO) CiscoAsa1000vDeviceVO(com.cloud.network.cisco.CiscoAsa1000vDeviceVO) CiscoNexusVSMDeviceVO(com.cloud.network.CiscoNexusVSMDeviceVO) NetworkOffering(com.cloud.offering.NetworkOffering) PublicIp(com.cloud.network.addr.PublicIp) ConfigureNexusVsmForAsaCommand(com.cloud.agent.api.ConfigureNexusVsmForAsaCommand) HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) DataCenter(com.cloud.dc.DataCenter) CreateLogicalEdgeFirewallCommand(com.cloud.agent.api.CreateLogicalEdgeFirewallCommand) DeployDestination(com.cloud.deploy.DeployDestination) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 5 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class ElasticLoadBalancerManagerImpl method findElbVmForLb.

protected DomainRouterVO findElbVmForLb(LoadBalancingRule lb) {
    //TODO: use a table to lookup
    Network ntwk = _networkModel.getNetwork(lb.getNetworkId());
    long sourceIpId = _networkModel.getPublicIpAddress(lb.getSourceIp().addr(), ntwk.getDataCenterId()).getId();
    ElasticLbVmMapVO map = _elbVmMapDao.findOneByIp(sourceIpId);
    if (map == null) {
        return null;
    }
    DomainRouterVO elbVm = _routerDao.findById(map.getElbVmId());
    return elbVm;
}
Also used : ElasticLbVmMapVO(com.cloud.network.ElasticLbVmMapVO) Network(com.cloud.network.Network) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

Network (com.cloud.network.Network)235 ArrayList (java.util.ArrayList)86 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)63 Account (com.cloud.user.Account)60 Test (org.junit.Test)55 NetworkOffering (com.cloud.offering.NetworkOffering)52 PhysicalNetwork (com.cloud.network.PhysicalNetwork)50 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)50 NetworkVO (com.cloud.network.dao.NetworkVO)38 DataCenter (com.cloud.dc.DataCenter)34 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)31 NicProfile (com.cloud.vm.NicProfile)31 HostVO (com.cloud.host.HostVO)27 DB (com.cloud.utils.db.DB)27 List (java.util.List)27 DataCenterVO (com.cloud.dc.DataCenterVO)26 IPAddressVO (com.cloud.network.dao.IPAddressVO)25 HashMap (java.util.HashMap)24 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)23 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20