Search in sources :

Example 1 with BaremetalRctVO

use of com.cloud.baremetal.database.BaremetalRctVO in project cloudstack by apache.

the class BaremetalVlanManagerImpl method releaseVlan.

@Override
public void releaseVlan(Network nw, VirtualMachineProfile vm) {
    List<BaremetalRctVO> vos = rctDao.listAll();
    if (vos.isEmpty()) {
        throw new CloudRuntimeException("no rack configuration found, please call addBaremetalRct to add one");
    }
    BaremetalRctVO vo = vos.get(0);
    BaremetalRct rct = gson.fromJson(vo.getRct(), BaremetalRct.class);
    HostVO host = hostDao.findById(vm.getVirtualMachine().getHostId());
    RackPair rp = findRack(rct, host.getPrivateMacAddress());
    assert rp != null : String.format("where is my rack???");
    int vlan = Integer.parseInt(Networks.BroadcastDomainType.getValue(nw.getBroadcastUri()));
    BaremetalVlanStruct struct = new BaremetalVlanStruct();
    struct.setHostMac(rp.host.getMac());
    struct.setPort(rp.host.getPort());
    struct.setSwitchIp(rp.rack.getL2Switch().getIp());
    struct.setSwitchPassword(rp.rack.getL2Switch().getPassword());
    struct.setSwitchType(rp.rack.getL2Switch().getType());
    struct.setSwitchUsername(rp.rack.getL2Switch().getUsername());
    struct.setVlan(vlan);
    BaremetalSwitchBackend backend = getSwitchBackend(rp.rack.getL2Switch().getType());
    backend.removePortFromVlan(struct);
}
Also used : BaremetalRctVO(com.cloud.baremetal.database.BaremetalRctVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) BaremetalSwitchBackend(com.cloud.baremetal.networkservice.BaremetalSwitchBackend) BaremetalVlanStruct(com.cloud.baremetal.networkservice.BaremetalVlanStruct) HostVO(com.cloud.host.HostVO)

Example 2 with BaremetalRctVO

use of com.cloud.baremetal.database.BaremetalRctVO in project cloudstack by apache.

the class BaremetalVlanManagerImpl method prepareVlan.

@Override
public void prepareVlan(Network nw, DeployDestination destHost) {
    List<BaremetalRctVO> vos = rctDao.listAll();
    if (vos.isEmpty()) {
        throw new CloudRuntimeException("no rack configuration found, please call addBaremetalRct to add one");
    }
    BaremetalRctVO vo = vos.get(0);
    BaremetalRct rct = gson.fromJson(vo.getRct(), BaremetalRct.class);
    RackPair rp = findRack(rct, destHost.getHost().getPrivateMacAddress());
    if (rp == null) {
        throw new CloudRuntimeException(String.format("cannot find any rack contains host[mac:%s], please double check your rack configuration file, update it and call addBaremetalRct again", destHost.getHost().getPrivateMacAddress()));
    }
    int vlan = Integer.parseInt(Networks.BroadcastDomainType.getValue(nw.getBroadcastUri()));
    BaremetalSwitchBackend backend = getSwitchBackend(rp.rack.getL2Switch().getType());
    BaremetalVlanStruct struct = new BaremetalVlanStruct();
    struct.setHostMac(rp.host.getMac());
    struct.setPort(rp.host.getPort());
    struct.setSwitchIp(rp.rack.getL2Switch().getIp());
    struct.setSwitchPassword(rp.rack.getL2Switch().getPassword());
    struct.setSwitchType(rp.rack.getL2Switch().getType());
    struct.setSwitchUsername(rp.rack.getL2Switch().getUsername());
    struct.setVlan(vlan);
    backend.prepareVlan(struct);
}
Also used : BaremetalRctVO(com.cloud.baremetal.database.BaremetalRctVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) BaremetalSwitchBackend(com.cloud.baremetal.networkservice.BaremetalSwitchBackend) BaremetalVlanStruct(com.cloud.baremetal.networkservice.BaremetalVlanStruct)

Example 3 with BaremetalRctVO

use of com.cloud.baremetal.database.BaremetalRctVO in project cloudstack by apache.

the class BaremetalVlanManagerImpl method addRct.

@Override
public BaremetalRctResponse addRct(AddBaremetalRctCmd cmd) {
    try {
        List<BaremetalRctVO> existings = rctDao.listAll();
        if (!existings.isEmpty()) {
            throw new CloudRuntimeException(String.format("there is some RCT existing. A CloudStack deployment accepts only one RCT"));
        }
        URL url = new URL(cmd.getRctUrl());
        RestTemplate rest = new RestTemplate();
        String rctStr = rest.getForObject(url.toString(), String.class);
        // validate it's right format
        BaremetalRct rct = gson.fromJson(rctStr, BaremetalRct.class);
        QueryBuilder<BaremetalRctVO> sc = QueryBuilder.create(BaremetalRctVO.class);
        sc.and(sc.entity().getUrl(), SearchCriteria.Op.EQ, cmd.getRctUrl());
        BaremetalRctVO vo = sc.find();
        if (vo == null) {
            vo = new BaremetalRctVO();
            vo.setRct(gson.toJson(rct));
            vo.setUrl(cmd.getRctUrl());
            vo = rctDao.persist(vo);
        } else {
            vo.setRct(gson.toJson(rct));
            rctDao.update(vo.getId(), vo);
        }
        BaremetalRctResponse rsp = new BaremetalRctResponse();
        rsp.setUrl(vo.getUrl());
        rsp.setId(vo.getUuid());
        rsp.setObjectName("baremetalrct");
        return rsp;
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(String.format("%s is not a legal http url", cmd.getRctUrl()));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) BaremetalRctVO(com.cloud.baremetal.database.BaremetalRctVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) RestTemplate(org.springframework.web.client.RestTemplate) BaremetalRctResponse(com.cloud.baremetal.networkservice.BaremetalRctResponse) URL(java.net.URL)

Example 4 with BaremetalRctVO

use of com.cloud.baremetal.database.BaremetalRctVO in project cloudstack by apache.

the class BaremetalVlanManagerImpl method listRct.

@Override
public BaremetalRctResponse listRct() {
    List<BaremetalRctVO> vos = rctDao.listAll();
    if (!vos.isEmpty()) {
        BaremetalRctVO vo = vos.get(0);
        BaremetalRctResponse rsp = new BaremetalRctResponse();
        rsp.setId(vo.getUuid());
        rsp.setUrl(vo.getUrl());
        rsp.setObjectName("baremetalrct");
        return rsp;
    }
    return null;
}
Also used : BaremetalRctVO(com.cloud.baremetal.database.BaremetalRctVO) BaremetalRctResponse(com.cloud.baremetal.networkservice.BaremetalRctResponse)

Aggregations

BaremetalRctVO (com.cloud.baremetal.database.BaremetalRctVO)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 BaremetalRctResponse (com.cloud.baremetal.networkservice.BaremetalRctResponse)2 BaremetalSwitchBackend (com.cloud.baremetal.networkservice.BaremetalSwitchBackend)2 BaremetalVlanStruct (com.cloud.baremetal.networkservice.BaremetalVlanStruct)2 HostVO (com.cloud.host.HostVO)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 RestTemplate (org.springframework.web.client.RestTemplate)1