本文整理汇总了Python中bkr.server.model.Recipe.by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Recipe.by_id方法的具体用法?Python Recipe.by_id怎么用?Python Recipe.by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bkr.server.model.Recipe
的用法示例。
在下文中一共展示了Recipe.by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: provision_virt_recipe
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def provision_virt_recipe(recipe_id):
log.debug('Attempting to provision dynamic virt guest for recipe %s', recipe_id)
session.begin()
try:
recipe = Recipe.by_id(recipe_id)
manager = dynamic_virt.VirtManager(recipe.recipeset.job.owner)
available_flavors = manager.available_flavors()
# We want them in order of smallest to largest, so that we can pick the
# smallest flavor that satisfies the recipe's requirements. Sorting by RAM
# is a decent approximation.
possible_flavors = XmlHost.from_string(recipe.host_requires)\
.filter_openstack_flavors(available_flavors, manager.lab_controller)
if not possible_flavors:
log.debug('No OpenStack flavors matched recipe %s, marking precluded',
recipe.id)
recipe.virt_status = RecipeVirtStatus.precluded
return
possible_flavors = sorted(possible_flavors, key=lambda flavor: flavor.ram)
flavor = possible_flavors[0]
vm_name = '%srecipe-%s' % (
ConfigItem.by_name(u'guest_name_prefix').current_value(u'beaker-'),
recipe.id)
# FIXME can we control use of virtio?
#virtio_possible = True
#if self.recipe.distro_tree.distro.osversion.osmajor.osmajor == "RedHatEnterpriseLinux3":
# virtio_possible = False
vm = manager.create_vm(vm_name, flavor)
vm.instance_created = datetime.utcnow()
try:
recipe.createRepo()
recipe.clear_candidate_systems()
recipe.watchdog = Watchdog()
recipe.resource = vm
recipe.recipeset.lab_controller = manager.lab_controller
recipe.virt_status = RecipeVirtStatus.succeeded
recipe.schedule()
log.info("recipe ID %s moved from Queued to Scheduled by provision_virt_recipe" % recipe.id)
recipe.waiting()
recipe.provision()
log.info("recipe ID %s moved from Scheduled to Waiting by provision_virt_recipe" % recipe.id)
except:
exc_type, exc_value, exc_tb = sys.exc_info()
try:
manager.destroy_vm(vm)
except Exception:
log.exception('Failed to clean up vm %s '
'during provision_virt_recipe, leaked!', vm.instance_id)
# suppress this exception so the original one is not masked
raise exc_type, exc_value, exc_tb
session.commit()
except Exception, e:
log.exception('Error in provision_virt_recipe(%s)', recipe_id)
session.rollback()
# As an added precaution, let's try and avoid this recipe in future
with session.begin():
recipe = Recipe.by_id(recipe_id)
recipe.virt_status = RecipeVirtStatus.failed
示例2: provision_virt_recipes
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def provision_virt_recipes(*args):
# We limit to labs where the tree is available by NFS because RHEV needs to
# use autofs to grab the images. See VirtManager.start_install.
recipes = MachineRecipe.query\
.join(Recipe.recipeset).join(RecipeSet.job)\
.filter(Job.dirty_version == Job.clean_version)\
.join(Recipe.distro_tree, DistroTree.lab_controller_assocs, LabController)\
.filter(Recipe.status == TaskStatus.queued)\
.filter(Recipe.virt_status == RecipeVirtStatus.possible)\
.filter(LabController.disabled == False)\
.filter(or_(RecipeSet.lab_controller == None,
RecipeSet.lab_controller_id == LabController.id))\
.filter(LabControllerDistroTree.url.like(u'nfs://%'))\
.order_by(RecipeSet.priority.desc(), Recipe.id.asc())
if not recipes.count():
return False
log.debug("Entering provision_virt_recipes")
for recipe_id, in recipes.values(Recipe.id.distinct()):
system_name = None
session.begin()
try:
system_name = u'%srecipe_%s' % (
ConfigItem.by_name(u'guest_name_prefix').current_value(u'beaker_'),
recipe_id)
provision_virt_recipe(system_name, recipe_id)
session.commit()
except needpropertyxml.NotVirtualisable:
session.rollback()
session.begin()
recipe = Recipe.by_id(recipe_id)
recipe.virt_status = RecipeVirtStatus.precluded
session.commit()
except VMCreationFailedException:
session.rollback()
session.begin()
recipe = Recipe.by_id(recipe_id)
recipe.virt_status = RecipeVirtStatus.skipped
session.commit()
except Exception, e: # This will get ovirt RequestErrors from recipe.provision()
log.exception('Error in provision_virt_recipe(%s)', recipe_id)
session.rollback()
try:
# Don't leak the vm if it was created
if system_name:
with dynamic_virt.VirtManager() as manager:
manager.destroy_vm(system_name)
# As an added precaution, let's try and avoid this recipe in future
session.begin()
recipe = Recipe.by_id(recipe_id)
recipe.virt_status = RecipeVirtStatus.failed
session.commit()
except Exception:
log.exception('Exception in exception handler :-(')
finally:
示例3: provision_virt_recipe
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def provision_virt_recipe(system_name, recipe_id):
recipe = Recipe.by_id(recipe_id)
recipe.createRepo()
# Figure out the "data centers" where we can run the recipe
if recipe.recipeset.lab_controller:
# First recipe of a recipeSet determines the lab_controller
lab_controllers = [recipe.recipeset.lab_controller]
else:
# NB the same criteria are also expressed above
lab_controllers = LabController.query.filter_by(disabled=False, removed=None)
lab_controllers = needpropertyxml.apply_lab_controller_filter(
recipe.host_requires, lab_controllers)
lab_controllers = [lc for lc in lab_controllers.all()
if recipe.distro_tree.url_in_lab(lc, 'nfs')]
recipe.systems = []
recipe.watchdog = Watchdog()
recipe.resource = VirtResource(system_name=system_name)
with dynamic_virt.VirtManager() as manager:
recipe.resource.allocate(manager, lab_controllers)
recipe.recipeset.lab_controller = recipe.resource.lab_controller
recipe.schedule()
log.info("recipe ID %s moved from Queued to Scheduled by provision_virt_recipe" % recipe.id)
recipe.waiting()
recipe.provision()
log.info("recipe ID %s moved from Scheduled to Waiting by provision_virt_recipe" % recipe.id)
示例4: run
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def run(self):
session.begin()
recipe = Recipe.by_id(self.recipe_id)
self.ready_evt.set()
self.continue_evt.wait()
recipe.tasks[-1].stop()
session.commit()
示例5: tearDown
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def tearDown(self):
admin_user = User.by_user_name(data_setup.ADMIN_USER)
if getattr(self,'recipe_id', None):
with session.begin():
recipe = Recipe.by_id(self.recipe_id)
if recipe.resource.system.open_reservation:
recipe.resource.release()
示例6: install_start
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def install_start(self, recipe_id=None):
"""
Report comencement of provisioning of a recipe's resource, extend
first task's watchdog, and report 'Install Started' against it.
"""
try:
recipe = Recipe.by_id(recipe_id)
except InvalidRequestError:
raise BX(_("Invalid Recipe ID %s" % recipe_id))
first_task = recipe.first_task
if not recipe.resource.install_started:
recipe.resource.install_started = datetime.utcnow()
# extend watchdog by 3 hours 60 * 60 * 3
kill_time = 10800
# XXX In future releases where 'Provisioning'
# is a valid recipe state, we will no longer
# need the following block.
log.debug('Extending watchdog for %s', first_task.t_id)
first_task.extend(kill_time)
log.debug('Recording /start for %s', first_task.t_id)
first_task.pass_(path=u'/start', score=0, summary=u'Install Started')
return True
else:
log.debug('Already recorded /start for %s', first_task.t_id)
return False
示例7: install_done
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def install_done(self, recipe_id=None, fqdn=None):
"""
Report completion of installation with current FQDN
"""
if not recipe_id:
raise BX(_("No recipe id provided!"))
if not fqdn:
raise BX(_("No fqdn provided!"))
try:
recipe = Recipe.by_id(recipe_id)
except InvalidRequestError:
raise BX(_("Invalid Recipe ID %s" % recipe_id))
recipe.resource.install_finished = datetime.utcnow()
# We don't want to change an existing FQDN, just set it
# if it hasn't been set already (see BZ#879146)
configured = recipe.resource.fqdn
if configured is None:
recipe.resource.fqdn = configured = fqdn
elif configured != fqdn:
# We use eager formatting here to make this easier to test
log.info("Configured FQDN (%s) != reported FQDN (%s) in R:%s" %
(configured, fqdn, recipe_id))
return configured
示例8: files
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def files(self, recipe_id):
"""
Return an array of logs for the given recipe.
:param recipe_id: id of recipe
:type recipe_id: integer
.. deprecated:: 0.9.4
Use :meth:`taskactions.files() <bkr.server.task_actions.taskactions.files>` instead.
"""
try:
recipe = Recipe.by_id(recipe_id)
except InvalidRequestError:
raise BX(_('Invalid recipe ID: %s' % recipe_id))
# Build a list of logs excluding duplicate paths, to mitigate:
# https://bugzilla.redhat.com/show_bug.cgi?id=963492
logdicts = []
seen_paths = set()
for log in recipe.all_logs():
logdict = log.dict
# The path we care about here is the path which beaker-transfer
# will move the file to.
# Don't be tempted to use os.path.join() here since log['path']
# is often '/' which does not give the result you would expect.
path = os.path.normpath('%s/%s/%s' % (logdict['filepath'],
logdict['path'], logdict['filename']))
if path in seen_paths:
logger.warn('%s contains duplicate log %s', log.parent.t_id, path)
else:
seen_paths.add(path)
logdicts.append(logdict)
return logdicts
示例9: really_return_reservation
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def really_return_reservation(self, id, msg=None):
try:
recipe = Recipe.by_id(id)
except InvalidRequestError:
raise BX(_("Invalid Recipe ID %s" % id))
recipe.return_reservation()
flash(_(u"Successfully released reserved system for %s" % recipe.t_id))
redirect('/jobs/mine')
示例10: extend
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def extend(self, recipe_id, kill_time):
"""
Extend recipe watchdog by kill_time seconds
"""
try:
recipe = Recipe.by_id(recipe_id)
except InvalidRequestError:
raise BX(_('Invalid recipe ID: %s' % recipe_id))
return recipe.extend(kill_time)
示例11: postinstall_done
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def postinstall_done(self, recipe_id=None):
"""
Report completion of postinstallation
"""
try:
recipe = Recipe.by_id(recipe_id)
except InvalidRequestError:
raise BX(_(u'Invalid Recipe ID %s' % recipe_id))
recipe.resource.postinstall_finished = datetime.utcnow()
return True
示例12: console_output
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def console_output(self, recipe_id, output_length=None, offset=None):
"""
Get text console log output from OpenStack
"""
try:
recipe = Recipe.by_id(recipe_id)
except InvalidRequestError:
raise BX(_('Invalid recipe ID: %s' % recipe_id))
manager = dynamic_virt.VirtManager(recipe.recipeset.job.owner)
return manager.get_console_output(recipe.resource.instance_id, output_length)
示例13: test_rendered_kickstart_is_deleted
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def test_rendered_kickstart_is_deleted(self):
with session.begin():
self.job_to_delete.to_delete = datetime.datetime.utcnow()
recipe = self.job_to_delete.recipesets[0].recipes[0]
ks = RenderedKickstart(kickstart=u'This is not a real kickstart.')
recipe.rendered_kickstart = ks
log_delete.log_delete()
with session.begin():
self.assertEqual(Recipe.by_id(recipe.id).rendered_kickstart, None)
self.assertRaises(NoResultFound, RenderedKickstart.by_id, ks.id)
示例14: to_xml
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def to_xml(self, recipe_id=None):
"""
Pass in recipe id and you'll get that recipe's xml
"""
if not recipe_id:
raise BX(_("No recipe id provided!"))
try:
recipexml = Recipe.by_id(recipe_id).to_xml().toprettyxml()
except InvalidRequestError:
raise BX(_("Invalid Recipe ID %s" % recipe_id))
return recipexml
示例15: systems
# 需要导入模块: from bkr.server.model import Recipe [as 别名]
# 或者: from bkr.server.model.Recipe import by_id [as 别名]
def systems(self, recipe_id=None, *args, **kw):
try:
recipe = Recipe.by_id(recipe_id)
except NoResultFound:
flash(_(u"Invalid recipe id %s" % recipe_id))
redirect(url("/recipes"))
PDC = widgets.PaginateDataGrid.Column
fields = [PDC(name='fqdn', getter=lambda x: x.link, title='Name'),
PDC(name='user', getter=lambda x: x.user.email_link if x.user else None, title='User'),]
grid = myPaginateDataGrid(fields=fields)
return dict(title='Recipe Systems', grid=grid, list=recipe.systems,
search_bar=None)