def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) allRepo = self.api.Orgs(org.dbId).Repositories.Getall() if allRepo is None: printer.out("No repositories found in [" + org.name + "].") return 0 if doArgs.sort is not None: if doArgs.sort.lower() == "name": printer.out("Repository list ordered by [name] :") allRepo = order_list_object_by(allRepo.repositories.repository, "name") elif doArgs.sort.lower() == "id": printer.out("Repository list ordered by [id] :") allRepo = sorted(allRepo.repositories.repository, key=lambda x: getattr(x, "dbId"), reverse=False) elif doArgs.sort.lower() == "url": printer.out("Repository list ordered by [url] :") allRepo = order_list_object_by(allRepo.repositories.repository, "url") elif doArgs.sort.lower() == "type": printer.out("Repository list ordered by [type] :") allRepo = order_list_object_by(allRepo.repositories.repository, "packagingType") else: printer.out("Sorting parameter filled don't exist.", printer.WARNING) printer.out("Repository list :") allRepo = sorted(allRepo.repositories.repository, key=lambda x: getattr(x, "dbId"), reverse=False) else: printer.out("Repository list :") allRepo = sorted(allRepo.repositories.repository, key=lambda x: getattr(x, "dbId"), reverse=False) table = Texttable(200) table.set_cols_align(["c", "c", "l", "l", "c"]) table.set_cols_width([5,5,30,80,8]) table.header(["Id", "Off. Supported", "Name", "URL", "Type"]) for item in allRepo: if item.officiallySupported: officiallySupported = "X" else: officiallySupported = "" table.add_row([item.dbId, officiallySupported, item.name, item.url, item.packagingType]) print table.draw() + "\n" printer.out("Found " + str(len(allRepo)) + " repositories.") return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: # call UForge API # get images printer.out("Getting all images and publications for [" + self.login + "] ...", printer.INFO) images = self.get_all_images() if len(images) == 0 : printer.out("No image available", printer.INFO) else : printer.out("Images:") 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", "Generation Status"]) images = generics_utils.order_list_object_by(images, "name") for image in images: 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.fileSize), "X" if image.compress else "", imgStatus]) print table.draw() + "\n" printer.out("Found " + str(len(images)) + " images", printer.INFO) # get publications publish_images = self.api.Users(self.login).Pimages.Getall() publish_images = publish_images.publishImages.publishImage if publish_images is None or len(publish_images) == 0: printer.out("No publication available", printer.INFO) return 0 printer.out("Publications:") table = self.initialize_text_table(800) table.set_cols_dtype(["t", "t", "t", "t", "t", "t", "t"]) table.header(["Template name", "Image ID", "Publish ID", "Account name", "Format", "Cloud ID", "Status"]) publish_images = generics_utils.order_list_object_by(publish_images, "name") for publish_image in publish_images: pubStatus = get_publish_status(publish_image.status) table.add_row([publish_image.name, generics_utils.extract_id(publish_image.imageUri), publish_image.dbId, publish_image.credAccount.name if publish_image.credAccount is not None else "-", publish_image.credAccount.targetPlatform.name, publish_image.cloudId if publish_image.cloudId is not None else "-", pubStatus]) print table.draw() + "\n" printer.out("Found " + str(len(publish_images)) + " publications", printer.INFO) return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) printer.out("Getting category list for [" + org.name + "] . . .") allCategory = self.api.Orgs(org.dbId).Categories.Getall() allCategory = order_list_object_by(allCategory.categories.category, "name") if len(allCategory) is 0: printer.out("[" + org.name + "] has no categories.") return 0 table = Texttable(200) table.set_cols_align(["l", "l", "l"]) table.header(["Id", "Category", "type"]) for item in allCategory: table.add_row([item.dbId, item.name, item.type]) print table.draw() + "\n" printer.out("Found " + str(len(allCategory)) + " categories.") return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: #call UForge API printer.out("Getting generation formats for ["+self.login+"] ...") targetFormatsUser = self.api.Users(self.login).Targetformats.Getall() if targetFormatsUser is None or len(targetFormatsUser.targetFormats.targetFormat) == 0: printer.out("No generation formats available") return 0 else: targetFormatsUser = generics_utils.order_list_object_by(targetFormatsUser.targetFormats.targetFormat,"name") table = Texttable(200) table.set_cols_align(["l", "l", "l", "l", "c"]) table.header(["Builder Type", "Format", "Category", "Cloud Account Type", "Access"]) for item in targetFormatsUser: if item.access: access = "X" else: access = "" if item.credAccountType is None: credAccountType = "" else: credAccountType = item.credAccountType table.add_row( [item.name, item.format.name, item.category.name, credAccountType, access]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) printer.out("Getting entitlements list of the UForge :") entList = self.api.Entitlements.Getall() if entList is None: printer.out("No entitlements found.", printer.OK) else: entList = generics_utils.order_list_object_by( entList.entitlements.entitlement, "name") printer.out("Entitlement list for the UForge :") table = Texttable(200) table.set_cols_align(["l", "l"]) table.header(["Name", "Description"]) table.set_cols_width([30, 60]) for item in entList: table.add_row([item.name, item.description]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: #call UForge API printer.out("Getting all your bundles ...") bundles = self.api.Users(self.login).Mysoftware.Getall() bundles = bundles.mySoftwareList.mySoftware if bundles is None or len(bundles) == 0: printer.out("No bundles available") else: table = Texttable(800) table.set_cols_dtype(["t", "t", "t", "t", "t", "t", "t"]) table.header([ "Id", "Name", "Version", "Description", "Category", "Size", "Imported" ]) bundles = generics_utils.order_list_object_by(bundles, "name") for bundle in bundles: category = "" if bundle.category is not None: category = bundle.category.name table.add_row([ bundle.dbId, bundle.name, bundle.version, bundle.description, category, size(bundle.size), "X" if bundle.imported else "" ]) print table.draw() + "\n" printer.out("Found " + str(len(bundles)) + " bundles") return 0 except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) printer.out("Getting user list for ["+org.name+"] . . .") allUsers = self.api.Orgs(org.dbId).Members.Getall() allUsers = order_list_object_by(allUsers.users.user, "loginName") table = Texttable(200) table.set_cols_align(["l", "l", "c"]) table.header(["Login", "Email", "Active"]) for item in allUsers: if item.active: active = "X" else: active = "" table.add_row([item.loginName, item.email, active]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: # add arguments do_parser = self.arg_list() do_args = do_parser.parse_args(shlex.split(args)) # call UForge API printer.out("Getting vendors ...") org = org_utils.org_get(self.api, do_args.org) vendors = self.api.Orgs(org.dbId).Vendors().Getall() table = Texttable(200) table.set_cols_align(["c", "c", "c"]) table.header(["Active", "Name", "Email"]) sorted_vendor_list = generics_utils.order_list_object_by( vendors.vendors.vendor, "name") for vendor in sorted_vendor_list: table.add_row([ "" if vendor.inactive else "X", vendor.name, vendor.email ]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_list(self, args): try: printer.out("Getting target platform :") targetPlatformsUser = self.api.Users( self.login).Targetplatforms.Getall() if targetPlatformsUser is None or len( targetPlatformsUser.targetPlatforms.targetPlatform) == 0: printer.out("There is no target platform") return 0 else: targetPlatformsUser = generics_utils.order_list_object_by( targetPlatformsUser.targetPlatforms.targetPlatform, "name") printer.out("Target platform list:") table = Texttable(200) table.set_cols_align(["c", "c", "c", "c"]) table.header(["Id", "Name", "Type", "Access"]) for item in targetPlatformsUser: if item.access: access = "X" else: access = "" table.add_row([item.dbId, item.name, item.type, access]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_search(self, args): try: #add arguments doParser = self.arg_search() 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("Search package '"+doArgs.pkg+"' ...") distribution = self.api.Distributions(doArgs.id).Get() printer.out("for OS '"+distribution.name+"', version "+distribution.version) pkgs = self.api.Distributions(distribution.dbId).Pkgs.Getall(Query="name=="+doArgs.pkg) pkgs = pkgs.pkgs.pkg if pkgs is None or len(pkgs) == 0: printer.out("No package found") else: table = Texttable(800) table.set_cols_dtype(["t","t","t","t","t","t","t"]) table.header(["Name", "Version", "Arch", "Release", "Build date", "Size", "FullName"]) pkgs = generics_utils.order_list_object_by(pkgs, "name") for pkg in pkgs: table.add_row([pkg.name, pkg.version, pkg.arch, pkg.release, pkg.pkgBuildDate.strftime("%Y-%m-%d %H:%M:%S"), size(pkg.size), pkg.fullName]) print table.draw() + "\n" printer.out("Found "+str(len(pkgs))+" packages") except ArgumentParserError as e: printer.out("ERROR: In Arguments: "+str(e), printer.ERROR) self.help_search() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: # call UForge API printer.out("Getting all your accounts ...") 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") else: table = Texttable(800) table.set_cols_dtype(["t", "t", "t", "t"]) table.header(["Id", "Name", "Type", "Created"]) accounts = generics_utils.order_list_object_by( accounts, "name") for account in accounts: table.add_row([ account.dbId, account.name, account.targetPlatform.name, account.created.strftime("%Y-%m-%d %H:%M:%S") ]) print table.draw() + "\n" printer.out("Found " + str(len(accounts)) + " accounts") return 0 except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: #call UForge API printer.out("Getting generation formats for ["+self.login+"] ...") targetFormatsUser = self.api.Users(self.login).Targetformats.Getall() if targetFormatsUser is None or len(targetFormatsUser.targetFormats.targetFormat) == 0: printer.out("No generation formats available") return 0 else: targetFormatsUser = generics_utils.order_list_object_by(targetFormatsUser.targetFormats.targetFormat,"name") table = Texttable(200) table.set_cols_align(["l", "l", "l", "l", "l", "c"]) table.header(["Name", "Format", "Category", "Type", "CredAccountType", "Access"]) for item in targetFormatsUser: if item.access: access = "X" else: access = "" if item.credAccountType is None: credAccountType = "" else: credAccountType = item.credAccountType table.add_row( [item.name, item.format.name, item.category.name, item.type, credAccountType, access]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: #call UForge API printer.out("Getting templates for ["+self.login+"] ...") appliances = self.api.Users(self.login).Appliances().Getall() appliances = appliances.appliances if appliances is None or not hasattr(appliances, 'appliance'): printer.out("No template") else: images = self.api.Users(self.login).Images.Get() images = images.images 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"]) appliances = generics_utils.order_list_object_by(appliances.appliance, "name") for appliance in appliances: nbImage=0 if images is not None and hasattr(images, 'image'): for image in images.image: if hasattr(image, 'applianceUri') and image.applianceUri == appliance.uri: nbImage+=1 table.add_row([appliance.dbId, appliance.name, str(appliance.version), appliance.distributionName+" "+appliance.archName, appliance.created.strftime("%Y-%m-%d %H:%M:%S"), appliance.lastModified.strftime("%Y-%m-%d %H:%M:%S"), nbImage, appliance.nbUpdates, "X" if appliance.imported else "", "X" if appliance.shared else ""]) print table.draw() + "\n" printer.out("Found "+str(len(appliances))+" templates") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: "+str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: #call UForge API printer.out("Getting distributions for ["+self.login+"] ...") distributions = self.api.Users(self.login).Distros.Getall() distributions = distributions.distributions if distributions is None or not hasattr(distributions, "distribution"): printer.out("No distributions available") else: table = Texttable(800) table.set_cols_dtype(["t","t","t","t","t", "t"]) table.header(["Id", "Name", "Version", "Architecture", "Release Date", "Profiles"]) distributions = generics_utils.order_list_object_by(distributions.distribution, "name") for distribution in distributions: profiles = self.api.Distributions(distribution.dbId).Profiles.Getall() profiles = profiles.distribProfiles.distribProfile if len(profiles) > 0: profile_text="" for profile in profiles: profile_text+=profile.name+"\n" table.add_row([distribution.dbId, distribution.name, distribution.version, distribution.arch, distribution.releaseDate.strftime("%Y-%m-%d %H:%M:%S") if distribution.releaseDate is not None else "", profile_text]) else: table.add_row([distribution.dbId, distribution.name, distribution.version, distribution.arch, distribution.releaseDate.strftime("%Y-%m-%d %H:%M:%S") if distribution.releaseDate is not None else "", "-"]) print table.draw() + "\n" printer.out("Found "+str(len(distributions))+" distributions") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: "+str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: printer.out("Getting target platform :") targetPlatformsUser = self.api.Users(self.login).Targetplatforms.Getall() if targetPlatformsUser is None or len(targetPlatformsUser.targetPlatforms.targetPlatform) == 0: printer.out("There is no target platform") return 0 else: targetPlatformsUser = generics_utils.order_list_object_by( targetPlatformsUser.targetPlatforms.targetPlatform, "name") printer.out("Target platform list:") table = Texttable(200) table.set_cols_align(["c", "c", "c", "c"]) table.header(["Id", "Name", "Type", "Access"]) for item in targetPlatformsUser: if item.access: access = "X" else: access = "" table.add_row([item.dbId, item.name, item.type, access]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) printer.out("Getting user list for [" + org.name + "] . . .") allUsers = self.api.Orgs(org.dbId).Members.Getall() allUsers = order_list_object_by(allUsers.users.user, "loginName") table = Texttable(200) table.set_cols_align(["l", "l", "c"]) table.header(["Login", "Email", "Active"]) for item in allUsers: if item.active: active = "X" else: active = "" table.add_row([item.loginName, item.email, active]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) printer.out("Getting entitlements list of the UForge :") entList = self.api.Entitlements.Getall() if entList is None: printer.out("No entitlements found.", printer.OK) else: entList=generics_utils.order_list_object_by(entList.entitlements.entitlement, "name") printer.out("Entitlement list for the UForge :") table = Texttable(200) table.set_cols_align(["l", "l"]) table.header(["Name", "Description"]) table.set_cols_width([30,60]) for item in entList: table.add_row([item.name, item.description]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) printer.out("Getting category list for ["+org.name+"] . . .") allCategory = self.api.Orgs(org.dbId).Categories.Getall() allCategory = order_list_object_by(allCategory.categories.category, "name") if len(allCategory) is 0: printer.out("["+org.name+"] has no categories.") return 0 table = Texttable(200) table.set_cols_align(["l", "l", "l"]) table.header(["Id", "Category", "type"]) for item in allCategory: table.add_row([item.dbId, item.name, item.type]) print table.draw() + "\n" printer.out("Found " + str(len(allCategory)) + " categories.") return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) # call UForge API printer.out("Getting all the subscription profiles for organization ...") subscriptions = self.api.Orgs(org.dbId).Subscriptions().Getall(Search=None) subscriptions = generics_utils.order_list_object_by(subscriptions.subscriptionProfiles.subscriptionProfile, "name") if subscriptions is None or len(subscriptions) == 0: printer.out("There is no subscriptions in [" + org.name + "] ") return 0 printer.out("List of subscription profiles in [" + org.name + "] :") table = Texttable(200) table.set_cols_align(["c", "c", "c", "c"]) table.header(["Name", "Code", "Active", "description"]) for subscription in subscriptions: if subscription.active: active = "X" else: active = "" table.add_row([subscription.name, subscription.code, active, subscription.description]) print table.draw() + "\n" printer.out("Foumd " + str(len(subscriptions)) + " subscription profile(s).") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def scan_table(scanInstances, scan=None): table = Texttable(800) table.set_cols_dtype(["t", "t", "t", "t", "t"]) table.set_cols_align(["c", "l", "c", "c", "c"]) table.header(["Id", "Name", "Status", "Distribution", "With overlay"]) if scan: table.add_row([scan.dbId, "\t" + scan.name, scan_status(scan), "", ""]) return table for myScannedInstance in scanInstances: withOverlayStr = '' if myScannedInstance.overlayIncluded: withOverlayStr = 'X' table.add_row([ myScannedInstance.dbId, myScannedInstance.name, "", myScannedInstance.distribution.name + " " + myScannedInstance.distribution.version + " " + myScannedInstance.distribution.arch, withOverlayStr ]) scans = generics_utils.order_list_object_by( myScannedInstance.scans.scan, "name") for lscan in scans: table.add_row( [lscan.dbId, "\t" + lscan.name, scan_status(lscan), "", ""]) return table
def do_enable(self, args): try: doParser = self.arg_enable() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) if org is None: printer.out("There is no organization matching ["+doArgs.org+"].", printer.OK) return 0 targetPlatformsOrg = self.api.Orgs(org.dbId).Targetplatforms.Getall() if targetPlatformsOrg is None or len(targetPlatformsOrg.targetPlatforms.targetPlatform) == 0: printer.out("There is no target platform for the user \""+doArgs.account+"\" in [" + org.name + "].") return 0 else: targetPlatformsOrg = targetPlatformsOrg.targetPlatforms.targetPlatform targetPlatformsList = targetPlatforms() targetPlatformsList.targetPlatforms = pyxb.BIND() targetPlatformsOrg = compare(targetPlatformsOrg, doArgs.targetPlatforms, "name") if len(targetPlatformsOrg) == 0: listName = "" for tpname in doArgs.targetPlatforms: listName = listName + tpname + " " printer.out("There is no target platforms matching ["+listName+"].") return 0 for item in targetPlatformsOrg: targetPlatformToEnable = targetPlatform() targetPlatformToEnable = item targetPlatformToEnable.active = True targetPlatformToEnable.access = True printer.out("Enabling ["+item.name+"].") targetPlatformsList.targetPlatforms.append(targetPlatformToEnable) result = self.api.Users(doArgs.account).Targetplatforms.Update(Org=org.name,body=targetPlatformsList) result =generics_utils.order_list_object_by(result.targetPlatforms.targetPlatform, "name") table = Texttable(200) table.set_cols_align(["c", "c", "c", "c"]) table.header(["Id", "Name", "Type", "Access"]) for item in result: if item.access: access = "X" else: access = "" table.add_row([item.dbId, item.name, item.type, access]) printer.out("Target Platform list for user \""+doArgs.account+"\" :") print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_enable() except Exception as e: return handle_uforge_exception(e)
def do_images(self, args): try: doParser = self.arg_images() doArgs = doParser.parse_args(shlex.split(args)) printer.out("Getting images list...") allImages = self.api.Users(doArgs.account).Appliances(doArgs.id).Images.Getall() appliancesList = self.api.Users(doArgs.account).Appliances.Getall() appliancesList = appliancesList.appliances.appliance if allImages is None or len(allImages.images.image) == 0: printer.out("No images found for user [" + doArgs.account + "].") return 0 allImages = generics_utils.order_list_object_by(allImages.images.image, "name") if doArgs.name is not None: allImages = compare(allImages, doArgs.name, "name") if doArgs.format is not None: allImages = compare(allImages, doArgs.format, "format", "name") if doArgs.os is not None: allImages = compare(list=allImages, values=doArgs.os, attrName='distributionName', subattrName=None, otherList=appliancesList, linkProperties=['applianceUri', 'uri']) if allImages is None or len(allImages) == 0: printer.out("No images found for user [" + doArgs.account + "] with these filters.") return 0 printer.out("Images list :") table = Texttable(200) table.set_cols_align(["l", "l", "l", "l", "l", "l", "l", "l", "l", "l"]) table.header(["ID", "Name", "Version", "Rev", "OS", "Format", "Created", "Size", "Compressed", "Status"]) for image in allImages: created = image.created.strftime("%Y-%m-%d %H:%M:%S") if image.compress: compressed = "X" else: compressed = "" if image.status.error: status = "Error" elif image.status.cancelled: status = "Cancelled" elif image.status.complete: status = "Done" else: status = "Generating" appliance = self.api.Users(doArgs.account).Appliances(doArgs.id).Get() osImage = appliance.distributionName + " " + appliance.archName table.add_row([image.dbId, image.name, image.version, image.revision, osImage, image.format.name, created, size(image.size), compressed, status]) print table.draw() + "\n" printer.out("Found " + str(len(allImages)) + " images.") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_images() except Exception as e: return handle_uforge_exception(e)
def do_listTargetPlatform(self, args): try: doParser = self.arg_listTargetPlatform() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) if org is None: printer.out( "There is no organization matching [" + doArgs.org + "].", printer.OK) return 0 printer.out("Getting target format with id [" + doArgs.id + "] for [" + org.name + "] . . .") targetFormat = self.api.Orgs(org.dbId).Targetformats( doArgs.id).Get() if targetFormat is None: printer.out( "targetFormat with id " + doArgs.id + " does not exist", printer.ERROR) return 2 else: printer.out( "Getting target platform list for target format [" + targetFormat.name + "] . . .") allTargetPlatforms = self.api.Orgs(org.dbId).Targetformats( targetFormat.dbId).Targetplatforms.Getalltargetplatforms() allTargetPlatforms = order_list_object_by( allTargetPlatforms.targetPlatforms.targetPlatform, "name") if len(allTargetPlatforms) == 0: printer.out( "There is no target platforms in target format [" + targetFormat.name + "].", printer.OK) return 0 printer.out( "Found " + str(len(allTargetPlatforms)) + " target platforms in target format [" + targetFormat.name + "].", printer.OK) table = Texttable(200) table.set_cols_align(["c", "l", "l", "c"]) table.header(["Id", "Name", "Type", "Access"]) for item in allTargetPlatforms: if item.access: access = "X" else: access = "" table.add_row([item.dbId, item.name, item.type, access]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_listTargetPlatform() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: printer.out("Getting all deployments for [" + self.login + "] ...") deployments = self.api.Users(self.login).Deployments.Getall() deployments = deployments.deployments.deployment if deployments is None or len(deployments) == 0: printer.out("No deployment available") else: printer.out("Deployments:") table = print_deploy_header() deployments = generics_utils.order_list_object_by( deployments, "name") for deployment in deployments: deployment_id = deployment.applicationId deployment_name = deployment.name deployment_status = deployment.state instances = deployment.instances.instance instance = instances[-1] source_type = source_id = source_name = hostname = location = cloud_provider = str( None) if instance: if instance.sourceSummary and type( instance.sourceSummary) == ScanSummaryLight: source_type = "Scan" source_id = str( extract_scannedinstance_id( instance.sourceSummary.uri)) source_name = instance.sourceSummary.name elif instance.sourceSummary and type( instance.sourceSummary) == ApplianceSummary: source_type = "Template" source_id = str( generics_utils.extract_id( instance.sourceSummary.uri)) source_name = instance.sourceSummary.name if instance.hostname: hostname = instance.hostname if instance.location: location = instance.location.provider if instance.cloudProvider: cloud_provider = format_cloud_provider( instance.cloudProvider) table.add_row([ deployment_name, deployment_id, cloud_provider, location, hostname, source_type, source_id, source_name, deployment_status ]) print table.draw() + "\n" printer.out("Found " + str(len(deployments)) + " deployments") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_modify(self, args): try: doParser = self.arg_modify() doArgs = doParser.parse_args(shlex.split(args)) if not doArgs.unlimited and doArgs.limit is None and doArgs.nb is None: printer.out("You must specify a modification (unlimited|limit|nb).", printer.ERROR) return 0 printer.out("Getting quotas for ["+doArgs.account+"] ...") quotas = self.api.Users(doArgs.account).Quotas.Get() if quotas is None or len(quotas.quotas.quota) == 0 : printer.out("No quotas available for ["+doArgs.account+"].", printer.ERROR) else: typeExist = False for item in quotas.quotas.quota: if item.type == doArgs.type: typeExist = True if doArgs.nb is not None: item.nb = doArgs.nb if doArgs.unlimited and doArgs.limit is None: item.limit = -1 elif doArgs.limit is not None and not doArgs.unlimited: item.limit = doArgs.limit elif doArgs.limit is not None and doArgs.unlimited: printer.out("You can't set a defined limit and on the other hand set an unlimited limit.", printer.ERROR) return 2 if not typeExist: printer.out("Type is not defined or correct.", printer.ERROR) return 2 else: quotas = self.api.Users(doArgs.account).Quotas.Update(body=quotas) printer.out("Changes done.", printer.OK) quotas = generics_utils.order_list_object_by(quotas.quotas.quota, "type") table = Texttable(200) table.set_cols_align(["c", "c", "c"]) table.header(["Type", "Consumed", "Limit"]) for item in quotas: if item.limit == -1: limit = "unlimited" else: limit = item.limit if item.nb > 1: name = item.type+"s" else: name = item.type table.add_row([name, item.nb, limit]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_modify() return 0 except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) if org is None: printer.out( "There is no organization matching [" + doArgs.org + "].", printer.OK) return 0 printer.out("Getting target format list for [" + org.name + "] . . .") allTargetFormats = self.api.Orgs(org.dbId).Targetformats.Getall() allTargetFormats = order_list_object_by( allTargetFormats.targetFormats.targetFormat, "name") if len(allTargetFormats) == 0: printer.out( "There is no target formats in [" + org.name + "].", printer.OK) return 0 table = Texttable(200) table.set_cols_align(["c", "l", "l", "l", "l", "l", "c"]) table.header([ "Id", "Name", "Format", "Category", "Type", "CredAccountType", "Access" ]) for item in allTargetFormats: if item.access: access = "X" else: access = "" if item.credAccountType is None: credAccountType = "" else: credAccountType = item.credAccountType table.add_row([ item.dbId, item.name, item.format.name, item.category.name, item.type, credAccountType, access ]) print table.draw() + "\n" printer.out( "Found " + str(len(allTargetFormats)) + " target formats.", printer.OK) return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) allDist = self.api.Orgs(org.dbId).Distributions.Getall() if allDist is None: printer.out("No distributions found in [" + org.name + "].") return 0 allDist = generics_utils.order_list_object_by( allDist.distributions.distribution, "name") table = Texttable(200) table.set_cols_align(["l", "l", "l", "l", "l", "l", "l"]) table.header([ "Distribution", "Version", "Architecture", "Access", "Visible", "Default", "Release Date" ]) for item in allDist: if item.active: access = "X" else: access = "" if item.visible: visible = "X" else: visible = "" if item.preselected: default = "X" else: default = "" if item.releaseDate is None: date = "Unknown" else: date = item.releaseDate.strftime("%Y-%m-%d %H:%M:%S") table.add_row([ item.name, item.version, item.arch, access, visible, default, date ]) print table.draw() + "\n" printer.out("Found " + str(len(allDist)) + " distributions in organization [" + org.name + "].") return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def scan_table(scanInstances, scan = None): table = Texttable(800) table.set_cols_dtype(["t","t","t","t"]) table.header(["Id", "Name", "Status", "Distribution"]) if scan: table.add_row([scan.dbId, "\t"+scan.name, scan_status(scan), "" ]) return table for myScannedInstance in scanInstances: table.add_row([myScannedInstance.dbId, myScannedInstance.name, "", myScannedInstance.distribution.name + " "+ myScannedInstance.distribution.version + " " + myScannedInstance.distribution.arch]) scans = generics_utils.order_list_object_by(myScannedInstance.scans.scan, "name") for lscan in scans: table.add_row([lscan.dbId, "\t"+lscan.name, scan_status(lscan), "" ]) return table
def do_list(self, args): try: #call UForge API printer.out("Getting distributions for [" + self.login + "] ...") distributions = self.api.Users(self.login).Distros.Getall() distributions = distributions.distributions if distributions is None or not hasattr(distributions, "distribution"): printer.out("No distributions available") else: table = Texttable(800) table.set_cols_dtype(["t", "t", "t", "t", "t", "t"]) table.header([ "Id", "Name", "Version", "Architecture", "Release Date", "Profiles" ]) distributions = generics_utils.order_list_object_by( distributions.distribution, "name") for distribution in distributions: profiles = self.api.Distributions( distribution.dbId).Profiles.Getall() profiles = profiles.distribProfiles.distribProfile if len(profiles) > 0: profile_text = "" for profile in profiles: profile_text += profile.name + "\n" table.add_row([ distribution.dbId, distribution.name, distribution.version, distribution.arch, distribution.releaseDate.strftime( "%Y-%m-%d %H:%M:%S") if distribution.releaseDate is not None else "", profile_text ]) else: table.add_row([ distribution.dbId, distribution.name, distribution.version, distribution.arch, distribution.releaseDate.strftime( "%Y-%m-%d %H:%M:%S") if distribution.releaseDate is not None else "", "-" ]) print table.draw() + "\n" printer.out("Found " + str(len(distributions)) + " distributions") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) printer.out("Getting distributions list for user \"" + doArgs.account + "\"...") distrosUser = self.api.Users(doArgs.account).Distros.Getall() if distrosUser.total == 0: printer.out("There is no distributions for the user \"" + doArgs.account + "\".") return 0 else: distrosUser = generics_utils.order_list_object_by( distrosUser.distributions.distribution, "name") printer.out("Distribution list for user \"" + doArgs.account + "\" :") table = Texttable(200) table.set_cols_align(["c", "c", "c", "c", "c", "c"]) table.header([ "Distribution", "Version", "Architecture", "Access", "Visible", "Release Date" ]) for item in distrosUser: if item.active: active = "X" else: active = "" if item.visible: visible = "X" else: visible = "" if item.releaseDate is None: releaseDate = "Unknown" else: releaseDate = item.releaseDate table.add_row([ item.name, item.version, item.arch, active, visible, releaseDate ]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_listTargetFormat(self, args): try: doParser = self.arg_listTargetFormat() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) if org is None: printer.out("There is no organization matching ["+doArgs.org+"].", printer.OK) return 0 printer.out("Getting target platform with id ["+doArgs.id+"] for ["+org.name+"] . . .") targetPlatform = self.api.Orgs(org.dbId).Targetplatforms(doArgs.id).Get() if targetPlatform is None: printer.out("TargetPlatform with id "+ doArgs.id +" does not exist", printer.ERROR) return 2 else: printer.out("Getting target format list for target platform ["+targetPlatform.name+"] . . .") allTargetFormats = self.api.Orgs(org.dbId).Targetplatforms(targetPlatform.dbId).Targetformats.Getalltargetformats() allTargetFormats = order_list_object_by(allTargetFormats.targetFormats.targetFormat, "name") if len(allTargetFormats) == 0: printer.out("There is no target formats in target platform ["+targetPlatform.name+"].", printer.OK) return 0 printer.out("Found "+str(len(allTargetFormats))+" target formats in target platform ["+targetPlatform.name+"].", printer.OK) table = Texttable(200) table.set_cols_align(["c", "l", "l", "l", "l", "l", "c"]) table.header(["Id", "Name", "Format", "Category", "Type", "CredAccountType", "Access"]) for item in allTargetFormats: if item.access: access = "X" else: access = "" if item.credAccountType is None: credAccountType = "" else: credAccountType = item.credAccountType table.add_row([item.dbId, item.name, item.format.name, item.category.name, item.type, credAccountType, access]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_listTargetFormat() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) printer.out("Getting organizations list for user \"" + doArgs.account + "\" :") orgsUser = self.api.Users(doArgs.account).Orgs.Getall() if len(orgsUser.orgs.org) is 0: printer.out("[" + doArgs.account + "] belongs to no organization.") return 0 else: orgsUser = generics_utils.order_list_object_by( orgsUser.orgs.org, "name") printer.out("Organization list for user \"" + doArgs.account + "\" :") table = Texttable(200) table.set_cols_align(["c", "c", "c", "c", "c"]) table.header( ["Name", "Default", "Auto Activation", "Store", "Admin"]) for item in orgsUser: if item.activateNewUsers: dfltActive = "X" else: dfltActive = "" if item.galleryUri is None: store = "" else: store = "X" if item.defaultOrg: default = "X" else: default = "" if item.admin: admin = "X" else: admin = "" table.add_row( [item.name, default, dfltActive, store, admin]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: printer.out("Getting all deployments for [" + self.login + "] ...") deployments = self.api.Users(self.login).Deployments.Getall() deployments = deployments.deployments.deployment if deployments is None or len(deployments) == 0: printer.out("No deployment available") else: printer.out("Deployments:") table = print_deploy_header() deployments = generics_utils.order_list_object_by(deployments, "name") for deployment in deployments: deployment_id = deployment.applicationId deployment_name = deployment.name deployment_status = deployment.state instances = deployment.instances.instance instance = instances[-1] source_type = source_id = source_name = hostname = location = cloud_provider = str(None) if instance: if instance.sourceSummary and type(instance.sourceSummary) == ScanSummaryLight: source_type = "Scan" source_id = str(extract_scannedinstance_id(instance.sourceSummary.uri)) source_name = instance.sourceSummary.name elif instance.sourceSummary and type(instance.sourceSummary) == ApplianceSummary: source_type = "Template" source_id = str(generics_utils.extract_id(instance.sourceSummary.uri)) source_name = instance.sourceSummary.name if instance.hostname: hostname = instance.hostname if instance.location: location = instance.location.provider if instance.cloudProvider: cloud_provider = format_cloud_provider(instance.cloudProvider) table.add_row([deployment_name, deployment_id, cloud_provider, location, hostname, source_type, source_id, source_name, deployment_status]) print table.draw() + "\n" printer.out("Found " + str(len(deployments)) + " deployments") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) allDist = self.api.Orgs(org.dbId).Distributions.Getall() allDist = allDist.distributions.distribution goldenId = None for distrib in allDist: if distrib.name == doArgs.name and distrib.version == doArgs.version and distrib.arch == doArgs.arch: goldenId = distrib.dbId break if goldenId is None: printer.out("No distributions found with the arguments entered.") return 2 allGoldens = self.api.Orgs(org.dbId).Distributions(goldenId).Goldens.Getall() if allGoldens is None: printer.out("No Golden Image found for this distribution.") return 0 allGoldens = order_list_object_by(allGoldens.pkgs.pkg, "name") if len(allGoldens) is 0: printer.out("No golden image for ["+org.name+"]") return 0 table = Texttable(200) table.set_cols_align(["l", "l"]) table.header(["Name", "Date"]) for item in allGoldens: table.add_row([item.name, item.pkgBuildDate.strftime("%Y-%m-%d %H:%M:%S")]) print table.draw() + "\n" printer.out("Found "+str(len(allGoldens))+" golden images in organization ["+org.name+"].") return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) if org is None: printer.out( "There is no organization matching [" + doArgs.org + "].", printer.OK) return 0 printer.out("Getting target platform list for user \"" + doArgs.account + "\" :") if doArgs.org is not None: targetPlatformsUser = self.api.Users( doArgs.account).Targetplatforms.Getall(org=org.dbId) else: targetPlatformsUser = self.api.Users( doArgs.account).Targetplatforms.Getall() if targetPlatformsUser is None or len( targetPlatformsUser.targetPlatforms.targetPlatform) == 0: printer.out("There is no target platform for the user \"" + doArgs.account + "\" in [" + org.name + "].") return 0 else: targetPlatformsUser = generics_utils.order_list_object_by( targetPlatformsUser.targetPlatforms.targetPlatform, "name") printer.out("Target platform list for user \"" + doArgs.account + "\":") table = Texttable(200) table.set_cols_align(["c", "c", "c", "c"]) table.header(["Id", "Name", "Type", "Access"]) for item in targetPlatformsUser: if item.access: access = "X" else: access = "" table.add_row([item.dbId, item.name, item.type, access]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: #call UForge API printer.out("Getting templates for [" + self.login + "] ...") appliances = self.api.Users(self.login).Appliances().Getall() appliances = appliances.appliances if appliances is None or not hasattr(appliances, 'appliance'): printer.out("No template") else: images = self.api.Users(self.login).Images.Getall() images = images.images 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" ]) appliances = generics_utils.order_list_object_by( appliances.appliance, "name") for appliance in appliances: nbImage = 0 if images is not None and hasattr(images, 'image'): for image in images.image: if hasattr( image, 'applianceUri' ) and image.applianceUri == appliance.uri: nbImage += 1 table.add_row([ appliance.dbId, appliance.name, str(appliance.version), appliance.distributionName + " " + appliance.archName, appliance.created.strftime("%Y-%m-%d %H:%M:%S"), appliance.lastModified.strftime("%Y-%m-%d %H:%M:%S"), nbImage, appliance.nbUpdates, "X" if appliance.imported else "", "X" if appliance.shared else "" ]) print table.draw() + "\n" printer.out("Found " + str(len(appliances)) + " templates") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) allDist = self.api.Orgs(org.dbId).Distributions.Getall() if allDist is None: printer.out("No distributions found in [" + org.name + "].") return 0 allDist = generics_utils.order_list_object_by(allDist.distributions.distribution, "name") table = Texttable(200) table.set_cols_align(["l", "l", "l", "l", "l", "l", "l"]) table.header(["Distribution", "Version", "Architecture", "Access", "Visible", "Default", "Release Date"]) for item in allDist: if item.active: access = "X" else: access = "" if item.visible: visible = "X" else: visible = "" if item.preselected: default = "X" else: default = "" if item.releaseDate is None: date = "Unknown" else: date = item.releaseDate.strftime("%Y-%m-%d %H:%M:%S") table.add_row([item.name, item.version, item.arch, access, visible, default, date]) print table.draw() + "\n" printer.out("Found " + str(len(allDist)) + " distributions in organization [" + org.name + "].") return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_search(self, args): try: #add arguments doParser = self.arg_search() 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("Search package '" + doArgs.pkg + "' ...") distribution = self.api.Distributions(doArgs.id).Get() printer.out("for OS '" + distribution.name + "', version " + distribution.version) pkgs = self.api.Distributions( distribution.dbId).Pkgs.Getall(Query="name==" + doArgs.pkg) pkgs = pkgs.pkgs.pkg if pkgs is None or len(pkgs) == 0: printer.out("No package found") else: table = Texttable(800) table.set_cols_dtype(["t", "t", "t", "t", "t", "t", "t"]) table.header([ "Name", "Version", "Arch", "Release", "Build date", "Size", "FullName" ]) pkgs = generics_utils.order_list_object_by(pkgs, "name") for pkg in pkgs: table.add_row([ pkg.name, pkg.version, pkg.arch, pkg.release, pkg.pkgBuildDate.strftime("%Y-%m-%d %H:%M:%S"), size(pkg.size), pkg.fullName ]) print table.draw() + "\n" printer.out("Found " + str(len(pkgs)) + " packages") except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_search() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) printer.out("Getting organizations list for user \""+doArgs.account+"\" :") orgsUser = self.api.Users(doArgs.account).Orgs.Getall() if len(orgsUser.orgs.org) is 0: printer.out("["+doArgs.account+"] belongs to no organization.") return 0 else: orgsUser=generics_utils.order_list_object_by(orgsUser.orgs.org, "name") printer.out("Organization list for user \""+doArgs.account+"\" :") table = Texttable(200) table.set_cols_align(["c", "c", "c", "c", "c"]) table.header(["Name", "Default", "Auto Activation", "Store", "Admin"]) for item in orgsUser: if item.activateNewUsers: dfltActive = "X" else: dfltActive = "" if item.galleryUri is None: store = "" else: store = "X" if item.defaultOrg: default = "X" else: default = "" if item.admin: admin = "X" else: admin = "" table.add_row([item.name, default, dfltActive, store, admin]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) if org is None: printer.out("There is no organization matching ["+doArgs.org+"].", printer.OK) return 0 printer.out("Getting target format list for user \""+doArgs.account+"\" :") if doArgs.org is not None: targetFormatsUser = self.api.Users(doArgs.account).Targetformats.Getall(org=org.dbId) else: targetFormatsUser = self.api.Users(doArgs.account).Targetformats.Getall() if targetFormatsUser is None or len(targetFormatsUser.targetFormats.targetFormat) == 0: printer.out("There is no target format for the user \""+doArgs.account+"\" in [" + org.name + "].") return 0 else: targetFormatsUser = generics_utils.order_list_object_by(targetFormatsUser.targetFormats.targetFormat, "name") printer.out("Target format list for user \""+doArgs.account+"\":") table = Texttable(200) table.set_cols_align(["c", "l", "l", "l", "l", "l", "c"]) table.header(["Id", "Name", "Format", "Category", "Type", "CredAccountType", "Access"]) for item in targetFormatsUser: if item.access: access = "X" else: access = "" if item.credAccountType is None: credAccountType = "" else: credAccountType = item.credAccountType table.add_row([item.dbId, item.name, item.format.name, item.category.name, item.type, credAccountType, access]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: #call UForge API printer.out("Getting all your bundles ...") bundles = self.api.Users(self.login).Mysoftware.Getall() bundles = bundles.mySoftwareList.mySoftware if bundles is None or len(bundles) == 0: printer.out("No bundles available") else: table = Texttable(800) table.set_cols_dtype(["t","t","t", "t","t", "t"]) table.header(["Id", "Name", "Version", "Description", "Size", "Imported"]) bundles = generics_utils.order_list_object_by(bundles, "name") for bundle in bundles: table.add_row([bundle.dbId, bundle.name, bundle.version, bundle.description, size(bundle.size), "X" if bundle.imported else ""]) print table.draw() + "\n" printer.out("Found "+str(len(bundles))+" bundles") return 0 except Exception as e: return handle_uforge_exception(e)
def do_categories(self, args): try: #call UForge API printer.out("Getting all categories available for bundles ...") orgId = (self.api.Users(self.login).Orgs().Getall()).orgs.org[0].dbId categories = self.api.Orgs(orgId).Categories.Getall(Query="type=='PROJECT'") categories = generics_utils.order_list_object_by(categories.categories.category, "name") if categories is None or len(categories) == 0: printer.out("No categories available") else: table = Texttable(800) table.set_cols_dtype(["t"]) table.header(["Name"]) for category in categories: table.add_row([category.name]) print table.draw() + "\n" printer.out("Found "+str(len(categories))+" categories") return 0 except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: # call UForge API printer.out("Getting all your accounts ...") 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") else: table = Texttable(800) table.set_cols_dtype(["t", "t", "t", "t"]) table.header(["Id", "Name", "Type", "Created"]) accounts = generics_utils.order_list_object_by(accounts, "name") for account in accounts: table.add_row( [account.dbId, account.name, account.targetPlatform.name, account.created.strftime("%Y-%m-%d %H:%M:%S")]) print table.draw() + "\n" printer.out("Found " + str(len(accounts)) + " accounts") return 0 except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) printer.out("Getting distributions list for user \""+doArgs.account+"\"...") distrosUser = self.api.Users(doArgs.account).Distros.Getall() if distrosUser.total == 0: printer.out("There is no distributions for the user \""+doArgs.account+"\".") return 0 else: distrosUser = generics_utils.order_list_object_by(distrosUser.distributions.distribution, "name") printer.out("Distribution list for user \""+doArgs.account+"\" :") table = Texttable(200) table.set_cols_align(["c", "c", "c", "c", "c", "c"]) table.header(["Distribution", "Version", "Architecture", "Access", "Visible", "Release Date"]) for item in distrosUser: if item.active: active = "X" else: active = "" if item.visible: visible = "X" else: visible = "" if item.releaseDate is None: releaseDate = "Unknown" else: releaseDate = item.releaseDate table.add_row([item.name, item.version, item.arch, active, visible, releaseDate]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) printer.out("Getting user list for ["+org.name+"] . . .") allFormats = self.api.Orgs(org.dbId).Formats.Getall() allFormats = order_list_object_by(allFormats.imageFormats.imageFormat, "name") if len(allFormats) == 0: printer.out("There is no formats in ["+org.name+"].") return 0 table = Texttable(200) table.set_cols_align(["l", "l", "c"]) table.header(["Format", "Access", "Default"]) for item in allFormats: if item.access: access = "X" else: access = "" if item.preselected: preselected = "X" else: preselected = "" table.add_row([item.name, access, preselected]) print table.draw() + "\n" printer.out("Found "+str(len(allFormats))+" formats.") return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) if org is None: printer.out("There is no organization matching ["+doArgs.org+"].", printer.OK) return 0 printer.out("Getting target platform list for ["+org.name+"] . . .") allTargetPlatforms = self.api.Orgs(org.dbId).Targetplatforms.Getall() allTargetPlatforms = order_list_object_by(allTargetPlatforms.targetPlatforms.targetPlatform, "name") if len(allTargetPlatforms) == 0: printer.out("There is no target platforms in ["+org.name+"].", printer.OK) return 0 table = Texttable(200) table.set_cols_align(["c", "l", "l", "c"]) table.header(["Id", "Name", "Type", "Access"]) for item in allTargetPlatforms: if item.access: access = "X" else: access = "" table.add_row([item.dbId, item.name, item.type, access]) print table.draw() + "\n" printer.out("Found "+str(len(allTargetPlatforms))+" target platforms.", printer.OK) return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) allOrgs = self.api.Orgs.Getall() allOrgs = order_list_object_by(allOrgs.orgs.org, "name") printer.out("List of organizations :") table = Texttable(200) table.set_cols_align(["l", "c", "c", "c"]) table.header(["Name", "Default", "Auto Activation", "Store"]) for item in allOrgs: if item.defaultOrg: default = "X" else: default = "" if item.activateNewUsers: active = "X" else: active = "" if item.galleryUri is not None: gallery = "X" else: gallery = "" table.add_row([item.name, default, active, gallery]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) allOrgs = self.api.Orgs.Getall() allOrgs = order_list_object_by(allOrgs.orgs.org, "name") printer.out("List of organizations :") table = Texttable(200) table.set_cols_align(["l", "c", "c", "c"]) table.header(["Name", "Default", "Auto Activation", "Store"]) for item in allOrgs: if item.defaultOrg: default = "X" else: default = "" if item.activateNewUsers: active = "X" else: active = "" if item.galleryUri is not None: gallery = "X" else: gallery = "" table.add_row([item.name, default, active, gallery]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: # add arguments do_parser = self.arg_list() do_args = do_parser.parse_args(shlex.split(args)) # call UForge API printer.out("Getting vendors ...") org = org_utils.org_get(self.api, do_args.org) vendors = self.api.Orgs(org.dbId).Vendors().Getall() table = Texttable(200) table.set_cols_align(["c", "c", "c"]) table.header(["Active", "Name", "Email"]) sorted_vendor_list = generics_utils.order_list_object_by(vendors.vendors.vendor, "name") for vendor in sorted_vendor_list: table.add_row(["" if vendor.inactive else "X", vendor.name, vendor.email]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return marketplace_utils.handle_uforge_exception(e)
def do_categories(self, args): try: #call UForge API printer.out("Getting all categories available for bundles ...") orgId = (self.api.Users( self.login).Orgs().Getall()).orgs.org[0].dbId categories = self.api.Orgs(orgId).Categories.Getall( Query="type=='PROJECT'") categories = generics_utils.order_list_object_by( categories.categories.category, "name") if categories is None or len(categories) == 0: printer.out("No categories available") else: table = Texttable(800) table.set_cols_dtype(["t"]) table.header(["Name"]) for category in categories: table.add_row([category.name]) print table.draw() + "\n" printer.out("Found " + str(len(categories)) + " categories") return 0 except Exception as e: return handle_uforge_exception(e)
def do_enable(self, args): try: doParser = self.arg_enable() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) if org is None: printer.out("There is no organization matching ["+doArgs.org+"].", printer.OK) return 0 targetFormatsOrg = self.api.Orgs(org.dbId).Targetformats.Getall() if targetFormatsOrg is None or len(targetFormatsOrg.targetFormats.targetFormat) == 0: printer.out("There is no target format for the user \""+doArgs.account+"\" in [" + org.name + "].") return 0 else: targetFormatsOrg = targetFormatsOrg.targetFormats.targetFormat targetFormatsList = targetFormats() targetFormatsList.targetFormats = pyxb.BIND() targetFormatsOrg = compare(targetFormatsOrg, doArgs.targetFormats, "name") if len(targetFormatsOrg) == 0: listName = "" for tfname in doArgs.targetFormats: listName = listName + tfname + " " printer.out("There is no target formats matching ["+listName+"].") return 0 for item in targetFormatsOrg: targetFormatToEnable = targetFormat() targetFormatToEnable = item targetFormatToEnable.active = True targetFormatToEnable.access = True printer.out("Enabling ["+item.name+"].") targetFormatsList.targetFormats.append(targetFormatToEnable) result = self.api.Users(doArgs.account).Targetformats.Update(Org=org.name,body=targetFormatsList) result =generics_utils.order_list_object_by(result.targetFormats.targetFormat, "name") table = Texttable(200) table.set_cols_align(["c", "l", "l", "l", "l", "l", "c"]) table.header(["Id", "Name", "Format", "Category", "Type", "CredAccountType", "Access"]) for item in result: if item.access: access = "X" else: access = "" if item.credAccountType is None: credAccountType = "" else: credAccountType = item.credAccountType table.add_row([item.dbId, item.name, item.format.name, item.category.name, item.type, credAccountType, access]) printer.out("Target Format list for user \""+doArgs.account+"\" :") print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_enable() except Exception as e: return handle_uforge_exception(e)
def do_modify(self, args): try: doParser = self.arg_modify() doArgs = doParser.parse_args(shlex.split(args)) if not doArgs.unlimited and doArgs.limit is None and doArgs.nb is None: printer.out( "You must specify a modification (unlimited|limit|nb).", printer.ERROR) return 0 printer.out("Getting quotas for [" + doArgs.account + "] ...") quotas = self.api.Users(doArgs.account).Quotas.Get() if quotas is None or len(quotas.quotas.quota) == 0: printer.out( "No quotas available for [" + doArgs.account + "].", printer.ERROR) else: typeExist = False for item in quotas.quotas.quota: if item.type == doArgs.type: typeExist = True if doArgs.nb is not None: item.nb = doArgs.nb if doArgs.unlimited and doArgs.limit is None: item.limit = -1 elif doArgs.limit is not None and not doArgs.unlimited: item.limit = doArgs.limit elif doArgs.limit is not None and doArgs.unlimited: printer.out( "You can't set a defined limit and on the other hand set an unlimited limit.", printer.ERROR) return 2 if not typeExist: printer.out("Type is not defined or correct.", printer.ERROR) return 2 else: quotas = self.api.Users( doArgs.account).Quotas.Update(body=quotas) printer.out("Changes done.", printer.OK) quotas = generics_utils.order_list_object_by( quotas.quotas.quota, "type") table = Texttable(200) table.set_cols_align(["c", "c", "c"]) table.header(["Type", "Consumed", "Limit"]) for item in quotas: if item.limit == -1: limit = "unlimited" else: limit = item.limit if item.nb > 1: name = item.type + "s" else: name = item.type table.add_row([name, item.nb, limit]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_modify() return 0 except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) org = org_utils.org_get(self.api, doArgs.org) allRepo = self.api.Orgs(org.dbId).Repositories.Getall() if allRepo is None: printer.out("No repositories found in [" + org.name + "].") return 0 if doArgs.sort is not None: if doArgs.sort.lower() == "name": printer.out("Repository list ordered by [name] :") allRepo = order_list_object_by( allRepo.repositories.repository, "name") elif doArgs.sort.lower() == "id": printer.out("Repository list ordered by [id] :") allRepo = sorted(allRepo.repositories.repository, key=lambda x: getattr(x, "dbId"), reverse=False) elif doArgs.sort.lower() == "url": printer.out("Repository list ordered by [url] :") allRepo = order_list_object_by( allRepo.repositories.repository, "url") elif doArgs.sort.lower() == "type": printer.out("Repository list ordered by [type] :") allRepo = order_list_object_by( allRepo.repositories.repository, "packagingType") else: printer.out("Sorting parameter filled don't exist.", printer.WARNING) printer.out("Repository list :") allRepo = sorted(allRepo.repositories.repository, key=lambda x: getattr(x, "dbId"), reverse=False) else: printer.out("Repository list :") allRepo = sorted(allRepo.repositories.repository, key=lambda x: getattr(x, "dbId"), reverse=False) table = Texttable(200) table.set_cols_align(["c", "c", "l", "l", "c"]) table.set_cols_width([5, 5, 30, 80, 8]) table.header(["Id", "Off. Supported", "Name", "URL", "Type"]) for item in allRepo: if item.officiallySupported: officiallySupported = "X" else: officiallySupported = "" table.add_row([ item.dbId, officiallySupported, item.name, item.url, item.packagingType ]) print table.draw() + "\n" printer.out("Found " + str(len(allRepo)) + " repositories.") return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_info(self, args): try: doParser = self.arg_info() doArgs = doParser.parse_args(shlex.split(args)) userAppliance = self.api.Users(doArgs.account).Appliances(doArgs.id).Get() printer.out("Informations about [" + userAppliance.name + "]:") table = Texttable(200) table.set_cols_align(["l", "l"]) table.add_row(["Name", userAppliance.name]) table.add_row(["Id", userAppliance.dbId]) table.add_row(["Version", userAppliance.version]) table.add_row(["Uri", userAppliance.uri]) table.add_row(["Created", userAppliance.created.strftime("%Y-%m-%d %H:%M:%S")]) table.add_row(["Last Modified", userAppliance.created.strftime("%Y-%m-%d %H:%M:%S")]) table.add_row(["Last Package Update", userAppliance.lastPkgUpdate.strftime("%Y-%m-%d %H:%M:%S")]) table.add_row(["Available OS Updates", userAppliance.nbUpdates]) if userAppliance.shared: shared = "Yes" else: shared = "No" table.add_row(["Shared", shared]) if userAppliance.imported: imported = "Yes" else: imported = "No" table.add_row(["Cloned from App Store", imported]) table.add_row(["Description", userAppliance.description]) print table.draw() + "\n" printer.out("OS Profile", printer.INFO) table = Texttable(200) table.set_cols_align(["l", "l"]) table.add_row(["OS", userAppliance.distributionName + " " + userAppliance.archName]) if userAppliance.osProfile is not None: table.add_row(["OS Profile Type", userAppliance.osProfile.name]) else: table.add_row(["OS Profile", "None"]) if userAppliance.osProfile is not None: packagesUri = extractId(userAppliance.osProfile.packagesUri, operation=False) allPkgs = self.api.Users(doArgs.account).Appliances(packagesUri[1]).Osprofile(packagesUri[0]).Pkgs.Getall() table.add_row(["# OS Packages", str(len(allPkgs.pkgs.pkg))]) if userAppliance.osProfile is not None: pkgsTotalSize = 0 for pkg in allPkgs.pkgs.pkg: pkgsTotalSize = pkgsTotalSize + pkg.size osTotalSize = pkgsTotalSize + userAppliance.size else: osTotalSize = userAppliance.size table.add_row(["Total OS Profile Size", size(osTotalSize)]) pkgNumber = 0 allPkgs = generics_utils.order_list_object_by(allPkgs.pkgs.pkg, "name") if doArgs.all: for pkg in allPkgs: pkgNumber = pkgNumber + 1 table.add_row(["Packages N " + str(pkgNumber), pkg.name + " " + pkg.version + " " + pkg.arch + " (" + size(pkg.size) + ")"]) print table.draw() + "\n" printer.out("Install Settings", printer.INFO) table = Texttable(200) table.set_cols_align(["l", "l"]) if userAppliance.installProfile.adminPasswordAuto: table.add_row(["Password", userAppliance.installProfile.adminPassword]) else: table.add_row(["Password", "asked during first boot or install"]) if userAppliance.installProfile.internetSettingsAuto: table.add_row(["Internet Settings", "DHCP"]) else: table.add_row(["Internet Settings", "asked during first boot or install"]) if userAppliance.installProfile.skipLicenses: table.add_row(["Licensing", "skipped"]) else: table.add_row(["Licensing", "shown at first boot or install"]) if userAppliance.installProfile.timezoneAuto: table.add_row(["Time Zone", userAppliance.installProfile.timezone]) else: table.add_row(["Time Zone", "asked during first boot or install"]) if userAppliance.installProfile.partitionTable.disks.disk is not None: diskNumber = 0 for disk in userAppliance.installProfile.partitionTable.disks.disk: diskNumber = diskNumber + 1 table.add_row(["Disk " + str(diskNumber), disk.name + " " + str(disk.size) + " MB " + disk.partitionType]) if disk.partitions.partition is not None: partitionNumber = 0 for partition in disk.partitions.partition: partitionNumber = partitionNumber + 1 if partition.fstype is not None: fstype = partition.fstype else: fstype = "" if partition.mpoint is not None: mpoint = partition.mpoint else: mpoint = "" if partition.label is not None: label = partition.label else: label = "" if partition.growable: growable = "grow" else: growable = "" table.add_row(["Partition " + str(partitionNumber), disk.name + partition.name + " " + str(partition.partitionSize) + " MB " + fstype + " " + mpoint + " " + label + " " + growable]) if partition.logicalPartitions.logicalPartition is not None: logicalPartitionNumber = 0 for logicalPartition4 in partition.logicalPartitions.logicalPartition: logicalPartitionNumber = logicalPartitionNumber + 1 if logicalPartition4.fstype is not None: fstype2 = logicalPartition4.fstype else: fstype2 = "" if logicalPartition4.mpoint is not None: mpoint2 = logicalPartition4.mpoint else: mpoint2 = "" if logicalPartition4.label is not None: label2 = logicalPartition4.label else: label2 = "" if logicalPartition4.growable: growable2 = "grow" else: growable2 = "" table.add_row(["Logical Partition " + str(logicalPartitionNumber), logicalPartition4.name + " " + str(logicalPartition4.partitionSize) + " MB " + fstype2 + " " + mpoint2 + " " + label2 + " " + growable2]) print table.draw() + "\n" printer.out("Projects", printer.INFO) table = Texttable(200) table.set_cols_align(["l", "l"]) allProjects = self.api.Users(doArgs.account).Appliances(userAppliance.dbId).Projects.Getall() if allProjects is None: totalProjects = "0" else: totalProjects = str(len(allProjects.projects.project)) table.add_row(["# Projects", totalProjects]) if doArgs.all and totalProjects != "0": projectNumber = 0 for project in allProjects.projects.project: projectNumber = projectNumber + 1 table.add_row(["Project N " + str(projectNumber), project.name + " " + project.version + " (" + project.size + " bytes)"]) print table.draw() + "\n" printer.out("My Software", printer.INFO) table = Texttable(200) table.set_cols_align(["l", "l"]) allSoftware = self.api.Users(doArgs.account).Appliances(userAppliance.dbId).Mysoftware.Getall() if allSoftware is None: totalSoftwares = "0" else: totalSoftwares = str(len(allSoftware.mySoftwareList.mySoftware)) table.add_row(["# Custom Software", totalSoftwares]) if doArgs.all and totalSoftwares != "0": softwareNumber = 0 for software in allSoftware.mySoftwareList.mySoftware: softwareNumber = softwareNumber + 1 table.add_row(["Project N " + str(softwareNumber), software.name + " " + software.version + " (" + software.size + " bytes)"]) print table.draw() + "\n" printer.out("Configuration", printer.INFO) table = Texttable(200) table.set_cols_align(["l", "l"]) if userAppliance.oasPackageUri is None: table.add_row(["OAS Pkg Uploaded", "no"]) else: Oas = self.api.Users(doArgs.account).Appliances(userAppliance.dbId).Oas(extractId(userAppliance.oasPackageUri)).Get() if not Oas.uploaded: table.add_row(["OAS Pkg Uploaded", "no"]) else: table.add_row(["OAS Pkg Uploaded", "yes"]) table.add_row(["OAS Pkg", Oas.name]) table.add_row(["OAS Pkg Size", size(Oas.size)]) if Oas.licenseUploaded: table.add_row(["OAS Licence Uploaded", "yes"]) else: table.add_row(["OAS Licence Uploaded", "no"]) if userAppliance.bootScriptsUri is None: table.add_row(["# Boot Scripts", "0"]) else: bootScripts = self.api.Users(doArgs.account).Appliances(userAppliance.dbId).Bootscripts(extractId(userAppliance.bootScriptsUri)).Getall() table.add_row(["# Boot Scripts", str(len(bootScripts.bootScripts.bootScript))]) bootScriptsNumber = 0 for item in bootScripts.bootScripts.bootScript: bootScriptsNumber = bootScriptsNumber + 1 table.add_row(["Boot Script N 1 Details", item.name + " " + item.bootType]) print table.draw() + "\n" return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_info() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) id = doArgs.account imagesList = self.api.Users(id).Images.Get() imagesList = imagesList.images.image appliancesList = self.api.Users(id).Appliances.Getall() appliancesList = appliancesList.appliances.appliance if imagesList is None or len(imagesList) == 0: printer.out("There is no images for user [" + doArgs.account + "].") return 0 if doArgs.name is not None: imagesList = compare(imagesList, doArgs.name, "name") if doArgs.format is not None: imagesList = compare(imagesList, doArgs.format, "format", "name") if doArgs.os is not None: imagesList = compare(list=imagesList, values=doArgs.os, attrName='distributionName', subattrName=None, otherList=appliancesList, linkProperties=['applianceUri', 'uri']) if len(imagesList) == 0: printer.out("There is no images for user [" + doArgs.account + "] with these filters.") return 0 imagesListSorted = order_list_object_by(imagesList, "name") printer.out("List of images :", printer.OK) table = Texttable(200) table.set_cols_align( ["c", "c", "c", "c", "c", "c", "c", "c", "c", "c"]) table.header([ "ID", "Name", "Version", "Rev", "OS", "Format", "Created", "Size", "Compressed", "Status" ]) count = 0 error = 0 for item in imagesListSorted: count = count + 1 if not item.compress: compressed = "No" else: compressed = "Yes" if item.status.error: status = "Error" error = error + 1 else: status = "Done" timeCreated = item.created.strftime("%Y-%m-%d %H:%M:%S") for item3 in imagesList: for item2 in appliancesList: if item3.applianceUri == item2.uri: os = "" + item2.distributionName + " " + item2.archName break table.add_row([ item.dbId, item.name, item.version, item.revision, os, item.format.name, timeCreated, size(item.size), compressed, status ]) print table.draw() + "\n" printer.out(str(count) + " images found.") if error != 0: printer.out(str(error) + " images with error status.") return 0 except ArgumentParserError as e: printer.out("In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: doParser = self.arg_list() doArgs = doParser.parse_args(shlex.split(args)) id = doArgs.account imagesList = self.api.Users(id).Images.Get() imagesList = imagesList.images.image appliancesList = self.api.Users(id).Appliances.Getall() appliancesList = appliancesList.appliances.appliance if imagesList is None or len(imagesList) == 0: printer.out("There is no images for user [" + doArgs.account + "].") return 0 if doArgs.name is not None: imagesList = compare(imagesList, doArgs.name, "name") if doArgs.format is not None: imagesList = compare(imagesList, doArgs.format, "format", "name") if doArgs.os is not None: imagesList = compare(list=imagesList, values=doArgs.os, attrName='distributionName', subattrName=None, otherList=appliancesList, linkProperties=['applianceUri', 'uri']) if len(imagesList) == 0: printer.out("There is no images for user [" + doArgs.account + "] with these filters.") return 0 imagesListSorted = order_list_object_by(imagesList, "name") printer.out("List of images :", printer.OK) table = Texttable(200) table.set_cols_align(["c", "c", "c", "c", "c", "c", "c", "c", "c", "c"]) table.header(["ID", "Name", "Version", "Rev", "OS", "Format", "Created", "Size", "Compressed", "Status"]) count = 0 error = 0 for item in imagesListSorted: count = count + 1 if not item.compress: compressed = "No" else: compressed = "Yes" if item.status.error: status = "Error" error = error + 1 else: status = "Done" timeCreated = item.created.strftime("%Y-%m-%d %H:%M:%S") for item3 in imagesList: for item2 in appliancesList: if item3.applianceUri == item2.uri: os = "" + item2.distributionName + " " + item2.archName break table.add_row([item.dbId, item.name, item.version, item.revision, os, item.targetFormat.name, timeCreated, size(item.size), compressed, status]) print table.draw() + "\n" printer.out(str(count)+" images found.") if error != 0: printer.out(str(error)+" images with error status.") return 0 except ArgumentParserError as e: printer.out("In Arguments: "+str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)
def do_list(self, args): try: # call UForge API # get images printer.out("Getting all images and publications for [" + self.login + "] ...") images = self.api.Users(self.login).Images.Getall() images = images.images.image # get publications pimages = self.api.Users(self.login).Pimages.Getall() pimages = pimages.publishImages.publishImage if images is None or len(images) == 0: printer.out("No images available") else: printer.out("Images:") 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", "Generation Status" ]) images = generics_utils.order_list_object_by(images, "name") for image in images: 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" printer.out("Found " + str(len(images)) + " images") if pimages is None or len(pimages) == 0: printer.out("No publication available") else: printer.out("Publications:") table = Texttable(800) table.set_cols_dtype(["t", "t", "t", "t", "t", "t"]) table.header([ "Template name", "Image ID", "Account name", "Format", "Cloud ID", "Status" ]) pimages = generics_utils.order_list_object_by(pimages, "name") for pimage in pimages: pubStatus = self.get_publish_status(pimage.status) table.add_row([ pimage.name, generics_utils.extract_id(pimage.imageUri), pimage.credAccount.name if pimage.credAccount is not None else "-", pimage.credAccount.targetPlatform.name, pimage.cloudId if pimage.cloudId is not None else "-", pubStatus ]) print table.draw() + "\n" printer.out("Found " + str(len(pimages)) + " publications") return 0 except ArgumentParserError as e: printer.out("ERROR: In Arguments: " + str(e), printer.ERROR) self.help_list() except Exception as e: return handle_uforge_exception(e)