Skip to content

Commit 3c1a375

Browse files
committed
Bug 9887 - baremetal: support for image operation (create template from guest disk)
Resolved fixed
1 parent b885915 commit 3c1a375

6 files changed

Lines changed: 62 additions & 22 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818

1919
package com.cloud.vm;
2020

21+
import com.cloud.exception.ResourceAllocationException;
22+
2123
public interface BareMetalVmService extends UserVmService {
24+
public Long createTemplate(Long hostId, Integer bits, String displayText, String url, Boolean featured, Boolean publicTemplate, String templateName, Long osTypeId) throws ResourceAllocationException;
2225
}

cloud.spec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ BuildRequires: java-1.6.0-openjdk-devel
2727
BuildRequires: tomcat6
2828
BuildRequires: ws-commons-util
2929
#BuildRequires: commons-codec
30-
BuildRequires: commons-dbcp
31-
BuildRequires: commons-collections
30+
#BuildRequires: commons-dbcp
31+
#BuildRequires: commons-collections
3232
BuildRequires: commons-httpclient
3333
BuildRequires: jpackage-utils
3434
BuildRequires: gcc

scripts/network/ping/prepare_tftp_bootfile.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from os import makedirs
2727
from os.path import exists, join
2828

29-
template = '''DEFAULT default
29+
restore_template = '''DEFAULT default
3030
PROMPT 1
3131
TIMEOUT 26
3232
DISPLAY boot.msg
@@ -35,19 +35,30 @@
3535
APPEND vga=normal devfs=nomount pxe ramdisk_size=66000 load_ramdisk=1 init=/linuxrc prompt_ramdisk=0 initrd=initrd.gz root=/dev/ram0 rw noapic nolapic lba combined_mode=libata ide0=noprobe nomce pci=nomsi irqpoll quiet Server="%s" Share="%s" Directory="%s" Image_To_Restore="%s" After_Completion="Reboot" CIFS_Preferred="Y" Zsplit_Preferred="Y" AUTO="Y" User="%s" Passwd="%s" Extend_Parts_Whenever_Possible="N" Replace_BIOS="N" IP="%s" Netmask="%s" Gateway="%s"
3636
'''
3737

38+
backup_template = '''DEFAULT default
39+
PROMPT 1
40+
TIMEOUT 26
41+
DISPLAY boot.msg
42+
LABEL default
43+
KERNEL kernel
44+
APPEND vga=normal devfs=nomount pxe ramdisk_size=66000 load_ramdisk=1 init=/linuxrc prompt_ramdisk=0 initrd=initrd.gz root=/dev/ram0 rw noapic nolapic lba combined_mode=libata ide0=noprobe nomce pci=nomsi irqpoll quiet Server="%s" Share="%s" Directory="%s" Image_To_Restore="Create_New_Image" New_Image_Name="%s" Already_Existing_Image="Replace" Store_MD5="N" Compression_Type="gzip" After_Completion="Reboot" Minimize_Before_Storing="N" Repart="N" CIFS_Preferred="Y" AUTO="Y" User="%s" Passwd="%s" Extend_Parts_Whenever_Possible="N" Replace_BIOS="N" IP="%s" Netmask="%s" Gateway="%s"
45+
'''
46+
47+
48+
cmd = ''
3849
tftp_dir = ''
3950
mac = ''
4051
cifs_server = ''
4152
share = ''
4253
directory = ''
43-
image_to_restore = ''
54+
template_dir = ''
4455
cifs_username = ''
4556
cifs_password = ''
4657
ip = ''
4758
netmask = ''
4859
gateway = ''
4960

50-
def prepare_boot_file():
61+
def prepare(is_restore):
5162
try:
5263
pxelinux = join(tftp_dir, "pxelinux.cfg")
5364
if exists(pxelinux) == False:
@@ -56,31 +67,32 @@ def prepare_boot_file():
5667
cfg_name = "01-" + mac.replace(':','-').lower()
5768
cfg_path = join(pxelinux, cfg_name)
5869
f = open(cfg_path, "w")
59-
stuff = template % (cifs_server, share, directory, image_to_restore, cifs_username, cifs_password, ip, netmask, gateway)
70+
if is_restore:
71+
fmt = restore_template
72+
else:
73+
fmt = backup_template
74+
stuff = fmt % (cifs_server, share, directory, template_dir, cifs_username, cifs_password, ip, netmask, gateway)
6075
f.write(stuff)
6176
f.close()
6277
return 0
63-
except IOError, e:
78+
except Exception, e:
6479
print e
6580
return 1
6681

82+
6783
if __name__ == "__main__":
6884
if len(sys.argv) < 12:
6985
print "Usage: prepare_tftp_bootfile.py tftp_dir mac cifs_server share directory image_to_restor cifs_username cifs_password ip netmask gateway"
7086
exit(1)
7187

72-
tftp_dir = sys.argv[1]
73-
mac = sys.argv[2]
74-
cifs_server = sys.argv[3]
75-
share = sys.argv[4]
76-
directory = sys.argv[5]
77-
image_to_restore = sys.argv[6]
78-
cifs_username = sys.argv[7]
79-
cifs_password = sys.argv[8]
80-
ip = sys.argv[9]
81-
netmask = sys.argv[10]
82-
gateway = sys.argv[11]
88+
(cmd, tftp_dir, mac, cifs_server, share, directory, template_dir, cifs_username, cifs_password, ip, netmask, gateway) = sys.argv[1:]
8389

84-
85-
ret = prepare_boot_file()
90+
if cmd == "restore":
91+
ret = prepare(True)
92+
elif cmd == "backup":
93+
ret = prepare(False)
94+
else:
95+
print "Unknown cmd: %s"%cmd
96+
ret = 1
97+
8698
exit(ret)

scripts/util/ipmi.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,26 @@ def power(args):
156156
else:
157157
return 0
158158

159-
call_table = {"ping":ping, "boot_dev":boot_dev, "reboot":reboot, "power":power}
159+
def boot_or_reboot(args):
160+
hostname = args.get("hostname")
161+
usrname = args.get("usrname")
162+
password = args.get("password")
163+
o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status")
164+
if o.ret:
165+
print o.stderr
166+
return 1
167+
168+
if "is on" in o.stdout:
169+
args["action"] = "reset"
170+
elif "is off" in o.stdout:
171+
args["action"] = "on"
172+
else:
173+
print "unknown power status:" + o.stdout
174+
return 1
175+
176+
return power(args)
177+
178+
call_table = {"ping":ping, "boot_dev":boot_dev, "reboot":reboot, "power":power, "boot_or_reboot":boot_or_reboot}
160179
def dispatch(args):
161180
cmd = args[1]
162181
params = args[2:]

server/src/com/cloud/template/TemplateAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.cloud.api.commands.RegisterIsoCmd;
66
import com.cloud.api.commands.RegisterTemplateCmd;
77
import com.cloud.exception.ResourceAllocationException;
8+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
89
import com.cloud.storage.VMTemplateVO;
910
import com.cloud.utils.component.Adapter;
1011

@@ -35,4 +36,9 @@ public String getName() {
3536
public TemplateProfile prepareDelete(DeleteIsoCmd cmd);
3637

3738
public boolean delete(TemplateProfile profile);
39+
40+
public TemplateProfile prepare(boolean isIso, Long userId, String name, String displayText, Integer bits,
41+
Boolean passwordEnabled, Boolean requiresHVM, String url, Boolean isPublic, Boolean featured,
42+
Boolean isExtractable, String format, Long guestOSId, Long zoneId, HypervisorType hypervisorType,
43+
String accountName, Long domainId, String chksum, Boolean bootable) throws ResourceAllocationException;
3844
}

server/src/com/cloud/template/TemplateAdapterBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private static boolean isAdmin(short accountType) {
8787
(accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
8888
}
8989

90-
private TemplateProfile prepare(boolean isIso, Long userId, String name, String displayText, Integer bits,
90+
public TemplateProfile prepare(boolean isIso, Long userId, String name, String displayText, Integer bits,
9191
Boolean passwordEnabled, Boolean requiresHVM, String url, Boolean isPublic, Boolean featured,
9292
Boolean isExtractable, String format, Long guestOSId, Long zoneId, HypervisorType hypervisorType,
9393
String accountName, Long domainId, String chksum, Boolean bootable) throws ResourceAllocationException {

0 commit comments

Comments
 (0)