本文整理汇总了Python中bkr.server.model.LabController类的典型用法代码示例。如果您正苦于以下问题:Python LabController类的具体用法?Python LabController怎么用?Python LabController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LabController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_labcontroller_helper
def _create_labcontroller_helper(data):
with convert_internal_errors():
if LabController.query.filter_by(fqdn=data['fqdn']).count():
raise Conflict409('Lab Controller %s already exists' % data['fqdn'])
user = find_user_or_create(data['user_name'])
user = update_user(
user=user,
display_name=data['fqdn'],
email_address=data.get('email_address', user.email_address),
password=data.get('password', user.password)
)
labcontroller = LabController(fqdn=data['fqdn'], disabled=False)
labcontroller.record_activity(
user=identity.current.user, service=u'HTTP',
action=u'Changed', field=u'FQDN', old=u'', new=data['fqdn'])
labcontroller.user = user
labcontroller.record_activity(
user=identity.current.user, service=u'HTTP',
action=u'Changed', field=u'User', old=u'', new=user.user_name)
# For backwards compatibility
labcontroller.record_activity(
user=identity.current.user, service=u'HTTP',
action=u'Changed', field=u'Disabled', old=u'', new=unicode(labcontroller.disabled))
session.add(labcontroller)
# flush it so we return an id, otherwise we'll end up back in here from
# the edit form
session.flush()
response = jsonify(labcontroller.__json__())
response.status_code = 201
return response
示例2: create_labcontroller
def create_labcontroller(fqdn=None, user=None):
if fqdn is None:
fqdn = unique_name(u'lab%s.testdata.invalid')
try:
lc = LabController.by_name(fqdn)
except NoResultFound:
if user is None:
user = User(user_name='host/%s' % fqdn)
lc = LabController(fqdn=fqdn)
lc.user = user
user.groups.append(Group.by_name(u'lab_controller'))
return lc
log.debug('labcontroller %s already exists' % fqdn)
return lc
示例3: save
def save(self, **kw):
if kw.get('id'):
labcontroller = LabController.by_id(kw['id'])
else:
labcontroller = LabController()
session.add(labcontroller)
if labcontroller.fqdn != kw['fqdn']:
activity = LabControllerActivity(identity.current.user,
'WEBUI', 'Changed', 'FQDN', labcontroller.fqdn, kw['fqdn'])
labcontroller.fqdn = kw['fqdn']
labcontroller.write_activity.append(activity)
# labcontroller.user is used by the lab controller to login here
try:
# pick up an existing user if it exists.
luser = User.query.filter_by(user_name=kw['lusername']).one()
except InvalidRequestError:
# Nope, create from scratch
luser = User()
if labcontroller.user != luser:
if labcontroller.user is None:
old_user_name = None
else:
old_user_name = labcontroller.user.user_name
activity = LabControllerActivity(identity.current.user, 'WEBUI',
'Changed', 'User', old_user_name, unicode(kw['lusername']))
labcontroller.user = luser
labcontroller.write_activity.append(activity)
# Make sure user is a member of lab_controller group
group = Group.by_name(u'lab_controller')
if group not in luser.groups:
luser.groups.append(group)
luser.display_name = kw['fqdn']
luser.email_address = kw['email']
luser.user_name = kw['lusername']
if kw['lpassword']:
luser.password = kw['lpassword']
if labcontroller.disabled != kw['disabled']:
activity = LabControllerActivity(identity.current.user, 'WEBUI',
'Changed', 'Disabled', unicode(labcontroller.disabled),
unicode(kw['disabled']))
labcontroller.disabled = kw['disabled']
labcontroller.write_activity.append(activity)
flash( _(u"%s saved" % labcontroller.fqdn) )
redirect(".")
示例4: remove
def remove(self, id, *args, **kw):
labcontroller = LabController.by_id(id)
labcontroller.removed = datetime.utcnow()
# de-associate systems
systems = System.query.filter(System.lab_controller == labcontroller)
System.record_bulk_activity(systems, user=identity.current.user,
service=u'WEBUI', action=u'Changed', field=u'lab_controller',
old=labcontroller.fqdn, new=None)
systems.update({'lab_controller_id': None}, synchronize_session=False)
# cancel running recipes
watchdogs = Watchdog.by_status(labcontroller=labcontroller,
status='active')
for w in watchdogs:
w.recipe.recipeset.job.cancel(msg='LabController %s has been deleted' % labcontroller.fqdn)
# remove distro trees
distro_tree_assocs = LabControllerDistroTree.query\
.filter(LabControllerDistroTree.lab_controller == labcontroller)\
.join(LabControllerDistroTree.distro_tree)
DistroTree.record_bulk_activity(distro_tree_assocs, user=identity.current.user,
service=u'WEBUI', action=u'Removed', field=u'lab_controller_assocs',
old=labcontroller.fqdn, new=None)
distro_tree_assocs.delete(synchronize_session=False)
labcontroller.disabled = True
labcontroller.record_activity(user=identity.current.user, service=u'WEBUI',
field=u'Disabled', action=u'Changed', old=unicode(False), new=unicode(True))
labcontroller.record_activity(user=identity.current.user, service=u'WEBUI',
field=u'Removed', action=u'Changed', old=unicode(False), new=unicode(True))
flash( _(u"%s removed") % labcontroller.fqdn )
raise redirect(".")
示例5: test_lookup_secret_fqdn
def test_lookup_secret_fqdn(self):
with session.begin():
system = data_setup.create_system()
system.private = True
lab_controller_user = LabController.by_name(self.lc_fqdn).user
system2 = System.by_fqdn(str(system.fqdn), user=lab_controller_user)
self.assertEquals(system, system2)
示例6: index
def index(self, **kwargs):
kwargs.setdefault('tag', 'STABLE')
value = dict((k, v) for k, v in kwargs.iteritems()
if k in ['osmajor', 'tag', 'distro'])
options = {}
tags = DistroTag.used()
options['tag'] = [('', 'None selected')] + \
[(tag.tag, tag.tag) for tag in tags]
options['osmajor'] = [('', 'None selected')] + \
[(osmajor.osmajor, osmajor.osmajor) for osmajor
in OSMajor.ordered_by_osmajor(OSMajor.in_any_lab())]
options['distro'] = self._get_distro_options(**kwargs)
options['lab_controller_id'] = [(None, 'None selected')] + \
LabController.get_all(valid=True)
options['distro_tree_id'] = self._get_distro_tree_options(**kwargs)
attrs = {}
if not options['distro']:
attrs['distro'] = dict(disabled=True)
return dict(title=_(u'Reserve Workflow'),
widget=self.widget,
value=value,
widget_options=options,
widget_attrs=attrs)
示例7: index
def index(self, **kwargs):
value = dict((k, v) for k, v in kwargs.iteritems()
if k in ['osmajor', 'tag', 'distro'])
options = {}
tags = DistroTag.used()
# It's important that 'None selected' is prepended
# rather then appended to the list of tags, as that will ensure
# it is the default option in the drop down.
options['tag'] = [('', 'None selected')] + \
[(tag.tag, tag.tag) for tag in tags]
options['osmajor'] = [('', 'None selected')] + \
[(osmajor.osmajor, osmajor.osmajor) for osmajor
in OSMajor.ordered_by_osmajor(OSMajor.in_any_lab())]
options['distro'] = self._get_distro_options(**kwargs)
options['lab_controller_id'] = [(None, 'None selected')] + \
LabController.get_all(valid=True)
options['distro_tree_id'] = self._get_distro_tree_options(**kwargs)
attrs = {}
if not options['distro']:
attrs['distro'] = dict(disabled=True)
return dict(title=_(u'Reserve Workflow'),
widget=self.widget,
value=value,
widget_options=options,
widget_attrs=attrs)
示例8: yum_config
def yum_config(self, distro_tree_id, *args, **kwargs):
# Ignore positional args, so that we can make nice URLs like
# /distrotrees/yum_config/12345/RHEL-6.2-Server-i386.repo
try:
distro_tree = DistroTree.by_id(int(distro_tree_id))
except (ValueError, NoResultFound):
raise cherrypy.NotFound(distro_tree_id)
if not kwargs.get('lab'):
lc = distro_tree.lab_controller_assocs[0].lab_controller
else:
try:
lc = LabController.by_name(kwargs['lab'])
except NoResultFound:
raise cherrypy.HTTPError(status=400,
message='No such lab controller %r' % kwargs['lab'])
base = distro_tree.url_in_lab(lc, scheme='http')
if not base:
raise cherrypy.HTTPError(status=404,
message='%s is not present in lab %s' % (distro_tree, lc))
if not distro_tree.repos:
return '# No repos for %s' % distro_tree
sections = []
for repo in distro_tree.repos:
sections.append('''[%s]
name=%s
baseurl=%s
enabled=1
gpgcheck=0
''' % (repo.repo_id, repo.repo_id, urlparse.urljoin(base, repo.path)))
return '\n'.join(sections)
示例9: lab_controller_add
def lab_controller_add(self, distro_tree_id, lab_controller_id, url):
try:
distro_tree = DistroTree.by_id(distro_tree_id)
except NoResultFound:
flash(_(u'Invalid distro tree id %s') % distro_tree_id)
redirect('.')
try:
lab_controller = LabController.by_id(lab_controller_id)
except NoResultFound:
flash(_(u'Invalid lab controller id %s') % lab_controller_id)
redirect(str(distro_tree.id))
url = url.strip()
if not url.endswith('/'):
url = url + '/'
if not urlparse.urlparse(url).scheme:
flash(_(u'URL %r is not absolute') % url)
redirect(str(distro_tree.id))
distro_tree.lab_controller_assocs.append(
LabControllerDistroTree(lab_controller=lab_controller, url=url))
distro_tree.activity.append(DistroTreeActivity(
user=identity.current.user, service=u'WEBUI',
action=u'Added', field_name=u'lab_controller_assocs',
old_value=None, new_value=u'%s %s' % (lab_controller, url)))
flash(_(u'Added %s %s') % (lab_controller, url))
redirect(str(distro_tree.id))
示例10: doit
def doit():
distro_trees = []
for id in request.form.getlist('distro_tree_id'):
try:
distro_trees.append(DistroTree.by_id(id))
except NoResultFound:
raise BadRequest400('Distro tree %r does not exist' % id)
job_details = {}
job_details['pick'] = request.form.get('pick') or 'auto'
if job_details['pick'] == 'fqdn':
try:
job_details['system'] = System.by_fqdn(request.form.get('system'),
identity.current.user)
except NoResultFound:
raise BadRequest400('System %s not found' % request.form.get('system'))
elif job_details['pick'] == 'lab':
try:
job_details['lab'] = LabController.by_name(request.form.get('lab'))
except NoResultFound:
raise BadRequest400('Lab controller %s not found' % request.form.get('lab'))
days = int(request.form.get('reserve_days') or DEFAULT_RESERVE_DAYS)
days = min(days, MAX_DAYS_PROVISION)
job_details['reservetime'] = days * 24 * 60 * 60
job_details['whiteboard'] = request.form.get('whiteboard')
job_details['ks_meta'] = request.form.get('ks_meta')
job_details['koptions'] = request.form.get('koptions')
job_details['koptions_post'] = request.form.get('koptions_post')
with convert_internal_errors():
job = Job.provision_system_job(distro_trees, **job_details)
return 'Created %s' % job.t_id, 201, [('Location', absolute_url('/jobs/%s' % job.id))]
示例11: _check_lc_leaks
def _check_lc_leaks(self):
with session.begin():
lc = LabController.by_name(lc_fqdn)
# check for outstanding watchdogs
watchdogs = Watchdog.query\
.join(Watchdog.recipe).join(Recipe.recipeset)\
.filter(RecipeSet.lab_controller == lc)
if watchdogs.count():
# If your test case hits this error, you need to fix it so that
# any running recipes are cancelled otherwise beaker-watchdog
# will eventually pick them up and abort them, interfering with
# some later test.
raise AssertionError('Leaked watchdogs for %s: %s'
% (lc_fqdn, watchdogs.all()))
# check for systems left associated to the LC
systems = System.query.filter(System.lab_controller == lc)
if systems.count():
# If your test case hits this error, you need to fix it so that
# any systems which were associated to the LC are
# de-associated, otherwise subsequent tests which invoke the
# scheduler will try to schedule recipes onto the system and
# then beaker-provision will start trying to run the
# provisioning commands.
raise AssertionError('Leaked systems for %s: %s'
% (lc_fqdn, systems.all()))
示例12: validate_python
def validate_python(self, form_fields, state):
lc_id = form_fields.get('id', None)
email_address = form_fields['email']
user_name = form_fields['lusername']
try:
User.by_email_address(email_address)
except NoResultFound:
email_is_used = False
else:
email_is_used = True
if User.by_user_name(user_name):
new_user = False
else:
new_user = True
if not lc_id:
labcontroller = None
luser = None
else:
labcontroller = LabController.by_id(lc_id)
luser = labcontroller.user
try:
if not labcontroller and email_is_used: # New LC using dupe email
raise ValueError
if new_user and email_is_used: #New user using dupe email
raise ValueError
if luser:
_check_user_email(email_address, luser.user_id)
except ValueError:
error = {'email' : self.message('not_unique', state)}
raise Invalid('Email address is not unique', form_fields,
state, error_dict=error)
示例13: remove
def remove(self, id, *args, **kw):
try:
labcontroller = LabController.by_id(id)
labcontroller.removed = datetime.utcnow()
systems = System.query.filter_by(lab_controller_id=id).values(System.id)
for system_id in systems:
sys_activity = SystemActivity(identity.current.user, 'WEBUI', \
'Changed', 'lab_controller', labcontroller.fqdn,
None, system_id=system_id[0])
system_table.update().where(system_table.c.lab_controller_id == id).\
values(lab_controller_id=None).execute()
watchdogs = Watchdog.by_status(labcontroller=labcontroller,
status='active')
for w in watchdogs:
w.recipe.recipeset.job.cancel(msg='LabController %s has been deleted' % labcontroller.fqdn)
for lca in labcontroller._distro_trees:
lca.distro_tree.activity.append(DistroTreeActivity(
user=identity.current.user, service=u'WEBUI',
action=u'Removed', field_name=u'lab_controller_assocs',
old_value=u'%s %s' % (lca.lab_controller, lca.url),
new_value=None))
session.delete(lca)
labcontroller.disabled = True
LabControllerActivity(identity.current.user, 'WEBUI',
'Changed', 'Disabled', unicode(False), unicode(True),
lab_controller_id=id)
LabControllerActivity(identity.current.user, 'WEBUI',
'Changed', 'Removed', unicode(False), unicode(True),
lab_controller_id=id)
session.commit()
finally:
session.close()
flash( _(u"%s removed") % labcontroller.fqdn )
raise redirect(".")
示例14: has_active_recipes
def has_active_recipes(self, id):
labcontroller = LabController.by_id(id)
count = Watchdog.by_status(labcontroller=labcontroller, status='active').count()
if count:
return {'has_active_recipes' : True}
else:
return {'has_active_recipes' : False}
示例15: find_labcontroller_or_raise404
def find_labcontroller_or_raise404(fqdn):
"""Returns a lab controller object or raises a NotFound404 error if the lab
controller does not exist in the database."""
try:
labcontroller = LabController.by_name(fqdn)
except NoResultFound:
raise NotFound404('Lab controller %s does not exist' % fqdn)
return labcontroller