@@ -570,13 +570,62 @@ def _get_target_xml(self):
570570 def _get_source_xml (self ):
571571 return ""
572572
573-
574573class DiskPool (StoragePool ):
575574 """
576- Create a raw disk storage pool
575+ Create a storage pool from a physical disk
577576 """
578- def __init__ (self , * args , ** kwargs ):
579- raise RuntimeError , "Not implemented"
577+
578+ # Register applicable property methods from parent class
579+ source_path = property (StoragePool .get_source_path ,
580+ StoragePool .set_source_path )
581+
582+ formats = [ "auto" , "bsd" , "msdos" , "dvh" , "gpt" , "mac" , "pc98" , "sun" ]
583+
584+ def get_volume_class ():
585+ return DiskVolume
586+ get_volume_class = staticmethod (get_volume_class )
587+
588+ def __init__ (self , conn , name , source_path = None , host = None ,
589+ target_path = None , format = "auto" , uuid = None ):
590+ StoragePool .__init__ (self , name = name , type = StoragePool .TYPE_DISK ,
591+ uuid = None , target_path = target_path , conn = conn )
592+ self .format = format
593+ if source_path :
594+ self .source_path = source_path
595+
596+ def get_format (self ):
597+ return self ._format
598+ def set_format (self , val ):
599+ if not val in self .formats :
600+ raise ValueError (_ ("Unknown Disk format: %s" % val ))
601+ self ._format = val
602+ format = property (get_format , set_format )
603+
604+ def _get_default_target_path (self ):
605+ return DEFAULT_DEV_TARGET
606+
607+ def _get_target_xml (self ):
608+ xml = " <path>%s</path>\n " % escape (self .target_path )
609+ return xml
610+
611+ def _get_source_xml (self ):
612+ if not self .source_path :
613+ raise RuntimeError (_ ("Host path is required" ))
614+
615+ xml = ""
616+ # There is no explicit "auto" type for disk pools, but leaving out
617+ # the format type seems to do the job for existing formatted disks
618+ if self .format != "auto" :
619+ xml = """ <format type="%s"/>\n """ % self .format
620+ xml += """ <device path="%s"/>\n """ % escape (self .source_path )
621+ return xml
622+
623+ def install (self , meter = None , create = False , build = False ):
624+ if self .format == "auto" and build :
625+ raise ValueError (_ ("Must explicitly specify disk format if "
626+ "formatting disk device." ))
627+ StoragePool .install (self , meter = meter , create = create , build = build )
628+
580629class iSCSIPool (StoragePool ):
581630 """
582631 Create an iSCSI based storage pool
0 commit comments