def test_optional_value(self): schema = Schema({"key": str, Optional("op_key"): IntVal()}) data = schema.validate({"key": "abc"}) self.assertEqual({"key": "abc"}, data) data = schema.validate({'key': 'abc', 'op_key': 123}) self.assertEqual({'key': 'abc', 'op_key': 123}, data) with self.assertRaises(SchemaError): schema.validate({'key': 'abc', 'op_key': 'bcd'})
def test_list(self): schema = Schema([str]) self.assertEqual(schema.validate(['abc', 'bbc', 'ddc']), ['abc', 'bbc', 'ddc']) with self.assertRaises(SchemaError): schema.validate(['abc', 123, 'bbc']) schema = Schema([IntVal(min=10, max=20)]) self.assertEqual(schema.validate([10, 12, 19, 11]), [10, 12, 19, 11]) with self.assertRaises(SchemaError): schema.validate([10, 12, 21])
def test_default_value(self): schema = Schema({ "key": str, Optional('op_key'): Default(IntVal(min=10), default=50) }) data = schema.validate({'key': 'abc'}) self.assertEqual({'key': 'abc', 'op_key': 50}, data) data = schema.validate({'key': 'abc', 'op_key': 20}) self.assertEqual({'key': 'abc', 'op_key': 20}, data) with self.assertRaises(SchemaError): schema.validate({'key': 'abc', 'op_key': 0})
def test_int_value(self): schema = Schema(IntVal()) self.assertEquals(10, schema.validate(10)) self.assertEquals(10, schema.validate('10')) with self.assertRaises(SchemaError): schema.validate('abc') schema = Schema(IntVal(values=(0, 1))) self.assertEqual(1, schema.validate(1)) self.assertEqual(1, schema.validate("1")) with self.assertRaises(SchemaError): schema.validate(2) with self.assertRaises(SchemaError): schema.validate("2") schema = Schema(IntVal(min=10, max=100)) self.assertEqual(10, schema.validate(10)) self.assertEqual(100, schema.validate('100')) self.assertEqual(50, schema.validate(50)) with self.assertRaises(SchemaError): schema.validate(200) with self.assertRaises(SchemaError): schema.validate(0) schema = Schema(IntVal(min=10, max=100, values=(0, 1))) self.assertEqual(0, schema.validate(0)) self.assertEqual(100, schema.validate(100)) self.assertEqual(50, schema.validate('50')) with self.assertRaises(SchemaError): schema.validate(2) with self.assertRaises(SchemaError): schema.validate(200) schema = Schema(IntVal(min=10, values=(0, 1))) self.assertEqual(200, schema.validate(200)) self.assertEqual(1, schema.validate(1)) with self.assertRaises(SchemaError): schema.validate(3)
for bond_name in bond_name_list: bond_object = bond_manager.get_group_by_name(bond_name) bond_info = { 'name': bond_object.name, 'mode': bond_object.mode, 'miimon': bond_object.miimon, 'slaves': bond_object.slaves } bond_info_dict.append(bond_info) return bond_info_dict bond_add_schema = Schema({ "mode": IntVal(0, 6), "miimon": IntVal(0, 65535), Optional("ifs"): Default(ListVal(Use(str)), default=[]), Optional("ip"): Default(StrRe(r"^(|\d+\.\d+\.\d+\.\d+)$"), default=""), # ip addr Optional("netmask"): Default(StrRe(r"^(|\d+\.\d+\.\d+\.\d+)$"), default=""), # netmask addr Optional("gateway"): Default(StrRe(r"^(|\d+\.\d+\.\d+\.\d+)$"), default=""), # gateway addr DoNotCare(Use(str)): object # for all those key we don't care })
return Response(status=200) @get_view(route_name='tgt_target_lun_list') def get_tgt_target_lun_list(request): iqn = request.matchdict['target_iqn'] tgt_mgr = tgtmgr.TgtManager target = tgt_mgr.get_target_by_iqn(iqn) return target.get_lun_list() lun_conf_schema = Schema({ # lun number "lun": IntVal(1, 255), # path to a regular file, or block device, or a sg char device Optional("path"): StrRe(r"^\S+$"), # the type of device . Possible device-types are: # disk : emulate a disk device # tape : emulate a tape reader # ssc : same as tape # cd : emulate a DVD drive # changer : emulate a media changer device # pt : passthrough type to export a /dev/sg device Optional("device_type"): StrRe(r"^(disk|tape|ssc|cd|changer|pt)$"),
#curl -v -X delete http://192.168.1.123:6543/storlever/api/v1/block/md_list/name @delete_view(route_name='md') def delete_md_rest(request): md_mgr = md.md_mgr() mds = md_mgr.get_all_md() name = request.matchdict['md_name'] mds.delete(name) return Response(status=200) md_op_schema = Schema({ "opt": StrRe(r"^(refresh|remove|add|grow)$"), Optional("dev"): StrRe(r"^(/dev/sd[a-z]|/dev/vxd[a-z])$"), Optional("sum"): IntVal(), DoNotCare(Use(str)): object # for all those key we don't care }) #curl -v -X post -d opt=refresh http://192.168.1.123:6543/storlever/api/v1/block/md_list/name/opt @post_view(route_name='md_op') def post_md_op(request): params = get_params_from_request(request, md_op_schema) md_name = request.matchdict['md_name'] mds_mgr = md.md_mgr() mds = mds_mgr.get_all_md() md_mgr = mds.get_md(md_name) if (params['opt']) == 'refresh': md_mgr.refresh()
"comment": "Provides the support of zabbix agent config for storlever" } ZABBIX_AGENT_CONF_FILE_NAME = "zabbix_agentd_conf.yaml" ZABBIX_AGENT_ETC_CONF_DIR = "/etc/zabbix/" ZABBIX_AGENT_CONF_FILE = "zabbix_agentd.conf" ZABBIX_AGENT_CONF_SCHEMA = Schema({ Optional("hostname"): Default(Use(str), default=""), # How often list of active checks is refreshed, in seconds. # Note that after failing to refresh active checks the next refresh # will be attempted after 60 seconds. Optional("refresh_active_check"): Default(IntVal(min=60, max=3600), default=120), # the server ip:port list for active check.zabbix_agent would get the active check list # from each server at the refresh_active_check frequency. Entry string Format is IP:PORT Optional("active_check_server_list"): Default([Use(str)], default=[]), # the server ip list for passive check. each passive check's source ip must # exist in this list. Entry string Format is IP Optional("passive_check_server_list"): Default([Use(str)], default=[]), AutoDel(str): object # for all other key we auto delete })
# ipv6 address in DNS resolution Optional("ipv6"): Default(BoolVal(), default=False), # Marks the server as preferred. All other things being equal, # this host will be chosen for synchronization among set of correctly operating hosts Optional("prefer"): Default(BoolVal(), default=False), # Specifies a mode number which is interpreted in a device # specific fashion. For instance, it selects a dialing, # protocol in the ACTS driver and a device subtype in the # parse drivers. # Only valid for reference clock server, i.e. server_addr is 127.127.t.n Optional("mode"): Default(IntVal(min=0, max=65535), default=0), # Specifies the stratum number assigned to the driver, an # integer between 0 and 15. This number overrides the # default stratum number ordinarily assigned by the driver # itself, usually zero. # Only valid for reference clock server, i.e. server_addr is 127.127.t.n Optional("stratum"): Default(IntVal(min=0, max=15), default=0), # These four flags are used for customizing the clock # driver. The interpretation of these values, and whether # 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
# This is a text field that is seen next to a share when a client does a # queries the server, either via the network neighborhood or via net view to # list what shares are available. Default is empty Optional("comment"): Default(Use(str), default=""), # When a file is created, the necessary permissions are calculated according # to the mapping from DOS modes to UNIX permissions, and the resulting UNIX # mode is then bit-wise ?AND?ed with this parameter. This parameter may be # thought of as a bit-wise MASK for the UNIX modes of a file. Any bit not set # here will be removed from the modes set on a file when it is created. # Default is 0744, which means removes the group and other write and # execute bits from the UNIX modes. Optional("create_mask"): Default(IntVal(min=0, max=0777), default=0744), # This parameter is the octal modes which are used when converting DOS modes # to UNIX modes when creating UNIX directories. # When a directory is created, the necessary permissions are calculated # according to the mapping from DOS modes to UNIX permissions, and the # resulting UNIX mode is then bit-wise ANDed with this parameter. This # parameter may be thought of as a bit-wise MASK for the UNIX modes of a # directory. Any bit not set here will be removed from the modes set on a # directory when it is created # default is 755, which means removes the ?group? and ?other? write # bits from the UNIX mode, allowing only the user who owns the directory to # modify it. Optional("directory_mask"): Default(IntVal(min=0, max=0777), default=0755),
'/nas/smb/account_list/{account_name}') @get_view(route_name='ftp_conf') def get_ftp_conf(request): ftp_mgr = ftpmgr.FtpManager return ftp_mgr.get_ftp_conf() ftp_conf_schema = Schema({ Optional("listen"): BoolVal(), # ftp service listen on ipv4 port Optional("listen6"): BoolVal(), # ftp service listen on ipv6 port Optional("listen_port"): IntVal(min=1, max=65535), # ftp port number # The maximum amount of time between commands from a remote client. # Once triggered, the connection to the remote client is closed Optional("idle_session_timeout"): Use(int), # the maximum data transfer rate for anonymous users in bytes per second. # The default value is 0, which does not limit the transfer rate. Optional("anon_max_rate"): Use(int), # the maximum rate data is transferred for local users in bytes per second. # The default value is 0, which does not limit the transfer rate. Optional("local_max_rate"): Use(int),
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] })
scsi_list_dict.append(scsi_dev) return scsi_list_dict # http://192.168.1.10:6543/storlever/api/v1/block/scsi/host_list @get_view(route_name='dev_host_list') def host_list_get(request): scsi_mgr = scsimgr.scsi_mgr() scsi_list = scsi_mgr.get_scsi_host_list() return scsi_list scan_bus_schema = Schema({ Optional("opt"): StrRe(r"^(re_scan)$"), Optional("host"): Default(ListVal(IntVal(0, 16)), default=[]), Optional("channels"): Default(ListVal(IntVal(0, 1)), default=[]), Optional("targets"): Default(ListVal(IntVal(0, 16)), default=[]), Optional("luns"): Default(ListVal(IntVal(0, 7)), default=[]), Optional("remove"): BoolVal(), Optional("force_rescan"): BoolVal(), Optional("force_remove"): BoolVal(), DoNotCare(Use(str)): object # for all those key we don't care }) # curl -v -X put -d opt=re_scan http://192.168.1.10:6543/storlever/api/v1/block/scsi/scan_bus @put_view(route_name='scan_bus') def scan_bus(request): scsi_mgr = scsimgr.scsi_mgr() params = get_params_from_request(request, scan_bus_schema) remove = params.get("remove", False), force_rescan = params.get("force_rescan", False),
# it can be a ipv4 address, ipv6 address, or host dns name "server_addr": Use(str), # if set to True, it would be forced to resolve the host name to # ipv6 address in DNS resolution Optional("ipv6"): Default(BoolVal(), default=False), # Marks the server as preferred. All other things being equal, # this host will be chosen for synchronization among set of correctly operating hosts Optional("prefer"): Default(BoolVal(), default=False), # Specifies a mode number which is interpreted in a device # specific fashion. For instance, it selects a dialing, # protocol in the ACTS driver and a device subtype in the # parse drivers. # Only valid for reference clock server, i.e. server_addr is 127.127.t.n Optional("mode"): Default(IntVal(min=0, max=65535), default=0), # Specifies the stratum number assigned to the driver, an # integer between 0 and 15. This number overrides the # default stratum number ordinarily assigned by the driver # itself, usually zero. # Only valid for reference clock server, i.e. server_addr is 127.127.t.n Optional("stratum"): Default(IntVal(min=0, max=15), default=0), # These four flags are used for customizing the clock # driver. The interpretation of these values, and whether # 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
VSFTPD_ETC_CHROOT_LIST = "chroot_list" FTP_USER_CONF_SCHEMA = Schema({ "user_name": Use(str), # When enabled, the user can log in ftp Optional("login_enable"): Default(BoolVal(), default=True), # When enabled, the user will be placed into the chroot jail Optional("chroot_enable"): Default(BoolVal(), default=False), AutoDel(str): object # for all other key we auto delete }) FTP_CONF_SCHEMA = Schema({ Optional("listen"): Default(BoolVal(), default=False), # ftp service listen on ipv4 port Optional("listen6"): Default(BoolVal(), default=False), # ftp service listen on ipv6 port Optional("listen_port"): Default(IntVal(min=1, max=65535), default=21), # ftp port number # The maximum amount of time between commands from a remote client. # Once triggered, the connection to the remote client is closed Optional("idle_session_timeout"): Default(Use(int), default=300), # the maximum data transfer rate for anonymous users in bytes per second. # The default value is 0, which does not limit the transfer rate. Optional("anon_max_rate"): Default(Use(int), default=0), # the maximum rate data is transferred for local users in bytes per second. # The default value is 0, which does not limit the transfer rate. Optional("local_max_rate"): Default(Use(int), default=0), # the maximum number of simultaneous clients allowed to connect to # the server when it is running in standalone mode. Any additional client # connections would result in an error message.
return Response(status=200) #curl -v -X delete http://192.168.1.123:6543/storlever/api/v1/block/lvm/vg_list/{vg} @delete_view(route_name='vg') def delete_vg_rest(request): vg_name = request.matchdict['vg'] lvm_mng = lvm.lvm_mgr() vg = lvm_mng.get_vg(vg_name) vg.delete() return Response(status=200) add_lv_schema = Schema({ "lvname": StrRe(r"^([a-zA-Z].+)$"), "size": IntVal(1024), #min 1024 DoNotCare(Use(str)): object # for all those key we don't care }) #curl -v -X post -d lvname=vgx size=204800000 http://192.168.1.123:6543/storlever/api/v1/block/lvm/vg_list/{vg} @post_view(route_name='vg') def add_lv(request): vg_name = request.matchdict['vg'] lvm_mng = lvm.lvm_mgr() vg = lvm_mng.get_vg(vg_name) params = get_params_from_request(request, add_lv_schema) lv = vg.create_lv(params['lvname'], params['size']) if vg is None: return Response(status=500) else:
# enable the default monitors for system Optional("default_monitors"): Default(BoolVal(), default=False), # system 1 minutes load max threshold for default load monitor, # if it's 0, this monitor never report error Optional("load_max"): Default(Use(float), default=0), # swap space min threshold for default memory monitor, in kB Optional("swap_min"): Default(Use(int), default=16384), # disk space min percent for the default disk usage monitor, 0 means never report error Optional("disk_min_percent"): Default(IntVal(0, 99), default=0), Optional("community_list"): Default([SNMP_COMMUNITY_CONF_SCHEMA], default=[]), Optional("trapsink_list"): Default([SNMP_SINK_CONF_SCHEMA], default=[]), Optional("monitor_list"): Default([SNMP_MONITOR_CONF_SCHEMA], default=[]), AutoDel(str): object # for all other key we auto delete }) class SnmpAgentManager(object): """contains all methods to manage NTP server in linux system""" def __init__(self): # need a mutex to protect create/delete bond interface