def _setup_common(self): # Items common to backends can go here. decompose_name = self.input_name self.registry, self.repo, self.image, self.tag, self.digest = Decompose( decompose_name).all if not self.fully_qualified and self.remote: self.registry, self.repo, self.image, self.tag, self.digest = Decompose( self.fq_name).all if not self.image: raise ValueError( 'Cannot create image object: no image detected from "{}"'. format(decompose_name))
def _make_image(self, image, info, remote=False): img_obj = Image(image, backend=self, remote=remote) if remote: return img_obj name = info['Id'] img_obj.input_name = image img_obj.name = image img_obj.config = info img_obj.backend = self img_obj.id = name img_obj.registry, img_obj.repo, img_obj.image, img_obj.tag, _ = Decompose( image).all img_obj.repotags = info['RepoTags'] img_obj.created = info['Created'] img_obj.size = None img_obj.original_structure = info img_obj.deep = True img_obj.labels = info.get('Labels', None) img_obj.version = img_obj.get_label("Version") img_obj.release = img_obj.get_label("Release") ostree_manifest = self.syscontainers.get_manifest(image) if ostree_manifest: ostree_manifest = json_loads(ostree_manifest) img_obj.digest = None if ostree_manifest is None else ostree_manifest.get( 'Digest') or ostree_manifest.get('digest') img_obj.os = img_obj.get_label("Os") img_obj.arch = img_obj.get_label("Arch") img_obj.graph_driver = None return img_obj
def update_all_images(self, be, debug): images = be.get_images() images_by_name = {} for i in images: if i.repotags is None: continue img_name = i.repotags[0] d = Decompose(img_name) if d.registry == "": write_err( "Image {} not fully qualified: skipping".format(img_name)) continue images_by_name[img_name] = i could_not_pull = {} pulled = {} write_out("Checking image {}...".format(img_name)) try: be.update(img_name, debug=debug, force=False, image_object=i) pulled[img_name] = True except: # pylint: disable=bare-except could_not_pull[img_name] = True def get_status(img_name, pre_id, post_id): COLOR_RED = 31 COLOR_GREEN = 32 if img_name in could_not_pull.keys(): return "Could not pull", COLOR_RED if pre_id != post_id: return "Updated now", COLOR_GREEN return "Updated", COLOR_GREEN def colored(line, color): if sys.stdout.isatty(): return "\x1b[1;%dm%s\x1b[0m" % (color, line) else: return line cols = "{0:50} {1:32} {2:32} {3:15}" write_out("\nSUMMARY\n") write_out( cols.format("Image", "Image ID before update", "Image ID after update", "Status")) for k, v in images_by_name.items(): new_image = be.inspect_image(k) status, color = get_status(k, v.id, new_image.id) colored_status = colored(status[:15], color) write_out( cols.format(k[:50], v.id[:32], new_image.id[:32], colored_status))
def ImagePush(self, image, pulp, satellite, verify_ssl, url, username, password, activation_key, repo_id, registry_type, sign_by, gnupghome, insecure, anonymous): p = Push() args = self.Args() args.image = image args.pulp = pulp args.satellite = satellite args.verify_ssl = verify_ssl args.insecure = insecure args.anonymous = anonymous args.url = None if not url else url args.username = None if not username else username args.password = None if not password else password args.activation_key = activation_key args.repo_id = repo_id registry = Decompose(image).registry if registry not in self.atomic.load_local_tokens( ) and not args.username or not args.password: raise dbus.DBusException( "There is no local token and no username/password were provided. Please try " "again with a username and password") if args.satellite or args.pulp: if not args.username or args.password: raise dbus.DBusException( "No username or password was provided for satellite or pulp. Please try " "again with a username and password") if not args.url: raise dbus.DBusException( "No URL was provided for satellite or pulp. Please try again " "with a defined URL.") if not registry_type: args.reg_type = 'docker' else: args.reg_type = registry_type if args.reg_type not in REGISTRY_TYPE_CHOICES: raise dbus.DBusException( "Registry type must be one of '{}'.".format( REGISTRY_TYPE_CHOICES)) args.sign_by = None if not sign_by else sign_by args.gnupghome = None if not gnupghome else gnupghome p.set_args(args) try: return p.push() except Exception as e: raise dbus.DBusException(str(e))
def propagate(_img): if self.remote: self.registry, self.repo, self.image, self.tag, self.digest = Decompose( _img).all