<s> import os <EOL> import sys <EOL> import re <EOL> import logging <EOL> from optparse import OptionParser <EOL> from ksscommand import KssCommand , KssCommandException , KssCommandOptException <EOL> import __cmd__ <EOL> try : <EOL> import karesansui <EOL> from karesansui import __version__ <EOL> from karesansui . lib . virt . virt import KaresansuiVirtConnection <EOL> from karesansui . lib . utils import load_locale , get_pwd_info , get_grp_info <EOL> from karesansui . lib . const import STORAGE_POOL_TYPE <EOL> except ImportError , e : <EOL> print >> sys . stderr , "<STR_LIT>" % e <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> _ = load_locale ( ) <EOL> usage = '<STR_LIT>' <EOL> def getopts ( ) : <EOL> optp = OptionParser ( usage = usage , version = __version__ ) <EOL> optp . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:name>' , help = _ ( '<STR_LIT:Name>' ) , default = None ) <EOL> optp . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:type>' , help = _ ( '<STR_LIT>' ) , default = None ) <EOL> optp . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = _ ( '<STR_LIT>' ) , default = None ) <EOL> optp . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = _ ( '<STR_LIT>' ) , default = None ) <EOL> optp . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = _ ( '<STR_LIT>' ) , default = None ) <EOL> optp . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = _ ( '<STR_LIT>' ) , default = None ) <EOL> optp . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:label>' , help = _ ( '<STR_LIT>' ) , default = None ) <EOL> optp . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = _ ( '<STR_LIT>' ) , default = None ) <EOL> optp . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , help = _ ( '<STR_LIT>' ) , default = None ) <EOL> return optp . parse_args ( ) <EOL> def chkopts ( opts ) : <EOL> reg = re . compile ( "<STR_LIT>" ) <EOL> if opts . name : <EOL> if reg . search ( opts . name ) : <EOL> raise KssCommandOptException ( '<STR_LIT>' % ( '<STR_LIT>' , opts . name ) ) <EOL> else : <EOL> raise KssCommandOptException ( '<STR_LIT>' % '<STR_LIT>' ) <EOL> if opts . type : <EOL> if opts . type not in STORAGE_POOL_TYPE . values ( ) : <EOL> raise KssCommandOptException ( '<STR_LIT>' % opts . type ) <EOL> else : <EOL> raise KssCommandOptException ( '<STR_LIT>' % '<STR_LIT>' ) <EOL> if opts . type == STORAGE_POOL_TYPE [ "<STR_LIT>" ] : <EOL> if not opts . target_path : <EOL> raise KssCommandOptException ( '<STR_LIT>' % '<STR_LIT>' ) <EOL> elif opts . type == STORAGE_POOL_TYPE [ "<STR_LIT>" ] : <EOL> if not opts . host_name : <EOL> raise KssCommandOptException ( '<STR_LIT>' % '<STR_LIT>' ) <EOL> if not opts . device_path : <EOL> raise KssCommandOptException ( '<STR_LIT>' % '<STR_LIT>' ) <EOL> elif opts . type == STORAGE_POOL_TYPE [ "<STR_LIT>" ] : <EOL> if not opts . target_path : <EOL> raise KssCommandOptException ( '<STR_LIT>' % '<STR_LIT>' ) <EOL> if not opts . device_path : <EOL> raise KssCommandOptException ( '<STR_LIT>' % '<STR_LIT>' ) <EOL> else : <EOL> raise KssCommandOptException ( '<STR_LIT>' % opts . type ) <EOL> if opts . label : <EOL> if reg . search ( opts . label ) : <EOL> raise KssCommandOptException ( '<STR_LIT>' % ( '<STR_LIT>' , opts . label ) ) <EOL> reg = re . compile ( "<STR_LIT>" ) <EOL> if opts . owner : <EOL> if reg . search ( opts . owner ) : <EOL> if opts . owner not in [ user [ <NUM_LIT:0> ] for user in get_pwd_info ( ) ] : <EOL> raise KssCommandOptException ( '<STR_LIT>' % ( opts . owner ) ) <EOL> else : <EOL> if int ( opts . owner ) not in [ user [ <NUM_LIT:2> ] for user in get_pwd_info ( ) ] : <EOL> raise KssCommandOptException ( '<STR_LIT>' % ( opts . owner ) ) <EOL> if opts . group : <EOL> if reg . search ( opts . group ) : <EOL> if opts . group not in [ group [ <NUM_LIT:0> ] for group in get_grp_info ( ) ] : <EOL> raise KssCommandOptException ( '<STR_LIT>' % ( opts . group ) ) <EOL> else : <EOL> if int ( opts . group ) not in [ group [ <NUM_LIT:2> ] for group in get_grp_info ( ) ] : <EOL> raise KssCommandOptException ( '<STR_LIT>' % ( opts . group ) ) <EOL> reg = re . compile ( "<STR_LIT>" ) <EOL> if opts . mode : <EOL> if not reg . match ( opts . mode ) : <EOL> raise KssCommandOptException ( '<STR_LIT>' % ( opts . mode ) ) <EOL> class CreateStoragePool ( KssCommand ) : <EOL> def process ( self ) : <EOL> ( opts , args ) = getopts ( ) <EOL> chkopts ( opts ) <EOL> self . up_progress ( <NUM_LIT:10> ) <EOL> conn = KaresansuiVirtConnection ( readonly = False ) <EOL> try : <EOL> inactive_storage_pools = conn . list_inactive_storage_pool ( ) <EOL> active_storage_pools = conn . list_active_storage_pool ( ) <EOL> self . up_progress ( <NUM_LIT:10> ) <EOL> if opts . name in active_storage_pools or opts . name in inactive_storage_pools : <EOL> raise KssCommandException ( '<STR_LIT>' % opts . name ) <EOL> try : <EOL> if opts . type == STORAGE_POOL_TYPE [ "<STR_LIT>" ] : <EOL> if conn . create_storage_pool ( opts . name , opts . type , <EOL> opts . target_path , <EOL> target_p_group = opts . group , target_p_label = opts . label , <EOL> target_p_mode = opts . mode , target_p_owner = opts . owner , <EOL> ) is False : <EOL> raise KssCommandException ( '<STR_LIT>' % opts . name ) <EOL> elif opts . type == STORAGE_POOL_TYPE [ "<STR_LIT>" ] : <EOL> if conn . create_storage_pool ( opts . name , opts . type , <EOL> target_path = "<STR_LIT>" , <EOL> source_h_name = opts . host_name , <EOL> source_dev_path = opts . device_path , <EOL> target_p_group = opts . group , target_p_label = opts . label , <EOL> target_p_mode = opts . mode , target_p_owner = opts . owner , <EOL> ) is False : <EOL> raise KssCommandException ( '<STR_LIT>' % opts . name ) <EOL> elif opts . type == STORAGE_POOL_TYPE [ "<STR_LIT>" ] : <EOL> if conn . create_storage_pool ( opts . name , opts . type , <EOL> opts . target_path , <EOL> source_dev_path = opts . device_path , <EOL> target_p_group = opts . group , target_p_label = opts . label , <EOL> target_p_mode = opts . mode , target_p_owner = opts . owner , <EOL> ) is False : <EOL> raise KssCommandException ( '<STR_LIT>' % opts . name ) <EOL> else : <EOL> raise KssCommandOptException ( '<STR_LIT>' % opts . type ) <EOL> self . up_progress ( <NUM_LIT:20> ) <EOL> inactive_storage_pools = conn . list_inactive_storage_pool ( ) <EOL> active_storage_pools = conn . list_active_storage_pool ( ) <EOL> if not ( opts . name in active_storage_pools or opts . name in inactive_storage_pools ) : <EOL> raise KssCommandException ( <EOL> '<STR_LIT>' % opts . name ) <EOL> self . up_progress ( <NUM_LIT:20> ) <EOL> flag = True <EOL> if conn . autostart_storage_pool ( flag ) is False : <EOL> raise KssCommandException ( <EOL> '<STR_LIT>' <EOL> % ( opts . name ) ) <EOL> ret = conn . is_autostart_storage_pool ( ) <EOL> if not ( ret is flag ) : <EOL> raise KssCommandException ( <EOL> '<STR_LIT>' % ( opts . name , str ( ret ) ) ) <EOL> self . logger . info ( '<STR_LIT>' % ( opts . name ) ) <EOL> print >> sys . stdout , _ ( '<STR_LIT>' ) % ( opts . name ) <EOL> return True <EOL> except KssCommandException , e : <EOL> raise e <EOL> finally : <EOL> conn . close ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> target = CreateStoragePool ( ) <EOL> sys . exit ( target . run ( ) ) </s>
