use of com.cloud.baremetal.networkservice.BaremetalRctResponse 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.networkservice.BaremetalRctResponse in project cloudstack by apache.
the class AddBaremetalRctCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
BaremetalRctResponse rsp = vlanMgr.addRct(this);
this.setResponseObject(rsp);
} catch (Exception e) {
s_logger.warn(String.format("unable to add baremetal RCT[%s]", getRctUrl()), e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.baremetal.networkservice.BaremetalRctResponse in project cloudstack by apache.
the class ListBaremetalRctCmd method execute.
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
try {
ListResponse<BaremetalRctResponse> response = new ListResponse<>();
List<BaremetalRctResponse> rctResponses = new ArrayList<>();
BaremetalRctResponse rsp = vlanMgr.listRct();
if (rsp != null) {
rctResponses.add(rsp);
}
response.setResponses(rctResponses);
response.setResponseName(getCommandName());
response.setObjectName("baremetalrcts");
this.setResponseObject(response);
} catch (Exception e) {
s_logger.debug("Exception happened while executing ListBaremetalRctCmd", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.baremetal.networkservice.BaremetalRctResponse 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