本文整理汇总了Python中bkr.server.model.Key类的典型用法代码示例。如果您正苦于以下问题:Python Key类的具体用法?Python Key怎么用?Python Key使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Key类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: by_name
def by_name(self,input,*args,**kw):
if 'anywhere' in kw:
search = Key.list_by_name(input,find_anywhere=True)
else:
search = Key.list_by_name(input)
keys = [elem.key_name for elem in search]
return dict(matches=keys)
示例2: test_closing_script_tag_escaped_in_search_bar
def test_closing_script_tag_escaped_in_search_bar(self):
with session.begin():
Key.lazy_create(key_name=u'</script>')
b = self.browser
b.get(get_server_base())
b.find_element_by_link_text('Show Search Options').click()
wait_for_animation(b, '#searchform')
Select(b.find_element_by_name('systemsearch-0.table'))\
.select_by_visible_text('Key/Value')
Select(b.find_element_by_name('systemsearch-0.keyvalue'))\
.select_by_visible_text('</script>')
示例3: save
def save(self, **kw):
if kw["id"]:
key = Key.by_id(kw["id"])
key.key_name = kw["key_name"]
else:
key = Key(key_name=kw["key_name"])
session.add(key)
if "numeric" in kw:
key.numeric = kw["numeric"]
flash(_(u"OK"))
redirect(".")
示例4: save
def save(self, **kw):
if kw['id']:
key = Key.by_id(kw['id'])
key.key_name = kw['key_name']
else:
key = Key(key_name=kw['key_name'])
session.add(key)
if 'numeric' in kw:
key.numeric = kw['numeric']
flash( _(u"OK") )
redirect(".")
示例5: save
def save(self, **kw):
if kw["id"]:
key = Key.by_id(kw["id"])
key.key_name = kw["key_name"]
else:
if Key.query.filter_by(key_name=kw["key_name"]).first():
flash(u"Key Type exists: %s" % kw["key_name"])
redirect(".")
key = Key(key_name=kw["key_name"])
session.add(key)
key.numeric = kw["numeric"]
flash(_(u"OK"))
redirect(".")
示例6: test_by_multiple_key_values
def test_by_multiple_key_values(self):
with session.begin():
self.system = data_setup.create_system()
self.system.key_values_string.append(Key_Value_String(
Key.by_name(u'CPUMODEL'), 'foocodename'))
self.system.key_values_string.append(Key_Value_String(
Key.by_name(u'HVM'), '1'))
self.system.key_values_int.append(Key_Value_Int(
Key.by_name(u'DISKSPACE'), '1024'))
b = self.browser
perform_search(b, [('Key/Value', 'HVM', 'is', '1'),
('Key/Value', 'CPUMODEL', 'is', 'foocodename'),
('Key/Value', 'DISKSPACE', 'greater than', '1000')])
check_system_search_results(b, present=[self.system],
absent=[self.another_system])
示例7: edit
def edit(self, **kw):
values = []
if kw.get("id"):
key = Key.by_id(kw["id"])
values = dict(id=key.id, key_name=key.key_name, numeric=key.numeric)
return dict(form=self.form, action="./save", options={}, value=values)
示例8: test_by_key_value_is_not
def test_by_key_value_is_not(self):
with session.begin():
self.another_system.key_values_string.append(Key_Value_String(
Key.by_name(u'CPUMODEL'), 'foocodename'))
b = self.browser
perform_search(b, [('Key/Value', 'CPUMODEL', 'is not', 'foocodename')],
search_url=u'mine')
check_system_search_results(b, present=[self.system],
absent=[self.another_system])
示例9: _from_csv
def _from_csv(cls,system,data,csv_type,log):
"""
Import data from CSV file into System Objects
"""
if 'key' in data and data['key']:
try:
key = Key.by_name(data['key'])
except InvalidRequestError:
log.append('%s: Invalid Key %s ' % (system.fqdn, data['key']))
return False
else:
log.append('%s: Key must not be blank!' % system.fqdn)
return False
if 'key_value' in data and data['key_value']:
if key.numeric:
system_key_values = system.key_values_int
try:
key_value = Key_Value_Int.by_key_value(system,
key,
data['key_value'])
except InvalidRequestError:
key_value = Key_Value_Int(key=key,
key_value=data['key_value'])
else:
system_key_values = system.key_values_string
try:
key_value = Key_Value_String.by_key_value(system,
key,
data['key_value'])
except InvalidRequestError:
key_value = Key_Value_String(key=key,
key_value=data['key_value'])
else:
log.append('%s: Key Value must not be blank!' % system.fqdn)
return False
deleted = False
if 'deleted' in data:
deleted = smart_bool(data['deleted'])
if deleted:
if key_value in system_key_values:
system.record_activity(user=identity.current.user, service=u'CSV',
action=u'Removed', field=u'Key/Value',
old=u'%s/%s' % (data['key'],data['key_value']), new=u'')
system_key_values.remove(key_value)
if not key_value.id:
session.expunge(key_value)
else:
if key_value not in system_key_values:
system.record_activity(user=identity.current.user, service=u'CSV',
action=u'Added', field=u'Key/Value', old=u'',
new=u'%s/%s' % (data['key'],data['key_value']))
system_key_values.append(key_value)
session.add(key_value)
return True
示例10: test_by_key_value_is_on_removed_systems_page
def test_by_key_value_is_on_removed_systems_page(self):
with session.begin():
system = data_setup.create_system()
removed_system = data_setup.create_system(status=SystemStatus.removed)
removed_system.key_values_string.append(Key_Value_String(
Key.by_name(u'CPUMODEL'), 'foocodename'))
# Key Value search from "Removed Systems"
b = self.browser
perform_search(b, [('Key/Value', 'CPUMODEL', 'is', 'foocodename')],
search_url='removed')
check_system_search_results(b, present=[removed_system],
absent=[system])
示例11: test_xml_filter
def test_xml_filter(self):
with session.begin():
module_key = Key.by_name(u"MODULE")
with_module = data_setup.create_system()
with_module.key_values_string.extend(
[Key_Value_String(module_key, u"cciss"), Key_Value_String(module_key, u"kvm")]
)
without_module = data_setup.create_system()
out = run_client(["bkr", "list-systems", "--xml-filter", '<key_value key="MODULE" />'])
returned_systems = out.splitlines()
self.assert_(with_module.fqdn in returned_systems, returned_systems)
self.assert_(without_module.fqdn not in returned_systems, returned_systems)
示例12: setUpClass
def setUpClass(cls):
cls.browser = cls.get_browser()
login(cls.browser)
cls.system_one_details = { 'fqdn' : u'a1',
'type' : u'Machine',
'arch' : u'i386',
'status' : u'Automated',
'owner' : data_setup.create_user(),}
cls.system_one = data_setup.create_system(**cls.system_one_details)
cls.system_one.loaned = data_setup.create_user()
cls.system_one.numa = Numa(nodes=2)
cls.system_one.key_values_string.append(Key_Value_String(
Key.by_name(u'CPUMODEL'), 'foocodename'))
cls.system_one.key_values_string.append(Key_Value_String(
Key.by_name(u'HVM'), '1'))
cls.system_one.cpu = Cpu(flags=['flag1', 'flag2'])
cls.system_one.key_values_int.append(Key_Value_Int(
Key.by_name(u'DISKSPACE'), '1024'))
cls.system_one.key_values_int.append(Key_Value_Int(
Key.by_name(u'MEMORY'), '4096'))
cls.system_two_details = { 'fqdn' : u'a2',
'type' : u'Prototype',
'arch' : u'x86_64',
'status' : u'Manual',
'owner' : data_setup.create_user(),}
cls.system_two = data_setup.create_system(**cls.system_two_details)
cls.system_two.key_values_int.append(Key_Value_Int(
Key.by_name(u'DISKSPACE'), '900'))
cls.system_two.key_values_string.append(Key_Value_String(
Key.by_name(u'HVM'), '1'))
device_class = DeviceClass.lazy_create(device_class='class_type')
device1 = Device.lazy_create(vendor_id = '0000',
device_id = '0000',
subsys_vendor_id = '2223',
subsys_device_id = '2224',
bus = '0000',
driver = '0000',
device_class_id = device_class.id,
description = 'blah')
cls.system_two.devices.append(device1)
cls.system_three_details = { 'fqdn' : u'a3',
'type' : u'Laptop',
'arch' : u'ia64',
'status' : u'Removed',
'owner' : data_setup.create_user(),}
cls.system_three = data_setup.create_system(**cls.system_three_details)
cls.system_three.numa = Numa(nodes=1)
device2 = Device.lazy_create(vendor_id = '0000',
device_id = '0000',
subsys_vendor_id = '1111',
subsys_device_id = '1112',
bus = '0000',
driver = '0000',
device_class_id = device_class.id,
description = 'blah')
cls.system_three.devices.append(device2)
示例13: test_key_present
def test_key_present(self):
module_key = Key.by_name(u'MODULE')
with_module = data_setup.create_system()
with_module.key_values_string.extend([
Key_Value_String(module_key, u'cciss'),
Key_Value_String(module_key, u'kvm')])
without_module = data_setup.create_system()
self.check_filter("""
<hostRequires>
<key_value key="MODULE" op="==" />
</hostRequires>
""",
present=[with_module], absent=[without_module])
示例14: test_xml_filter
def test_xml_filter(self):
with session.begin():
module_key = Key.by_name(u'MODULE')
with_module = data_setup.create_system()
with_module.key_values_string.extend([
Key_Value_String(module_key, u'cciss'),
Key_Value_String(module_key, u'kvm')])
without_module = data_setup.create_system()
feed_url = urljoin(get_server_base(), '?' + urlencode({
'tg_format': 'atom', 'list_tgp_order': '-date_modified',
'xmlsearch': '<key_value key="MODULE" />'}))
feed = lxml.etree.parse(urlopen(feed_url)).getroot()
self.assert_(self.feed_contains_system(feed, with_module.fqdn))
self.assert_(not self.feed_contains_system(feed, without_module.fqdn))
示例15: test_xml_filter
def test_xml_filter(self):
with session.begin():
module_key = Key.by_name(u'MODULE')
with_module = data_setup.create_system()
with_module.key_values_string.extend([
Key_Value_String(module_key, u'cciss'),
Key_Value_String(module_key, u'kvm')])
without_module = data_setup.create_system()
out = run_client(['bkr', 'system-list',
'--xml-filter', '<key_value key="MODULE" />'])
returned_systems = out.splitlines()
self.assert_(with_module.fqdn in returned_systems, returned_systems)
self.assert_(without_module.fqdn not in returned_systems,
returned_systems)