本文整理汇总了Python中ussclicore.utils.generics_utils.query_yes_no函数的典型用法代码示例。如果您正苦于以下问题:Python query_yes_no函数的具体用法?Python query_yes_no怎么用?Python query_yes_no使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了query_yes_no函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: do_delete
def do_delete(self, args):
try:
#add arguments
doParser = self.arg_delete()
doArgs = doParser.parse_args(shlex.split(args))
#if the help command is called, parse_args returns None object
if not doArgs:
return 2
#call UForge API
printer.out("Searching bundle with id ["+doArgs.id+"] ...")
myBundle = self.api.Users(self.login).Mysoftware(doArgs.id).Get()
if myBundle is None or type(myBundle) is not MySoftware:
printer.out("Bundle not found", printer.WARNING)
else:
table = Texttable(800)
table.set_cols_dtype(["t","t","t", "t","t", "t"])
table.header(["Id", "Name", "Version", "Description", "Size", "Imported"])
table.add_row([myBundle.dbId, myBundle.name, myBundle.version, myBundle.description, size(myBundle.size), "X" if myBundle.imported else ""])
print table.draw() + "\n"
if generics_utils.query_yes_no("Do you really want to delete bundle with id "+str(myBundle.dbId)):
self.api.Users(self.login).Mysoftware(myBundle.dbId).Delete()
printer.out("Bundle deleted", printer.OK)
except ArgumentParserError as e:
printer.out("ERROR: In Arguments: "+str(e), printer.ERROR)
self.help_delete()
except Exception as e:
return handle_uforge_exception(e)
开发者ID:lqueiroga,项目名称:hammr,代码行数:31,代码来源:bundle.py
示例2: do_delete
def do_delete(self, args):
try:
#add arguments
doParser = self.arg_delete()
try:
doArgs = doParser.parse_args(args.split())
except SystemExit as e:
return
#call UForge API
printer.out("Searching template with id ["+doArgs.id+"] ...")
myAppliance = self.api.Users(self.login).Appliances(doArgs.id).Get()
if myAppliance is None or type(myAppliance) is not Appliance:
printer.out("Template not found")
else:
table = Texttable(800)
table.set_cols_dtype(["t","t","t","t","t","t","t","t","t","t"])
table.header(["Id", "Name", "Version", "OS", "Created", "Last modified", "# Imgs", "Updates", "Imp", "Shared"])
table.add_row([myAppliance.dbId, myAppliance.name, str(myAppliance.version), myAppliance.distributionName+" "+myAppliance.archName,
myAppliance.created.strftime("%Y-%m-%d %H:%M:%S"), myAppliance.lastModified.strftime("%Y-%m-%d %H:%M:%S"), len(myAppliance.imageUris.uri),myAppliance.nbUpdates, "X" if myAppliance.imported else "", "X" if myAppliance.shared else ""])
print table.draw() + "\n"
if doArgs.no_confirm:
self.api.Users(self.login).Appliances(myAppliance.dbId).Delete()
printer.out("Template deleted", printer.OK)
elif generics_utils.query_yes_no("Do you really want to delete template with id "+str(myAppliance.dbId)):
self.api.Users(self.login).Appliances(myAppliance.dbId).Delete()
printer.out("Template deleted", printer.OK)
return 0
except ArgumentParserError as e:
printer.out("ERROR: In Arguments: "+str(e), printer.ERROR)
self.help_delete()
except Exception as e:
return handle_uforge_exception(e)
开发者ID:ShigeruIchihashi,项目名称:hammr,代码行数:33,代码来源:template.py
示例3: do_delete
def do_delete(self, args):
try:
# add arguments
doParser = self.arg_delete()
doArgs = doParser.parse_args(shlex.split(args))
#if the help command is called, parse_args returns None object
if not doArgs:
return 2
# call UForge API
printer.out("Searching account with id [" + doArgs.id + "] ...")
account = self.api.Users(self.login).Accounts(doArgs.id).Get()
if account is None:
printer.out("No Account available", printer.WARNING)
else:
table = Texttable(800)
table.set_cols_dtype(["t", "t", "t", "t"])
table.header(["Id", "Name", "Type", "Created"])
table.add_row(
[account.dbId, account.name, account.targetPlatform.name, account.created.strftime("%Y-%m-%d %H:%M:%S")])
print table.draw() + "\n"
if doArgs.no_confirm:
self.api.Users(self.login).Accounts(doArgs.id).Delete()
printer.out("Account deleted", printer.OK)
elif generics_utils.query_yes_no("Do you really want to delete account with id " + str(account.dbId)):
self.api.Users(self.login).Accounts(doArgs.id).Delete()
printer.out("Account deleted", printer.OK)
return 0
except ArgumentParserError as e:
printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
self.help_delete()
except Exception as e:
return handle_uforge_exception(e)
开发者ID:jgweir,项目名称:hammr,代码行数:35,代码来源:account.py
示例4: do_delete
def do_delete(self, args):
try:
doParser = self.arg_delete()
doArgs = doParser.parse_args(shlex.split(args))
if not doArgs:
return 2
# call UForge API
printer.out("Retrieving migration with id [" + doArgs.id + "]...")
migration = self.api.Users(self.login).Migrations(doArgs.id).Get()
if migration is None:
printer.out("No migration available with id " + doArgs.id)
return 2
print migration_utils.migration_table([migration]).draw() + "\n"
if doArgs.no_confirm or generics_utils.query_yes_no(
"Do you really want to delete migration with id " + doArgs.id + "?"):
printer.out("Please wait...")
self.api.Users(self.login).Migrations(doArgs.id).Delete()
printer.out("Migration deleted", printer.OK)
except ArgumentParserError as e:
printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
self.help_delete()
except Exception as e:
return hammr_utils.handle_uforge_exception(e)
开发者ID:lqueiroga,项目名称:hammr,代码行数:30,代码来源:migration.py
示例5: do_cancel
def do_cancel(self, args):
try:
# add arguments
doParser = self.arg_cancel()
try:
doArgs = doParser.parse_args(shlex.split(args))
except SystemExit as e:
return
# call UForge API
printer.out("Searching image with id [" + doArgs.id + "] ...")
images = self.api.Users(self.login).Images.Getall()
images = images.images.image
if images is None or len(images) == 0:
printer.out("No images available")
else:
table = Texttable(800)
table.set_cols_dtype(["t", "t", "t", "t", "t", "t", "t", "c", "t"])
table.header(["Id", "Name", "Version", "Rev.", "Format", "Created", "Size", "Compressed", "Status"])
cancelImage = None
for image in images:
if str(image.dbId) == str(doArgs.id):
imgStatus = self.get_image_status(image.status)
table.add_row([image.dbId, image.name, image.version, image.revision, image.targetFormat.name,
image.created.strftime("%Y-%m-%d %H:%M:%S"), size(image.size),
"X" if image.compress else "", imgStatus])
print table.draw() + "\n"
cancelImage = image
if cancelImage is None or cancelImage.status.complete or cancelImage.status.cancelled:
printer.out("Image not being generated, impossible to canceled", printer.ERROR)
return
if cancelImage is not None:
if generics_utils.query_yes_no(
"Do you really want to cancel image with id " + str(cancelImage.dbId)):
self.api.Users(self.login).Appliances(
generics_utils.extract_id(cancelImage.applianceUri)).Images(
cancelImage.dbId).Status.Cancel()
printer.out("Image Canceled", printer.OK)
else:
printer.out("Image not found", printer.ERROR)
except ArgumentParserError as e:
printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
self.help_delete()
except Exception as e:
return handle_uforge_exception(e)
开发者ID:MaxTakahashi,项目名称:hammr,代码行数:47,代码来源:image.py
示例6: do_terminate
def do_terminate(self, args):
try:
# add arguments
doParser = self.arg_terminate()
doArgs = doParser.parse_args(shlex.split(args))
deployment = self.api.Users(self.login).Deployments(doArgs.id).Get()
if doArgs.force or generics_utils.query_yes_no("Do you really want to terminate deployment with id '" + str(
doArgs.id) + "' named '" + deployment.name + "'"):
# When terminating a running deployment, we stop if the status goes to on-fire.
# But when terminating an on-fire deployment we stop if it is terminated.
# So we need to get the status before invoking the terminate.
status = self.api.Users(self.login).Deployments(doArgs.id).Status.Getdeploystatus()
initial_status = status.message
self.api.Users(self.login).Deployments(doArgs.id).Terminate()
printer.out("Terminating the deployment")
bar = ProgressBar(widgets=[BouncingBar()], maxval=UnknownLength)
bar.start()
i = 1
while (True):
deployment = self.get_deployment(doArgs.id)
if deployment is None:
break;
if initial_status != "on-fire":
if deployment.state == "on-fire":
# If the deployment went from running to on-fire, we stop and print an error message
break
time.sleep(1)
bar.update(i)
i += 2
bar.finish()
if deployment:
printer.out("Could not terminate the deployment.", printer.ERROR)
status = self.api.Users(self.login).Deployments(doArgs.id).Status.Getdeploystatus()
if status.message == "on-fire" and status.detailedError:
printer.out(status.detailedErrorMsg, printer.ERROR)
return 1
else:
printer.out("Deployment terminated", printer.OK)
return 0
except ArgumentParserError as e:
printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
self.help_terminate()
except Exception as e:
return handle_uforge_exception(e)
开发者ID:lqueiroga,项目名称:hammr,代码行数:47,代码来源:deploy.py
示例7: do_cancel
def do_cancel(self, args):
try:
# add arguments
do_parser = self.arg_cancel()
try:
do_args = do_parser.parse_args(shlex.split(args))
except SystemExit as e:
return 2
# call UForge API
printer.out("Searching image with id [" + do_args.id + "] ...", printer.INFO)
images = self.get_all_images()
if len(images) == 0 :
raise ValueError("No image found")
table = self.initialize_text_table(800)
table.set_cols_dtype(["t", "t", "t", "t", "t", "t", "t", "t", "t"])
table.header(["Id", "Name", "Version", "Rev.", "Format", "Created", "Size", "Compressed", "Status"])
cancel_image = None
for image in images:
if str(image.dbId) == str(do_args.id):
img_status = self.get_image_status(image.status)
table.add_row([image.dbId, image.name, image.version, image.revision, image.targetFormat.name,
image.created.strftime("%Y-%m-%d %H:%M:%S"), size(image.size),
"X" if image.compress else "", img_status])
print table.draw() + "\n"
cancel_image = image
if cancel_image is None or cancel_image.status.complete or cancel_image.status.cancelled:
raise ValueError("Image not being generated, impossible to canceled")
if cancel_image is not None:
if generics_utils.query_yes_no(
"Do you really want to cancel image with id " + str(cancel_image.dbId)):
self.cancel_image(cancel_image)
else:
printer.out("Image not found", printer.ERROR)
except ArgumentParserError as e:
printer.out("In Arguments: " + str(e), printer.ERROR)
self.help_delete()
return 2
except ValueError as e:
printer.out(str(e), printer.ERROR)
return 2
except Exception as e:
return handle_uforge_exception(e)
开发者ID:jgweir,项目名称:hammr,代码行数:46,代码来源:image.py
示例8: publish_image_from_builder
def publish_image_from_builder(image_object, builder, template, source, counter, image):
try:
if image is None:
image = get_image_to_publish(image_object, builder, template, source, counter)
publish_image = image_object.retrieve_publish_image_with_target_format_builder(image, builder)
publish_image.imageUri = image.uri
publish_image.parentUri = source.uri
publish_image.credAccount = get_account_to_publish(image_object, builder)
account_name = publish_image.credAccount.name
published_image = call_publish_webservice(image_object, image, source, publish_image)
print_publish_status(image_object, source, image, published_image, builder, account_name)
return 0
except KeyboardInterrupt:
printer.out("\n")
if generics_utils.query_yes_no("Do you want to cancel the job ?"):
cancel_publish_in_progress(image_object, source, image, published_image)
else:
printer.out("Exiting command")
raise KeyboardInterrupt
开发者ID:jgweir,项目名称:hammr,代码行数:22,代码来源:publish_utils.py
示例9: publish_builder
def publish_builder(self, builder, template, appliance, rInstallProfile, i, comliantImage):
try:
if comliantImage is None:
printer.out("Publishing '"+builder["type"]+"' image ("+str(i)+"/"+str(len(template["builders"]))+")")
images = self.api.Users(self.login).Appliances(appliance.dbId).Images.Getall(Query="targetFormat.name=='"+builder["type"]+"'")
images = images.images.image
if images is None or len(images) == 0:
printer.out("No images found for the template '"+template["stack"]["name"]+"' with type: "+builder["type"], printer.ERROR)
return 2
compliantImages = []
for image in images:
isOk = self.is_image_ready_to_publish(image, builder)
if isOk:
compliantImages.append(image)
if(len(compliantImages)==0):
printer.out("No images found for the template '"+template["stack"]["name"]+"' with type: "+builder["type"], printer.ERROR)
return 2
elif(len(compliantImages)==1):
comliantImage=compliantImages[0]
else:
#TODO get the last created image
comliantImage=compliantImages[0]
else: #publishing image in param --id
printer.out("Publishing '"+builder["type"]+"' image ("+str(i)+"/"+str(1)+")")
mypImage = publishImage()
mypImage.imageUri = comliantImage.uri
mypImage.applianceUri = appliance.uri
if not "account" in builder:
printer.out("Missing account section on builder: ["+builder["type"]+"]", printer.ERROR)
return 2
#Get all cloud account on the plateform (for the user)
accounts = self.api.Users(self.login).Accounts.Getall()
accounts = accounts.credAccounts.credAccount
if accounts is None or len(accounts) == 0:
printer.out("No accounts available on the plateform", printer.ERROR)
return 2
else:
for account in accounts:
if account.name == builder["account"]["name"]:
#TODO refactor this
account.uri=None
account.parentUri=None
account.dbId=None
account.created=None
account.lastModified=None
account.digest=None
mypImage.credAccount = account
break
if mypImage.credAccount is None:
printer.out("No accounts available with name " +builder["account"]["name"], printer.ERROR)
return 2
format_type = comliantImage.targetFormat.format.name
func = getattr(publish_utils, "publish_"+generics_utils.remove_special_chars(format_type), None)
if func:
mypImage = func(mypImage, builder)
else:
printer.out("Builder type unknown: "+format_type, printer.ERROR)
return 2
if mypImage is None:
return 2
rpImage = self.api.Users(self.login).Appliances(appliance.dbId).Images(comliantImage.dbId).Pimages().Publish(mypImage)
status = rpImage.status
statusWidget = progressbar_widget.Status()
statusWidget.status = status
widgets = [Bar('>'), ' ', statusWidget, ' ', ReverseBar('<')]
progress = ProgressBar(widgets=widgets, maxval=100).start()
while not (status.complete or status.error or status.cancelled):
statusWidget.status = status
progress.update(status.percentage)
status = self.api.Users(self.login).Appliances(appliance.dbId).Images(comliantImage.dbId).Pimages(rpImage.dbId).Status.Get()
time.sleep(2)
statusWidget.status = status
progress.finish()
if status.error:
printer.out("Publication to '"+builder["account"]["name"]+"' error: "+status.message+"\n"+status.errorMessage, printer.ERROR)
if status.detailedError:
printer.out(status.detailedErrorMsg)
elif status.cancelled:
printer.out("\nPublication to '"+builder["account"]["name"]+"' canceled: "+status.message. printer.WARNING)
else:
printer.out("Publication to '"+builder["account"]["name"]+"' is ok", printer.OK)
rpImage = self.api.Users(self.login).Appliances(appliance.dbId).Images(comliantImage.dbId).Pimages(rpImage.dbId).Get()
if rpImage.cloudId is not None and rpImage.cloudId!="":
printer.out("Cloud ID : "+rpImage.cloudId)
return 0
except KeyboardInterrupt:
printer.out("\n")
if generics_utils.query_yes_no("Do you want to cancel the job ?"):
if 'appliance' in locals() and 'comliantImage' in locals() and 'rpImage' in locals() \
#.........这里部分代码省略.........
开发者ID:hidakanoko,项目名称:hammr,代码行数:101,代码来源:image.py
示例10: publish_builder
def publish_builder(self, builder, template, appliance, rInstallProfile, i, comliantImage):
try:
if comliantImage is None:
comliantImage = self.get_image_to_publish(builder, template, appliance, i)
# get target format to define publish method
format_type = comliantImage.targetFormat.format.name
publishMethod = getattr(publish_utils, "publish_" + generics_utils.remove_special_chars(format_type), None)
if publishMethod:
mypImage = publishMethod(builder)
if mypImage is None:
return 2
else:
printer.out("Builder type unknown: " + format_type, printer.ERROR)
return 2
mypImage.imageUri = comliantImage.uri
mypImage.applianceUri = appliance.uri
mypImage.credAccount = self.get_account_to_publish(builder)
account_name = mypImage.credAccount.name
rpImage = self.api.Users(self.login).Appliances(appliance.dbId).Images(
comliantImage.dbId).Pimages().Publish(body=mypImage, element_name="ns1:publishImage")
status = rpImage.status
statusWidget = progressbar_widget.Status()
statusWidget.status = status
widgets = [Bar('>'), ' ', statusWidget, ' ', ReverseBar('<')]
progress = ProgressBar(widgets=widgets, maxval=100).start()
while not (status.complete or status.error or status.cancelled):
statusWidget.status = status
progress.update(status.percentage)
status = self.api.Users(self.login).Appliances(appliance.dbId).Images(comliantImage.dbId).Pimages(
rpImage.dbId).Status.Get()
time.sleep(2)
statusWidget.status = status
progress.finish()
if status.error:
printer.out("Publication to '" + builder["account"][
"name"] + "' error: " + status.message + "\n" + status.errorMessage, printer.ERROR)
if status.detailedError:
printer.out(status.detailedErrorMsg)
elif status.cancelled:
printer.out("\nPublication to '" + builder["account"][
"name"] + "' canceled: " + status.message.printer.WARNING)
else:
printer.out("Publication to " + account_name + " is ok", printer.OK)
rpImage = self.api.Users(self.login).Appliances(appliance.dbId).Images(comliantImage.dbId).Pimages(
rpImage.dbId).Get()
if rpImage.cloudId is not None and rpImage.cloudId != "":
printer.out("Cloud ID : " + rpImage.cloudId)
return 0
except KeyboardInterrupt:
printer.out("\n")
if generics_utils.query_yes_no("Do you want to cancel the job ?"):
if 'appliance' in locals() and 'comliantImage' in locals() and 'rpImage' in locals() \
and hasattr(appliance, 'dbId') and hasattr(comliantImage, 'dbId') and hasattr(rpImage, 'dbId'):
self.api.Users(self.login).Appliances(appliance.dbId).Images(comliantImage.dbId).Pimages(
rpImage.dbId).Cancel.Cancel()
else:
printer.out("Impossible to cancel", printer.WARNING)
else:
printer.out("Exiting command")
raise KeyboardInterrupt
开发者ID:cinlloc,项目名称:hammr,代码行数:64,代码来源:image.py
示例11: do_build
#.........这里部分代码省略.........
progress.update(status.percentage)
status = (
self.api.Users(self.login).Appliances(myAppliance.dbId).Images(rImage.dbId).Status.Get()
)
time.sleep(2)
statusWidget.status = status
progress.finish()
if status.error:
printer.out(
"Generation '"
+ builder["type"]
+ "' error: "
+ status.message
+ "\n"
+ status.errorMessage,
printer.ERROR,
)
if status.detailedError:
printer.out(status.detailedErrorMsg)
if doArgs.junit is not None:
test.elapsed_sec = time.time() - start_time
test.add_error_info("Error", status.message + "\n" + status.errorMessage)
elif status.cancelled:
printer.out(
"Generation '" + builder["type"] + "' canceled: " + status.message, printer.WARNING
)
if doArgs.junit is not None:
test.elapsed_sec = time.time() - start_time
test.add_failure_info("Canceled", status.message)
else:
printer.out("Generation '" + builder["type"] + "' ok", printer.OK)
printer.out("Image URI: " + rImage.uri)
printer.out("Image Id : " + generics_utils.extract_id(rImage.uri))
if doArgs.junit is not None:
test.elapsed_sec = time.time() - start_time
# the downloadUri already contains downloadKey at the end
if rImage.downloadUri is not None:
test.stdout = self.api._url + "/" + rImage.downloadUri
i += 1
except Exception as e:
if is_uforge_exception(e):
print_uforge_exception(e)
if doArgs.junit is not None and "test_results" in locals() and len(test_results) > 0:
test = test_results[len(test_results) - 1]
test.elapsed_sec = time.time() - start_time
test.add_error_info("Error", get_uforge_exception(e))
else:
raise
if doArgs.junit is not None:
testName = myAppliance.distributionName + " " + myAppliance.archName
ts = TestSuite("Generation " + testName, test_results)
with open(doArgs.junit, "w") as f:
TestSuite.to_file(f, [ts], prettyprint=False)
return 0
except KeyError as e:
printer.out("unknown error in template file", printer.ERROR)
except ArgumentParserError as e:
printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
self.help_build()
except KeyboardInterrupt:
printer.out("\n")
if generics_utils.query_yes_no("Do you want to cancel the job ?"):
if (
"myAppliance" in locals()
and "rImage" in locals()
and hasattr(myAppliance, "dbId")
and hasattr(rImage, "dbId")
):
self.api.Users(self.login).Appliances(myAppliance.dbId).Images(rImage.dbId).Status.Cancel()
else:
printer.out("Impossible to cancel", printer.WARNING)
else:
printer.out("Exiting command")
except Exception as e:
print_uforge_exception(e)
if doArgs.junit is not None and "test_results" in locals() and len(test_results) > 0:
test = test_results[len(test_results) - 1]
if "start_time" in locals():
elapse = time.time() - start_time
else:
elapse = 0
test.elapsed_sec = elapse
test.add_error_info("Error", get_uforge_exception(e))
else:
return 2
finally:
if (
"doArgs" in locals()
and doArgs.junit is not None
and "test_results" in locals()
and len(test_results) > 0
):
if "myAppliance" in locals():
testName = myAppliance.distributionName + " " + myAppliance.archName
else:
testName = ""
ts = TestSuite("Generation " + testName, test_results)
with open(doArgs.junit, "w") as f:
TestSuite.to_file(f, [ts], prettyprint=False)
开发者ID:usharesoft,项目名称:hammr,代码行数:101,代码来源:template.py
示例12: do_delete
def do_delete(self, args):
try:
doParser = self.arg_delete()
try:
doArgs = doParser.parse_args(shlex.split(args))
except SystemExit as e:
return
# call UForge API
searchedScanType = 'scan'
extraInfo = "Retrieving scan with id [" + doArgs.id + "] ..."
if doArgs.scantype:
if doArgs.scantype != 'scan' and doArgs.scantype != 'instance' and doArgs.scantype != 'all':
printer.out(
"ERROR: scantype can only be 'scan', 'instance' or 'all' not: '" + doArgs.scantype + "'",
printer.ERROR)
return
searchedScanType = doArgs.scantype
if searchedScanType != 'instance' and doArgs.scansonly:
printer.out(
"ERROR: 'scansonly' can only be used with 'instance' scantype but not with '" + searchedScanType + "'",
printer.ERROR)
return
if searchedScanType == 'instance':
extraInfo = "Retrieving scan instance with id [" + doArgs.id + "] ..."
else:
if searchedScanType == 'all':
extraInfo = 'Retrieving all scan instances and associated scans'
printer.out(extraInfo)
myScannedInstances = self.api.Users(self.login).Scannedinstances.Getall(Includescans="true")
myScannedInstances = myScannedInstances.scannedInstances.scannedInstance
if myScannedInstances is None or len(myScannedInstances) == 0:
printer.out("Nothing found")
return
if searchedScanType == 'all':
print scan_utils.scan_table(myScannedInstances).draw() + "\n"
if generics_utils.query_yes_no("Do you really want to delete all scan instances"):
printer.out("Please wait...")
self.api.Users(self.login).Scannedinstances().Deleteall()
printer.out("All instances and scans deleted", printer.OK)
return
for myScannedInstance in myScannedInstances:
if searchedScanType == 'instance' and str(myScannedInstance.dbId) == doArgs.id:
print scan_utils.scan_table([myScannedInstance]).draw() + "\n"
if doArgs.scansonly:
extraInfo = "Do you really want to delete all scans in instance with id " + str(doArgs.id)
else:
extraInfo = "Do you really want to delete scan instance with id " + str(
doArgs.id) + " and all associated scans"
if generics_utils.query_yes_no(extraInfo):
printer.out("Please wait...")
if doArgs.scansonly:
self.api.Users(self.login).Scannedinstances(doArgs.id).Scans().Deleteall()
printer.out("Instance scans deleted", printer.OK)
else:
self.api.Users(self.login).Scannedinstances(doArgs.id).Delete()
printer.out("Instance deleted", printer.OK)
return
return
if searchedScanType == 'scan':
for scan in myScannedInstance.scans.scan:
if str(scan.dbId) == doArgs.id:
print scan_utils.scan_table([myScannedInstance], scan).draw() + "\n"
if generics_utils.query_yes_no(
"Do you really want to delete scan with id " + str(doArgs.id)):
printer.out("Please wait...")
self.api.Users(self.login).Scannedinstances(myScannedInstance.dbId).Scans(
doArgs.id).Delete()
printer.out("Scan deleted", printer.OK)
return
printer.out("Scan not found", printer.ERROR)
except ArgumentParserError as e:
printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
self.help_delete()
except Exception as e:
return handle_uforge_exception(e)
开发者ID:MaxTakahashi,项目名称:hammr,代码行数:75,代码来源:scan.py
示例13: do_import
def do_import(self, args):
try:
# add arguments
doParser = self.arg_import()
try:
doArgs = doParser.parse_args(shlex.split(args))
doArgs.name = " ".join(doArgs.name)
except SystemExit as e:
return
printer.out("Import scan id [" + doArgs.id + "] ...")
myScannedInstances = self.api.Users(self.login).Scannedinstances.Getall(Includescans="true")
if myScannedInstances is None or not hasattr(myScannedInstances, 'scannedInstances'):
printer.out("scan not found", printer.ERROR)
return
else:
myScan = None
for myScannedInstance in myScannedInstances.scannedInstances.scannedInstance:
for scan in myScannedInstance.scans.scan:
if str(scan.dbId) == doArgs.id:
myScan = scan
myRScannedInstance = myScannedInstance
break
if myScan is not None:
break
if myScan is not None and myScan.status.complete and not myScan.status.error and not myScan.status.cancelled:
myScanImport = scanImport()
myScanImport.importedObjectName = doArgs.name
myScanImport.importedObjectVersion = doArgs.version
myScanImport.orgUri = (self.api.Users(self.login).Orgs().Getall()).orgs.org[0].uri
rScanImport = self.api.Users(self.login).Scannedinstances(myRScannedInstance.dbId).Scans(
myScan.dbId).Imports().Import(myScanImport)
status = rScanImport.status
statusWidget = progressbar_widget.Status()
statusWidget.status = status
widgets = [Bar('>'), ' ', statusWidget, ' ', ReverseBar('<')]
progress = ProgressBar(widgets=widgets, maxval=100).start()
while not (status.complete or status.error or status.cancelled):
statusWidget.status = status
progress.update(status.percentage)
status = (self.api.Users(self.login).Scannedinstances(myRScannedInstance.dbId).Scans(
myScan.dbId).Imports().Status.Get(I=rScanImport.uri)).statuses.status[0]
time.sleep(2)
statusWidget.status = status
progress.finish()
if status.error:
printer.out("Importing error: " + status.message + "\n" + status.errorMessage, printer.ERROR)
if status.detailedError:
printer.out(status.detailedErrorMsg)
elif status.cancelled:
printer.out("Importing canceled: " + status.message, printer.WARNING)
else:
printer.out("Importing ok", printer.OK)
except KeyboardInterrupt:
printer.out("\n")
if generics_utils.query_yes_no("Do you want to cancel the job ?"):
if 'myRScannedInstance' in locals() and 'myScan' in locals() and 'rScanImport' in locals() \
and hasattr(myRScannedInstance, 'dbId') and hasattr(myScan, 'dbId') and hasattr(rScanImport,
'dbId'):
self.api.Users(self.login).Scannedinstances(myRScannedInstance.dbId).Scans(myScan.dbId).Imports(
rScanImport.dbId).Status.Cancel()
else:
printer.out("Exiting command")
except ArgumentParserError as e:
printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
self.help_import()
except Exception as e:
return handle_uforge_exception(e)
开发者ID:MaxTakahashi,项目名称:hammr,代码行数:70,代码来源:scan.py
示例14: do_build
#.........这里部分代码省略.........
builders = hammr_utils.check_mandatory_builders(data["builders"])
builders = hammr_utils.check_mandatory_generate_scan(builders)
else:
printer.out("no builder section found", printer.ERROR)
return
if builders is None:
return
try:
myScannedInstances = self.api.Users(self.login).Scannedinstances.Getall(Includescans="true")
if myScannedInstances is None or not hasattr(myScannedInstances, 'scannedInstances'):
printer.out("scan not found", printer.ERROR)
return
else:
myScan = None
for myScannedInstance in myScannedInstances.scannedInstances.scannedInstance:
for scan in myScannedInstance.scans.scan:
if str(scan.dbId) == doArgs.id:
myScan = scan
myRScannedInstance = myScannedInstance
break
if myScan is not None:
break
if myScan is not None and myScan.status.complete and not myScan.status.error and not myScan.status.cancelled:
i = 1
for builder in builders:
printer.out(
"Generating '" + builder["type"] + "' image (" + str(i) + "/" + str(len(builders)) + ")")
format_type = builder["type"]
targetFormat = generate_utils.get_target_format_object(self.api, self.login, format_type)
if targetFormat is None:
printer.out("Builder type unknown: "+format_type, printer.ERROR)
return 2
myimage = image()
myinstallProfile = installProfile()
if "swapSize" in builder["installation"]:
myinstallProfile.swapSize = builder["installation"]["swapSize"]
myinstallProfile.diskSize = builder["installation"]["diskSize"]
func = getattr(generate_utils, "generate_"+generics_utils.remove_special_chars(targetFormat.format.name), None)
if func:
myimage, myinstallProfile = func(myimage, builder, myinstallProfile, self.api, self.login)
else:
printer.out("Builder type unknown: "+format_type, printer.ERROR)
return 2
myimage.targetFormat = targetFormat
myimage.installProfile = myinstallProfile
rImage = self.api.Users(self.login).Scannedinstances(myRScannedInstance.dbId).Scans(
myScan.dbId).Images().Generate(myimage)
status = rImage.status
statusWidget = progressbar_widget.Status()
statusWidget.status = status
widgets = [Bar('>'), ' ', statusWidget, ' ', ReverseBar('<')]
progress = ProgressBar(widgets=widgets, maxval=100).start()
while not (status.complete or status.error or status.cancelled):
statusWidget.status = status
progress.update(status.percentage)
status = self.api.Users(self.login).Scannedinstances(myRScannedInstance.dbId).Scans(
myScan.dbId).Images(Sitid=rImage.dbId).Status.Get()
time.sleep(2)
statusWidget.status = status
progress.finish()
if status.error:
printer.out("Generation '" + builder[
"type"] + "' error: " + status.message + "\n" + status.errorMessage, printer.ERROR)
if status.detailedError:
printer.out(status.detailedErrorMsg)
elif status.cancelled:
printer.out("Generation '" + builder["type"] + "' canceled: " + status.message,
printer.ERROR)
else:
printer.out("Generation '" + builder["type"] + "' ok", printer.OK)
i += 1
else:
printer.out("Impossible to gener
|
请发表评论