def test_donot_care(self): schema = Schema({'key': str, DoNotCare(str): object}) data = schema.validate({ 'key': 'abc', 'key2': 'bbb', 'key3': [1, 2, 3] }) self.assertEqual({ 'key': 'abc', 'key2': 'bbb', 'key3': [1, 2, 3] }, data) with self.assertRaises(SchemaError): schema.validate({'key2': 'bbb', 'key3': [1, 2, 3]})
def __init__(self): # need a mutex to protect create/delete bond interface self.lock = lock() self.support_fs_type = {} self.conf_file = os.path.join(STORLEVER_CONF_DIR, FS_CONF_FILE_NAME) self.fs_conf_schema = Schema({ "type": Use(str), # filesystem type "dev_file": Use(str), # dev file "dev_uuid": Use(str), # dev uuid "mount_point": Use(str), # mount point of this fs, "mount_option": Use(str), # mount option of this fs "check_onboot": BoolVal(), # fsck fs on boot Optional("comment"): Default(Use(str), default=""), # comment, AutoDel(str): object # for all other key we auto delete }) self.fs_dict_schema = Schema({ DoNotCare(str): self.fs_conf_schema }) # sync fs conf to fstab on boot self.sync_to_fstab()
vg_info = { 'name': vgs[vg].name, 'uuid': vgs[vg].uuid, 'size': vgs[vg].size, 'free_size': vgs[vg].free_size, } vg_dict.append(vg_info) return vg_dict new_vg_schema = Schema({ "vgname": StrRe(r"^([a-zA-Z].+)$"), "dev": Default(ListVal(StrRe(r"^(/dev/sd[a-z]|/dev/md.+)$")), default=[]), DoNotCare(Use(str)): object # for all those key we don't care }) #curl -v -X POST -d vgname=vg1 -d dev=/dev/sdb,/dev/sdc http://192.168.1.123:6543/storlever/api/v1/block/lvm/vg_list #enable eth* or disable eth* @post_view(route_name='vg_list') def create_vg(request): lvm_mng = lvm.lvm_mgr() params = get_params_from_request(request, new_vg_schema) vg = lvm_mng.new_vg(params['vgname'], params['dev']) if vg is None: return Response(status=500) else:
# Specifies the directory ftpd changes to after a local user logs in. default is # empty, which means the user's home directory Optional("local_root"): Default(Use(str), default=""), # When enabled, local users are change-rooted to their home directories after logging in. Optional("chroot_enable"): Default(BoolVal(), default=False), # Only valid when chroot_enable is true. If chroot_list == False, # all local user are placed in a chroot jail upon log in. # Otherwise, only the users, who is in the user list and is chroot enabled, would be # placed in a chroot jail upon log in. Optional("chroot_list"): Default(BoolVal(), default=False), # the umask value for file creation. default is 022(18 in 10-based) Optional("local_umask"): Default(IntVal(min=0, max=0777), default=18), Optional("user_list"): Default(Schema({DoNotCare(str): FTP_USER_CONF_SCHEMA}), default={}), # When enabled, anonymous users are allowed to log in. # The usernames anonymous and ftp are accepted. Optional("anonymous_enable"): Default(BoolVal(), default=False), # When enabled in conjunction with the write_enable directive, # anonymous users are allowed to create new directories within # a parent directory which has write permissions Optional("anon_mkdir_write_enable"): Default(BoolVal(), default=False), # When enabled in conjunction with the write_enable directive, # anonymous users are allowed to upload files within # a parent directory which has write permissions. Optional("anon_upload_enable"): Default(BoolVal(), default=False),
tgt_mgr = tgtmgr.TgtManager return tgt_mgr.get_tgt_conf() tgt_conf_schema = Schema({ # Define iscsi incoming discovery authentication setting. If it is # empty, no authentication is performed. The format is username:passwd Optional("incomingdiscoveryuser"): StrRe(r"^(|\w+:\w+)$"), # Define iscsi outgoing discovery authentication setting. If it is # empty, no authentication is performe The format is username:passwd Optional("outgoingdiscoveryuser"): StrRe(r"^(|\w+:\w+)$"), DoNotCare(Use(str)): object # for all other key we don't care }) @put_view(route_name='tgt_conf') def put_tgt_conf(request): tgt_mgr = tgtmgr.TgtManager tgt_conf = get_params_from_request(request, tgt_conf_schema) tgt_mgr.set_tgt_conf(tgt_conf, operator=request.client_addr) return Response(status=200) @get_view(route_name='tgt_target_iqn_list') def get_tgt_target_iqn_list(request): tgt_mgr = tgtmgr.TgtManager
# they are used at all, is a function of the particular # clock driver. However, by convention flag4 is used to # enable recording monitoring data to the clockstats file # configured with the filegen command. Further information # on the filegen command can be found in Monitoring # Options. # Only valid for reference clock server, i.e. server_addr is 127.127.t.n Optional("flag1"): Default(IntVal(min=0, max=1), default=0), Optional("flag2"): Default(IntVal(min=0, max=1), default=0), Optional("flag3"): Default(IntVal(min=0, max=1), default=0), Optional("flag4"): Default(IntVal(min=0, max=1), default=0), DoNotCare(Use(str)): object # for all other key we don't care }]) @put_view(route_name='ntp_server_list') def put_ntp_server_list(request): ntp_mgr = ntpmgr.NtpManager new_server_list = get_params_from_request(request, ntp_server_list_schema) ntp_mgr.set_server_conf_list(new_server_list, operator=request.client_addr) return Response(status=200) @get_view(route_name='ntp_restrict_list') def get_ntp_restrict_list(request): ntp_mgr = ntpmgr.NtpManager
Optional("realm"): Default(Use(str), default=""), # This is a username which will be used for access to services which are # specified as guest ok (see below). Whatever privileges this user has will # be available to any client connecting to the guest service. This user must # exist in the password file, but does not require a valid login.. Optional("guest_account"): Default(Use(str), default="nobody"), # This controls whether the auto-home share is seen in the list of available shares in # a net view and in the browse list Optional("browseable"): Default(BoolVal(), default=False), Optional("share_list"): Default(Schema({DoNotCare(str): SHARE_CONF_SCHEMA}), default={}), AutoDel(str): object # for all other key we auto delete }) class SmbManager(object): """contains all methods to manage ethernet interface in linux system""" def __init__(self): # need a mutex to protect create/delete bond interface self.lock = lock() self.conf_file = os.path.join(STORLEVER_CONF_DIR, SMB_CONF_FILE_NAME) self.share_conf_schema = SHARE_CONF_SCHEMA self.smb_conf_schema = SMB_CONF_SCHEMA def _load_conf(self):
def test_dict(self): schema = Schema({ "key1": str, # key1 should be string "key2": Use(int), # key3 should be in or int in string "key3": [IntVal(min=10, max=20)], # key4 is optional, Optional("key4"): str, Optional('key5'): Default(IntVal(min=100, max=200), default=100), DoNotCare(str): object # for all those key we don't care }) data = schema.validate({ "key1": "abc", "key2": '123', "key3": [10, 15, 20], "key5": 199, }) self.assertEqual(data, { "key1": "abc", "key2": 123, "key3": [10, 15, 20], "key5": 199 }) data = schema.validate({ "key1": "abc", "key2": '123', "key3": [10, 15, 20], }) self.assertEqual(data, { "key1": "abc", "key2": 123, "key3": [10, 15, 20], "key5": 100 }) data = schema.validate({ "key1": "abc", "key2": '123', "key3": [10, 15, 20], "key4": 'abc' }) self.assertEqual( data, { "key1": "abc", "key2": 123, "key3": [10, 15, 20], "key4": 'abc', "key5": 100 }) data = schema.validate({ "key1": "abc", "key2": '123', "key3": [10, 15, 20], "key4": 'abc', "key100": 'bbc', 'key200': [123, 23, 334] }) self.assertEqual( data, { "key1": "abc", "key2": 123, "key3": [10, 15, 20], "key4": 'abc', "key5": 100, "key100": 'bbc', 'key200': [123, 23, 334] }) with self.assertRaises(SchemaError): schema.validate({ 'key1': 123, "key2": '123', "key3": [10, 15, 20], "key4": 223, }) with self.assertRaises(SchemaError): schema.validate({ 'key1': 123, "key2": '123', "key3": [10, 15, 20], "key4": 'abc', "key100": 'bbc', 'key200': [123, 23, 334] }) with self.assertRaises(SchemaError): schema.validate({ 'key1': 'abc', "key2": '123', "key3": [10, 15, 20], "key4": 'abc', 'key5': 0, "key100": 'bbc', 'key200': [123, 23, 334] })