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);
}
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);
}
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()));
}
}
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;
}
Aggregations