Search in sources :

Example 26 with Account

use of com.cloud.user.Account in project cloudstack by apache.

the class ManagementServerMock method createPublicVlanIpRange.

private void createPublicVlanIpRange() {
    CreateVlanIpRangeCmd cmd = new CreateVlanIpRangeCmd();
    BaseCmd proxy = ComponentContext.inject(cmd);
    Long public_net_id = null;
    List<NetworkVO> nets = _networksDao.listByZoneAndTrafficType(_zone.getId(), TrafficType.Public);
    if (nets != null && !nets.isEmpty()) {
        NetworkVO public_net = nets.get(0);
        public_net_id = public_net.getId();
    } else {
        s_logger.debug("no public network found in the zone: " + _zone.getId());
    }
    Account system = _accountMgr.getSystemAccount();
    setParameter(cmd, "accountName", BaseCmd.CommandType.STRING, system.getAccountName());
    setParameter(cmd, "domainId", BaseCmd.CommandType.LONG, Domain.ROOT_DOMAIN);
    setParameter(cmd, "startIp", BaseCmd.CommandType.STRING, "10.84.60.200");
    setParameter(cmd, "endIp", BaseCmd.CommandType.STRING, "10.84.60.250");
    setParameter(cmd, ApiConstants.GATEWAY, BaseCmd.CommandType.STRING, "10.84.60.254");
    setParameter(cmd, ApiConstants.NETMASK, BaseCmd.CommandType.STRING, "255.255.255.0");
    setParameter(cmd, "networkID", BaseCmd.CommandType.LONG, public_net_id);
    setParameter(cmd, "zoneId", BaseCmd.CommandType.LONG, _zone.getId());
    setParameter(cmd, "vlan", BaseCmd.CommandType.STRING, "untagged");
    s_logger.debug("createPublicVlanIpRange execute : zone id: " + _zone.getId() + ", public net id: " + public_net_id);
    try {
        _configService.createVlanAndPublicIpRange(cmd);
    } catch (Exception e) {
        s_logger.debug("createPublicVlanIpRange: " + e);
    }
}
Also used : Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) CreateVlanIpRangeCmd(org.apache.cloudstack.api.command.admin.vlan.CreateVlanIpRangeCmd) BaseCmd(org.apache.cloudstack.api.BaseCmd) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException)

Example 27 with Account

use of com.cloud.user.Account in project cloudstack by apache.

the class NetworkProviderTest method createFloatingIp.

public IPAddressVO createFloatingIp(Network network, UserVm vm) throws Exception {
    BaseCmd cmd = new AssociateIPAddrCmd();
    BaseCmd proxy = ComponentContext.inject(cmd);
    Account system = _accountMgr.getSystemAccount();
    DataCenter zone = _server.getZone();
    ManagementServerMock.setParameter(proxy, "accountName", BaseCmd.CommandType.STRING, system.getAccountName());
    ManagementServerMock.setParameter(proxy, "domainId", BaseCmd.CommandType.LONG, Domain.ROOT_DOMAIN);
    ManagementServerMock.setParameter(proxy, "zoneId", BaseCmd.CommandType.LONG, zone.getId());
    ManagementServerMock.setParameter(proxy, "networkId", BaseCmd.CommandType.LONG, network.getId());
    try {
        ((AssociateIPAddrCmd) cmd).create();
        ((AssociateIPAddrCmd) cmd).execute();
    } catch (Exception e) {
        s_logger.debug("AssociateIPAddrCmd exception: " + e);
        e.printStackTrace();
        throw e;
    }
    SearchBuilder<IPAddressVO> searchBuilder = _ipAddressDao.createSearchBuilder();
    searchBuilder.and("sourceNat", searchBuilder.entity().isSourceNat(), Op.EQ);
    searchBuilder.and("network", searchBuilder.entity().getAssociatedWithNetworkId(), Op.EQ);
    searchBuilder.and("dataCenterId", searchBuilder.entity().getDataCenterId(), Op.EQ);
    searchBuilder.and("associatedWithVmId", searchBuilder.entity().getAssociatedWithVmId(), Op.NULL);
    SearchCriteria<IPAddressVO> sc = searchBuilder.create();
    sc.setParameters("sourceNat", false);
    sc.setParameters("network", network.getId());
    List<IPAddressVO> publicIps = _ipAddressDao.search(sc, null);
    assertNotNull(publicIps);
    cmd = new EnableStaticNatCmd();
    proxy = ComponentContext.inject(cmd);
    ManagementServerMock.setParameter(proxy, "ipAddressId", BaseCmd.CommandType.LONG, publicIps.get(0).getId());
    ManagementServerMock.setParameter(proxy, "networkId", BaseCmd.CommandType.LONG, network.getId());
    ManagementServerMock.setParameter(proxy, "virtualMachineId", BaseCmd.CommandType.LONG, vm.getId());
    try {
        proxy.execute();
    } catch (Exception e) {
        s_logger.debug("EnableStaticNatCmd exception: " + e);
        e.printStackTrace();
        throw e;
    }
    return publicIps.get(0);
}
Also used : Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) AssociateIPAddrCmd(org.apache.cloudstack.api.command.user.address.AssociateIPAddrCmd) IPAddressVO(com.cloud.network.dao.IPAddressVO) EnableStaticNatCmd(org.apache.cloudstack.api.command.user.nat.EnableStaticNatCmd) BaseCmd(org.apache.cloudstack.api.BaseCmd) CloudException(com.cloud.exception.CloudException) IOException(java.io.IOException)

Example 28 with Account

use of com.cloud.user.Account in project cloudstack by apache.

the class NetworkProviderTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    try {
        ComponentContext.initComponentsLifeCycle();
    } catch (Exception ex) {
        ex.printStackTrace();
        s_logger.error(ex.getMessage());
    }
    Account system = _accountMgr.getSystemAccount();
    User user = _accountMgr.getSystemUser();
    CallContext.register(user, system);
    _server = ComponentContext.inject(new ManagementServerMock());
    _server.initialize(!s_initDone);
    s_initDone = false;
    _api = _contrailMgr.getApiConnector();
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) CloudException(com.cloud.exception.CloudException) IOException(java.io.IOException) Before(org.junit.Before)

Example 29 with Account

use of com.cloud.user.Account in project cloudstack by apache.

the class VxlanGuestNetworkGuruTest method testDesign.

@Test
public void testDesign() {
    PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById(anyLong())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VXLAN" }));
    when(physnet.getId()).thenReturn(42L);
    NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(42L);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    DeploymentPlan plan = mock(DeploymentPlan.class);
    Network network = mock(Network.class);
    Account account = mock(Account.class);
    Network designednetwork = guru.design(offering, plan, network, account);
    assertTrue(designednetwork != null);
    assertTrue(designednetwork.getBroadcastDomainType() == BroadcastDomainType.Vxlan);
}
Also used : Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DeploymentPlan(com.cloud.deploy.DeploymentPlan) Test(org.junit.Test)

Example 30 with Account

use of com.cloud.user.Account in project cloudstack by apache.

the class VxlanGuestNetworkGuruTest method testImplement.

@Test
public void testImplement() throws InsufficientVirtualNetworkCapacityException {
    PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById(anyLong())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VXLAN" }));
    when(physnet.getId()).thenReturn(42L);
    NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(42L);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getPhysicalNetworkId()).thenReturn(42L);
    DeployDestination dest = mock(DeployDestination.class);
    DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
    //TODO(VXLAN): doesn't support VNI specified
    //when(confsvr.getConfigValue((String) any(), (String) any(), anyLong())).thenReturn("true");
    when(dcdao.allocateVnet(anyLong(), anyLong(), anyLong(), (String) any(), eq(true))).thenReturn("42");
    doNothing().when(guru).allocateVnetComplete((Network) any(), (NetworkVO) any(), anyLong(), anyLong(), (String) any(), eq("42"));
    Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    Network implementednetwork = guru.implement(network, offering, dest, res);
    assertTrue(implementednetwork != null);
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DataCenter(com.cloud.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Aggregations

Account (com.cloud.user.Account)566 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)254 ArrayList (java.util.ArrayList)152 ActionEvent (com.cloud.event.ActionEvent)114 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)98 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)82 List (java.util.List)80 Test (org.junit.Test)73 User (com.cloud.user.User)66 AccountVO (com.cloud.user.AccountVO)64 DB (com.cloud.utils.db.DB)61 Network (com.cloud.network.Network)60 Pair (com.cloud.utils.Pair)52 DataCenter (com.cloud.dc.DataCenter)49 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)46 Filter (com.cloud.utils.db.Filter)46 CallContext (org.apache.cloudstack.context.CallContext)45 DomainVO (com.cloud.domain.DomainVO)44 TransactionStatus (com.cloud.utils.db.TransactionStatus)44 NetworkVO (com.cloud.network.dao.NetworkVO)43