Skip to content

Commit 35b7c26

Browse files
committed
Bug 8208 - bare metal provisioning
able to start, stop, reboot, destroy VM
1 parent cd676f4 commit 35b7c26

13 files changed

Lines changed: 111 additions & 21 deletions

File tree

api/src/com/cloud/api/commands/DestroyVMCmd.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.cloud.event.EventTypes;
3131
import com.cloud.exception.ConcurrentOperationException;
3232
import com.cloud.exception.ResourceUnavailableException;
33+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3334
import com.cloud.user.Account;
3435
import com.cloud.user.UserContext;
3536
import com.cloud.uservm.UserVm;
@@ -95,7 +96,13 @@ public Long getInstanceId() {
9596
@Override
9697
public void execute() throws ResourceUnavailableException, ConcurrentOperationException{
9798
UserContext.current().setEventDetails("Vm Id: "+getId());
98-
UserVm result = _userVmService.destroyVm(this);
99+
UserVm result;
100+
if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
101+
result = _bareMetalVmService.destroyVm(this);
102+
} else {
103+
result = _userVmService.destroyVm(this);
104+
}
105+
99106
if (result != null) {
100107
UserVmResponse response = _responseGenerator.createUserVmResponse(result);
101108
response.setResponseName("virtualmachine");

api/src/com/cloud/api/commands/RebootVMCmd.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.cloud.event.EventTypes;
3131
import com.cloud.exception.InsufficientCapacityException;
3232
import com.cloud.exception.ResourceUnavailableException;
33+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3334
import com.cloud.user.Account;
3435
import com.cloud.user.UserContext;
3536
import com.cloud.uservm.UserVm;
@@ -94,7 +95,13 @@ public Long getInstanceId() {
9495
@Override
9596
public void execute() throws ResourceUnavailableException, InsufficientCapacityException{
9697
UserContext.current().setEventDetails("Vm Id: "+getId());
97-
UserVm result = _userVmService.rebootVirtualMachine(this);
98+
UserVm result;
99+
if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
100+
result = _bareMetalVmService.rebootVirtualMachine(this);
101+
} else {
102+
result = _userVmService.rebootVirtualMachine(this);
103+
}
104+
98105
if (result !=null){
99106
UserVmResponse response = _responseGenerator.createUserVmResponse(result);
100107
response.setResponseName(getCommandName());

api/src/com/cloud/api/commands/StartVMCmd.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.cloud.exception.ResourceAllocationException;
3434
import com.cloud.exception.ResourceUnavailableException;
3535
import com.cloud.exception.StorageUnavailableException;
36+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3637
import com.cloud.user.Account;
3738
import com.cloud.user.UserContext;
3839
import com.cloud.uservm.UserVm;
@@ -104,7 +105,13 @@ public Long getInstanceId() {
104105
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException{
105106
try {
106107
UserContext.current().setEventDetails("Vm Id: "+getId());
107-
UserVm result = _userVmService.startVirtualMachine(this);
108+
UserVm result;
109+
if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
110+
result = _bareMetalVmService.startVirtualMachine(this);
111+
} else {
112+
result = _userVmService.startVirtualMachine(this);
113+
}
114+
108115
if (result != null){
109116
UserVmResponse response = _responseGenerator.createUserVmResponse(result);
110117
response.setResponseName(getCommandName());

api/src/com/cloud/api/commands/StopVMCmd.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.cloud.async.AsyncJob;
3030
import com.cloud.event.EventTypes;
3131
import com.cloud.exception.ConcurrentOperationException;
32+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3233
import com.cloud.user.Account;
3334
import com.cloud.user.UserContext;
3435
import com.cloud.uservm.UserVm;
@@ -107,7 +108,14 @@ public boolean isForced() {
107108
@Override
108109
public void execute() throws ServerApiException, ConcurrentOperationException{
109110
UserContext.current().setEventDetails("Vm Id: "+getId());
110-
UserVm result = _userVmService.stopVirtualMachine(getId(), isForced());
111+
UserVm result;
112+
113+
if (_userVmService.getHypervisorTypeOfUserVM(getId()) == HypervisorType.BareMetal) {
114+
result = _bareMetalVmService.stopVirtualMachine(getId(), isForced());
115+
} else {
116+
result = _userVmService.stopVirtualMachine(getId(), isForced());
117+
}
118+
111119
if (result != null) {
112120
UserVmResponse response = _responseGenerator.createUserVmResponse(result);
113121
response.setResponseName(getCommandName());

api/src/com/cloud/vm/UserVmService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.cloud.exception.ResourceAllocationException;
4343
import com.cloud.exception.ResourceUnavailableException;
4444
import com.cloud.exception.StorageUnavailableException;
45+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
4546
import com.cloud.storage.Volume;
4647
import com.cloud.template.VirtualMachineTemplate;
4748
import com.cloud.uservm.UserVm;
@@ -170,4 +171,6 @@ public interface UserVmService {
170171
* @return List of UserVMs.
171172
*/
172173
List<? extends UserVm> searchForUserVMs(ListVMsCmd cmd);
174+
175+
HypervisorType getHypervisorTypeOfUserVM(long vmid);
173176
}

scripts/util/ipmi.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def ping(args):
7878
print o.stderr
7979
return 1
8080
else:
81+
print o.stdout
8182
return 0
8283

8384
def boot_dev(args):
@@ -117,7 +118,24 @@ def reboot(args):
117118
else:
118119
return 0
119120

120-
call_table = {"ping":ping, "boot_dev":boot_dev, "reboot":reboot}
121+
def power(args):
122+
hostname = args.get("hostname")
123+
usrname = args.get("usrname")
124+
password = args.get("password")
125+
action = args.get("action")
126+
127+
if hostname == None:
128+
print "No hostname"
129+
return 1
130+
131+
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", action)
132+
if o.ret:
133+
print o.stderr
134+
return 1
135+
else:
136+
return 0
137+
138+
call_table = {"ping":ping, "boot_dev":boot_dev, "reboot":reboot, "power":power}
121139
def dispatch(args):
122140
cmd = args[1]
123141
params = args[2:]

server/src/com/cloud/api/AddPxeServerCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public class AddPxeServerCmd extends BaseCmd {
3333
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required = true, description="Zone in which to add the external firewall appliance.")
3434
private Long zoneId;
3535

36+
@Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, required = true, description="Zone in which to add the external firewall appliance.")
37+
private Long podId;
38+
3639
@Parameter(name=ApiConstants.URL, type=CommandType.STRING, required = true, description="URL of the PXE server appliance.")
3740
private String url;
3841

@@ -68,6 +71,10 @@ public String getPassword() {
6871
public String getType() {
6972
return type;
7073
}
74+
75+
public Long getPod() {
76+
return podId;
77+
}
7178

7279
/////////////////////////////////////////////////////
7380
/////////////// API Implementation///////////////////

server/src/com/cloud/baremetal/LinMinPxeServerManagerImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,16 @@ public class LinMinPxeServerManagerImpl extends PxeServerManagerImpl implements
3737
@Override
3838
public Host addPxeServer(AddPxeServerCmd cmd) throws InvalidParameterValueException, CloudRuntimeException {
3939
long zoneId = cmd.getZoneId();
40+
Long podId = cmd.getPod();
4041

4142
DataCenterVO zone = _dcDao.findById(zoneId);
42-
String zoneName;
4343
if (zone == null) {
4444
throw new InvalidParameterValueException("Could not find zone with ID: " + zoneId);
45-
} else {
46-
zoneName = zone.getName();
47-
}
45+
}
4846

49-
List<HostVO> pxeServers = _hostDao.listByTypeDataCenter(Host.Type.PxeServer, zoneId);
47+
List<HostVO> pxeServers = _hostDao.listBy(Host.Type.PxeServer, null, podId, zoneId);
5048
if (pxeServers.size() != 0) {
51-
throw new InvalidParameterValueException("Already had a PXE server in zone: " + zoneName);
49+
throw new InvalidParameterValueException("Already had a PXE server in Pod: " + podId + " zone: " + zoneId);
5250
}
5351

5452
URI uri;
@@ -65,10 +63,12 @@ public Host addPxeServer(AddPxeServerCmd cmd) throws InvalidParameterValueExcept
6563
String guid = getPxeServerGuid(Long.toString(zoneId), PxeServerType.LinMin.getName(), ipAddress);
6664
Map params = new HashMap<String, String>();
6765
params.put("zone", Long.toString(zoneId));
66+
params.put("pod", podId.toString());
6867
params.put("ip", ipAddress);
6968
params.put("username", username);
7069
params.put("password", password);
7170
params.put("guid", guid);
71+
params.put("pod", Long.toString(cmd.getPod()));
7272

7373
ServerResource resource = null;
7474
try {

server/src/com/cloud/baremetal/LinMinPxeServerResource.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class LinMinPxeServerResource implements ServerResource {
4848
String _password;
4949
String _ip;
5050
String _zoneId;
51+
String _podId;
5152

5253
class XmlReturn {
5354
NodeList nList;
@@ -86,6 +87,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
8687
_username = (String)params.get("username");
8788
_password = (String)params.get("password");
8889
_zoneId = (String)params.get("zone");
90+
_podId = (String)params.get("pod");
8991

9092
if (_guid == null) {
9193
throw new ConfigurationException("No Guid specified");
@@ -95,6 +97,10 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
9597
throw new ConfigurationException("No Zone specified");
9698
}
9799

100+
if (_podId == null) {
101+
throw new ConfigurationException("No Pod specified");
102+
}
103+
98104
if (_ip == null) {
99105
throw new ConfigurationException("No IP specified");
100106
}
@@ -157,7 +163,7 @@ public StartupCommand[] initialize() {
157163
StartupPxeServerCommand cmd = new StartupPxeServerCommand();
158164
cmd.setName(_name);
159165
cmd.setDataCenter(_zoneId);
160-
cmd.setPod("");
166+
cmd.setPod(_podId);
161167
cmd.setPrivateIpAddress(_ip);
162168
cmd.setStorageIpAddress("");
163169
cmd.setVersion("");

server/src/com/cloud/vm/BareMetalVmManagerImpl.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import org.apache.log4j.Logger;
1818

19+
import com.cloud.agent.api.StopAnswer;
1920
import com.cloud.agent.api.baremetal.PrepareLinMinPxeServerCommand;
2021
import com.cloud.agent.manager.Commands;
2122
import com.cloud.api.commands.AttachVolumeCmd;
@@ -271,7 +272,9 @@ public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityE
271272
if (_itMgr.allocate(vm, template, offering, null, null, networks, null, plan, cmd.getHypervisor(), owner) == null) {
272273
return null;
273274
}
274-
275+
276+
// startVirtualMachine() will retrieve this property
277+
vm.setDetail("pxeboot", "true");
275278
_vmDao.saveDetails(vm);
276279

277280
if (s_logger.isDebugEnabled()) {
@@ -374,16 +377,12 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<UserVmVO> pro
374377
throw new PermissionDeniedException("The owner of " + vm + " either does not exist or is disabled: " + vm.getAccountId());
375378
}
376379

377-
if (profile.getTemplate() == null) {
380+
PxeServerType pxeType = (PxeServerType) profile.getParameter(Param.PxeSeverType);
381+
if (pxeType == null) {
378382
s_logger.debug("This is a normal IPMI start, skip prepartion of PXE server");
379383
return true;
380384
}
381-
382385
s_logger.debug("This is a PXE start, prepare PXE server first");
383-
PxeServerType pxeType = (PxeServerType) profile.getParameter(Param.PxeSeverType);
384-
if (pxeType == null) {
385-
throw new CloudRuntimeException("No PXE type specified");
386-
}
387386

388387
PxeServerManager pxeMgr = null;
389388
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
@@ -445,4 +444,14 @@ public boolean finalizeStart(VirtualMachineProfile<UserVmVO> profile, long hostI
445444

446445
return true;
447446
}
447+
448+
@Override
449+
public void finalizeStop(VirtualMachineProfile<UserVmVO> profile, StopAnswer answer) {
450+
super.finalizeStop(profile, answer);
451+
}
452+
453+
@Override
454+
public UserVm destroyVm(long vmId) throws ResourceUnavailableException, ConcurrentOperationException {
455+
return super.destroyVm(vmId);
456+
}
448457
}

0 commit comments

Comments
 (0)