use of com.cloud.ucs.database.UcsManagerVO in project cloudstack by apache.
the class UcsManagerImpl method addUcsManager.
@Override
@DB
public UcsManagerResponse addUcsManager(AddUcsManagerCmd cmd) {
QueryBuilder<UcsManagerVO> q = QueryBuilder.create(UcsManagerVO.class);
q.and(q.entity().getUrl(), Op.EQ, cmd.getUrl());
UcsManagerVO mgrvo = q.find();
if (mgrvo != null) {
throw new IllegalArgumentException(String.format("duplicate UCS manager. url[%s] is used by another UCS manager already", cmd.getUrl()));
}
try {
UcsManagerVO vo = new UcsManagerVO();
vo.setUuid(UUID.randomUUID().toString());
vo.setPassword(cmd.getPassword());
vo.setUrl(cmd.getUrl());
vo.setUsername(cmd.getUsername());
vo.setZoneId(cmd.getZoneId());
vo.setName(cmd.getName());
mgrvo = ucsDao.persist(vo);
UcsManagerResponse rsp = new UcsManagerResponse();
rsp.setId(String.valueOf(vo.getId()));
rsp.setName(vo.getName());
rsp.setUrl(vo.getUrl());
rsp.setZoneId(String.valueOf(vo.getZoneId()));
discoverBlades(vo);
return rsp;
} catch (CloudRuntimeException e) {
if (mgrvo != null) {
ucsDao.remove(mgrvo.getId());
}
throw e;
}
}
use of com.cloud.ucs.database.UcsManagerVO in project cloudstack by apache.
the class UcsManagerImpl method isProfileAssociated.
private boolean isProfileAssociated(Long ucsMgrId, String dn) {
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
String cookie = getCookie(ucsMgrId);
String cmd = UcsCommands.configResolveDn(cookie, dn);
String res = client.call(cmd);
XmlObject xo = XmlObjectParser.parseFromString(res);
s_logger.debug(String.format("association response is %s", res));
if (xo.get("outConfig.computeBlade.association").equals("none")) {
throw new CloudRuntimeException(String.format("cannot associated a profile to blade[dn:%s]. please check your UCS manasger for detailed error information", dn));
}
return xo.get("outConfig.computeBlade.association").equals("associated");
}
use of com.cloud.ucs.database.UcsManagerVO in project cloudstack by apache.
the class UcsManagerImpl method getCookie.
private String getCookie(Long ucsMgrId) {
try {
UcsCookie ucsCookie = cookies.get(ucsMgrId);
long currentTime = System.currentTimeMillis();
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
String cmd = null;
if (ucsCookie == null) {
cmd = UcsCommands.loginCmd(mgrvo.getUsername(), mgrvo.getPassword());
} else {
String cookie = ucsCookie.getCookie();
long cookieStartTime = ucsCookie.getStartTime();
if (currentTime - cookieStartTime > COOKIE_TTL) {
cmd = UcsCommands.loginCmd(mgrvo.getUsername(), mgrvo.getPassword());
} else if (currentTime - cookieStartTime > COOKIE_REFRESH_TTL) {
cmd = UcsCommands.refreshCmd(mgrvo.getUsername(), mgrvo.getPassword(), cookie);
}
}
if (!(cmd == null)) {
String ret = client.call(cmd);
XmlObject xo = XmlObjectParser.parseFromString(ret);
String cookie = xo.get("outCookie");
ucsCookie = new UcsCookie(cookie, currentTime);
cookies.put(ucsMgrId, ucsCookie);
// cookiesTime.put(cookie, currentTime); //This is currentTime on purpose, and not latest time.
}
return ucsCookie.getCookie();
} catch (Exception e) {
throw new CloudRuntimeException("Cannot get cookie", e);
}
}
use of com.cloud.ucs.database.UcsManagerVO in project cloudstack by apache.
the class UcsManagerImpl method cloneProfile.
private String cloneProfile(Long ucsMgrId, String srcDn, String newProfileName) {
UcsManagerVO mgrvo = ucsDao.findById(ucsMgrId);
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
String cookie = getCookie(ucsMgrId);
String cmd = UcsCommands.cloneProfile(cookie, srcDn, newProfileName);
String res = client.call(cmd);
XmlObject xo = XmlObjectParser.parseFromString(res);
return xo.get("outConfig.lsServer.dn");
}
use of com.cloud.ucs.database.UcsManagerVO in project cloudstack by apache.
the class UcsManagerImpl method associateProfileToBlade.
@Override
public UcsBladeResponse associateProfileToBlade(AssociateUcsProfileToBladeCmd cmd) {
QueryBuilder<UcsBladeVO> q = QueryBuilder.create(UcsBladeVO.class);
q.and(q.entity().getUcsManagerId(), Op.EQ, cmd.getUcsManagerId());
q.and(q.entity().getId(), Op.EQ, cmd.getBladeId());
UcsBladeVO bvo = q.find();
if (bvo == null) {
throw new IllegalArgumentException(String.format("cannot find UCS blade[id:%s, ucs manager id:%s]", cmd.getBladeId(), cmd.getUcsManagerId()));
}
if (bvo.getHostId() != null) {
throw new CloudRuntimeException(String.format("blade[id:%s, dn:%s] has been associated with host[id:%s]", bvo.getId(), bvo.getDn(), bvo.getHostId()));
}
UcsManagerVO mgrvo = ucsDao.findById(cmd.getUcsManagerId());
String cookie = getCookie(cmd.getUcsManagerId());
String pdn = cloneProfile(mgrvo.getId(), cmd.getProfileDn(), "profile-for-blade-" + bvo.getId());
String ucscmd = UcsCommands.associateProfileToBlade(cookie, pdn, bvo.getDn());
UcsHttpClient client = new UcsHttpClient(mgrvo.getUrl());
String res = client.call(ucscmd);
int count = 0;
int timeout = 600;
while (count < timeout) {
if (isProfileAssociated(mgrvo.getId(), bvo.getDn())) {
break;
}
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
throw new CloudRuntimeException(e);
}
count += 2;
}
if (count >= timeout) {
throw new CloudRuntimeException(String.format("associating profile[%s] to balde[%s] timeout after 600 seconds", pdn, bvo.getDn()));
}
bvo.setProfileDn(pdn);
bladeDao.update(bvo.getId(), bvo);
UcsBladeResponse rsp = bladeVOToResponse(bvo);
s_logger.debug(String.format("successfully associated profile[%s] to blade[%s]", pdn, bvo.getDn()));
return rsp;
}
Aggregations