diff --git a/api/src/com/cloud/vm/BareMetalVmService.java b/api/src/com/cloud/vm/BareMetalVmService.java index 75359784537..6958b98e24a 100644 --- a/api/src/com/cloud/vm/BareMetalVmService.java +++ b/api/src/com/cloud/vm/BareMetalVmService.java @@ -18,5 +18,8 @@ package com.cloud.vm; +import com.cloud.exception.ResourceAllocationException; + public interface BareMetalVmService extends UserVmService { + public Long createTemplate(Long hostId, Integer bits, String displayText, String url, Boolean featured, Boolean publicTemplate, String templateName, Long osTypeId) throws ResourceAllocationException; } diff --git a/cloud.spec b/cloud.spec index 4bd81de8ef1..df3f49e3008 100644 --- a/cloud.spec +++ b/cloud.spec @@ -27,8 +27,8 @@ BuildRequires: java-1.6.0-openjdk-devel BuildRequires: tomcat6 BuildRequires: ws-commons-util #BuildRequires: commons-codec -BuildRequires: commons-dbcp -BuildRequires: commons-collections +#BuildRequires: commons-dbcp +#BuildRequires: commons-collections BuildRequires: commons-httpclient BuildRequires: jpackage-utils BuildRequires: gcc diff --git a/scripts/network/ping/prepare_tftp_bootfile.py b/scripts/network/ping/prepare_tftp_bootfile.py index f4589faff9b..5b853baaef6 100644 --- a/scripts/network/ping/prepare_tftp_bootfile.py +++ b/scripts/network/ping/prepare_tftp_bootfile.py @@ -26,7 +26,7 @@ from sys import exit from os import makedirs from os.path import exists, join -template = '''DEFAULT default +restore_template = '''DEFAULT default PROMPT 1 TIMEOUT 26 DISPLAY boot.msg @@ -35,19 +35,30 @@ KERNEL kernel 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" ''' +backup_template = '''DEFAULT default +PROMPT 1 +TIMEOUT 26 +DISPLAY boot.msg +LABEL default +KERNEL kernel +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" +''' + + +cmd = '' tftp_dir = '' mac = '' cifs_server = '' share = '' directory = '' -image_to_restore = '' +template_dir = '' cifs_username = '' cifs_password = '' ip = '' netmask = '' gateway = '' -def prepare_boot_file(): +def prepare(is_restore): try: pxelinux = join(tftp_dir, "pxelinux.cfg") if exists(pxelinux) == False: @@ -56,31 +67,32 @@ def prepare_boot_file(): cfg_name = "01-" + mac.replace(':','-').lower() cfg_path = join(pxelinux, cfg_name) f = open(cfg_path, "w") - stuff = template % (cifs_server, share, directory, image_to_restore, cifs_username, cifs_password, ip, netmask, gateway) + if is_restore: + fmt = restore_template + else: + fmt = backup_template + stuff = fmt % (cifs_server, share, directory, template_dir, cifs_username, cifs_password, ip, netmask, gateway) f.write(stuff) f.close() return 0 - except IOError, e: + except Exception, e: print e return 1 + if __name__ == "__main__": if len(sys.argv) < 12: print "Usage: prepare_tftp_bootfile.py tftp_dir mac cifs_server share directory image_to_restor cifs_username cifs_password ip netmask gateway" exit(1) - tftp_dir = sys.argv[1] - mac = sys.argv[2] - cifs_server = sys.argv[3] - share = sys.argv[4] - directory = sys.argv[5] - image_to_restore = sys.argv[6] - cifs_username = sys.argv[7] - cifs_password = sys.argv[8] - ip = sys.argv[9] - netmask = sys.argv[10] - gateway = sys.argv[11] + (cmd, tftp_dir, mac, cifs_server, share, directory, template_dir, cifs_username, cifs_password, ip, netmask, gateway) = sys.argv[1:] - - ret = prepare_boot_file() + if cmd == "restore": + ret = prepare(True) + elif cmd == "backup": + ret = prepare(False) + else: + print "Unknown cmd: %s"%cmd + ret = 1 + exit(ret) diff --git a/scripts/util/ipmi.py b/scripts/util/ipmi.py index 3989b4efbb8..40ff2153837 100644 --- a/scripts/util/ipmi.py +++ b/scripts/util/ipmi.py @@ -156,7 +156,26 @@ def power(args): else: return 0 -call_table = {"ping":ping, "boot_dev":boot_dev, "reboot":reboot, "power":power} +def boot_or_reboot(args): + hostname = args.get("hostname") + usrname = args.get("usrname") + password = args.get("password") + o = ipmitool("-H", hostname, "-U", usrname, "-P", password, "chassis", "power", "status") + if o.ret: + print o.stderr + return 1 + + if "is on" in o.stdout: + args["action"] = "reset" + elif "is off" in o.stdout: + args["action"] = "on" + else: + print "unknown power status:" + o.stdout + return 1 + + return power(args) + +call_table = {"ping":ping, "boot_dev":boot_dev, "reboot":reboot, "power":power, "boot_or_reboot":boot_or_reboot} def dispatch(args): cmd = args[1] params = args[2:] diff --git a/server/src/com/cloud/template/TemplateAdapter.java b/server/src/com/cloud/template/TemplateAdapter.java index 5ea98529091..dfd750c9732 100644 --- a/server/src/com/cloud/template/TemplateAdapter.java +++ b/server/src/com/cloud/template/TemplateAdapter.java @@ -5,6 +5,7 @@ import com.cloud.api.commands.DeleteTemplateCmd; import com.cloud.api.commands.RegisterIsoCmd; import com.cloud.api.commands.RegisterTemplateCmd; import com.cloud.exception.ResourceAllocationException; +import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.VMTemplateVO; import com.cloud.utils.component.Adapter; @@ -35,4 +36,9 @@ public interface TemplateAdapter extends Adapter { public TemplateProfile prepareDelete(DeleteIsoCmd cmd); public boolean delete(TemplateProfile profile); + + public TemplateProfile prepare(boolean isIso, Long userId, String name, String displayText, Integer bits, + Boolean passwordEnabled, Boolean requiresHVM, String url, Boolean isPublic, Boolean featured, + Boolean isExtractable, String format, Long guestOSId, Long zoneId, HypervisorType hypervisorType, + String accountName, Long domainId, String chksum, Boolean bootable) throws ResourceAllocationException; } diff --git a/server/src/com/cloud/template/TemplateAdapterBase.java b/server/src/com/cloud/template/TemplateAdapterBase.java index 88d646d8331..1a5b1cbbeaf 100755 --- a/server/src/com/cloud/template/TemplateAdapterBase.java +++ b/server/src/com/cloud/template/TemplateAdapterBase.java @@ -87,7 +87,7 @@ public abstract class TemplateAdapterBase implements TemplateAdapter { (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN)); } - private TemplateProfile prepare(boolean isIso, Long userId, String name, String displayText, Integer bits, + public TemplateProfile prepare(boolean isIso, Long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHVM, String url, Boolean isPublic, Boolean featured, Boolean isExtractable, String format, Long guestOSId, Long zoneId, HypervisorType hypervisorType, String accountName, Long domainId, String chksum, Boolean bootable) throws ResourceAllocationException {