def printout(self, stream, context): obj = Container() if self.show_stream: obj.stream_position = stream.tell() follows = stream.read(self.stream_lookahead) if not follows: obj.following_stream_data = "EOF reached" else: stream.seek(-len(follows), 1) obj.following_stream_data = HexString(follows) print if self.show_context: obj.context = context if self.show_stack: obj.stack = ListContainer() frames = [s[0] for s in inspect.stack()][1:-1] frames.reverse() for f in frames: a = Container() a.__update__(f.f_locals) obj.stack.append(a) print "=" * 80 print "Probe", self.printname print obj print "=" * 80
def _parse(self, stream, context): if "<obj>" in context: obj = context["<obj>"] del context["<obj>"] else: obj = Container() if self.nested: context = Container(_=context) for sc in self.subcons: if sc.conflags & self.FLAG_EMBED: context["<obj>"] = obj sc._parse(stream, context) else: subobj = sc._parse(stream, context) if sc.name is not None: obj[sc.name] = subobj context[sc.name] = subobj return obj
def parse_stream(self, stream): """ Parse a stream. Files, pipes, sockets, and other streaming sources of data are handled by this method. """ return self._parse(stream, Container())
def _build(self, obj, stream, context): if "<unnested>" in context: del context["<unnested>"] elif self.nested: context = Container(_=context) for sc in self.subcons: if sc.conflags & self.FLAG_EMBED: context["<unnested>"] = True subobj = obj elif sc.name is None: subobj = None else: subobj = getattr(obj, sc.name) context[sc.name] = subobj sc._build(subobj, stream, context)
def sizeof(self, context=None): """ Calculate the size of this object, optionally using a context. Some constructs have no fixed size and can only know their size for a given hunk of data; these constructs will raise an error if they are not passed a context. :param ``Container`` context: contextual data :returns: int of the length of this construct :raises SizeofError: the size could not be determined """ if context is None: context = Container() try: return self._sizeof(context) except Exception, e: raise SizeofError(e)
def test_containerIsOutOfSync_hosts(self): container_def = ContainerDefinition.parseFile(os.path.join(self.EXAMPLE_DIR, "00-hosts.yaml")) ## blalor/docker-hosts:latest img_info = Image.fromJson({ "Size": 0, "Os": "linux", "Architecture": "amd64", "Id": "98e7ca605530c6ee637e175f08e692149a4d019b384e421e661bd35601b25975", "Parent": "15e3a43eb69d67df5a6ae1f3b3e87407f3b82157bf54fe8a5dc997cf2ce6528a", "Created": "2014-07-30T01:02:04.516066768Z", "Container": "5d7384258a7ac29d8eabe30b6b1d83dfe4a8925440f33982b439731906a087f2", "Docker_version": "1.1.1", "Author": "Brian Lalor <*****@*****.**>", "Config": { "OnBuild": [], "NetworkDisabled": False, "Entrypoint": [ "/usr/local/bin/docker-hosts" ], "WorkingDir": "", "Volumes": None, "Image": "15e3a43eb69d67df5a6ae1f3b3e87407f3b82157bf54fe8a5dc997cf2ce6528a", "Cmd": None, "AttachStdin": False, "Cpuset": "", "CpuShares": 0, "MemorySwap": 0, "Memory": 0, "User": "", "Domainname": "", "Hostname": "5ca9d941ba62", "AttachStdout": False, "AttachStderr": False, "PortSpecs": None, "ExposedPorts": None, "Tty": False, "OpenStdin": False, "StdinOnce": False, "Env": [ "HOME=/", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ] } }) container_info = Container.fromJson("hosts", { "HostConfig": { "NetworkMode": "", "VolumesFrom": None, "DnsSearch": None, "Binds": [ "/var/run/docker.sock:/var/run/docker.sock:rw", "/var/lib/docker/hosts:/srv/hosts:rw" ], "ContainerIDFile": "", "LxcConf": None, "Privileged": False, "PortBindings": None, "Links": None, "PublishAllPorts": False, "Dns": None }, "VolumesRW": { "/var/run/docker.sock": True, "/srv/hosts": True }, "Volumes": { "/var/run/docker.sock": "/var/run/docker.sock", "/srv/hosts": "/var/lib/docker/hosts" }, "NetworkSettings": { "Ports": {}, "PortMapping": None, "Bridge": "docker0", "Gateway": "172.17.42.1", "IPPrefixLen": 16, "IPAddress": "172.17.0.17" }, "Image": "98e7ca605530c6ee637e175f08e692149a4d019b384e421e661bd35601b25975", "State": { "FinishedAt": "0001-01-01T00:00:00Z", "StartedAt": "2014-10-28T18:22:51.492441086Z", "ExitCode": 0, "Pid": 27669, "Paused": False, "Running": True }, "Config": { "OnBuild": None, "NetworkDisabled": False, "Entrypoint": [ "/usr/local/bin/docker-hosts" ], "WorkingDir": "", "Volumes": { "/var/run/docker.sock": {}, "/srv/hosts": {} }, "Image": "blalor/docker-hosts:latest", "Cmd": [ "--domain-name=dev.docker", "/srv/hosts" ], "AttachStdin": False, "Cpuset": "", "CpuShares": 0, "MemorySwap": 0, "Memory": 0, "User": "", "Domainname": "", "Hostname": "04bf6ca07d2c", "AttachStdout": False, "AttachStderr": False, "PortSpecs": None, "ExposedPorts": None, "Tty": False, "OpenStdin": False, "StdinOnce": False, "Env": [ "HOME=/", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ] }, "Args": [ "--domain-name=dev.docker", "/srv/hosts" ], "Path": "/usr/local/bin/docker-hosts", "Created": "2014-10-28T18:22:51.142918682Z", "Id": "04bf6ca07d2c610235f57b041e224c19b6fab51d400a599ee0f1b1c53e12201f", "ResolvConfPath": "/etc/resolv.conf", "HostnamePath": "/var/lib/docker/containers/04bf6ca07d2c610235f57b041e224c19b6fab51d400a599ee0f1b1c53e12201f/hostname", "HostsPath": "/var/lib/docker/containers/04bf6ca07d2c610235f57b041e224c19b6fab51d400a599ee0f1b1c53e12201f/hosts", "Name": "/hosts", "Driver": "devicemapper", "ExecDriver": "native-0.2", "MountLabel": "", "ProcessLabel": "" }) eq_(Manager.containerIsOutOfSync(container_def, container_info, img_info), False)
def test_containerIsOutOfSync(self): container_def = ContainerDefinition.parseFile(os.path.join(self.EXAMPLE_DIR, "00-private-registry.yaml")) img_info = Image.fromJson({ "Id": "2e2d7133e4a578bd861e85e7195412201f765d050af78c7906841ea62eb6f7dd", "Parent": "c79dab5561020bda9ce1b1cbe76283fc95f824cfb26a8a21a384993ed7f392bd", "Created": "2014-10-21T08:50:44.448455269Z", "Container": "b756100785c797b9f43d36f249b0d5688d88a1ca68df56d915cb436c4bfc7286", "Config": { "OnBuild": [], "NetworkDisabled": False, "Entrypoint": None, "WorkingDir": "", "Volumes": None, "Image": "c79dab5561020bda9ce1b1cbe76283fc95f824cfb26a8a21a384993ed7f392bd", "Cmd": [ "/bin/sh", "-c", "exec docker-registry" ], "AttachStdin": False, "Cpuset": "", "CpuShares": 0, "MemorySwap": 0, "Memory": 0, "User": "", "Domainname": "", "Hostname": "965c252e48c3", "AttachStdout": False, "AttachStderr": False, "PortSpecs": None, "ExposedPorts": { "5000/tcp": {} }, "Tty": False, "OpenStdin": False, "StdinOnce": False, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "DOCKER_REGISTRY_CONFIG=/docker-registry/config/config_sample.yml", "SETTINGS_FLAVOR=dev" ] }, }) container_info = Container.fromJson("private-registry", { "HostConfig": { "NetworkMode": "", "VolumesFrom": None, "DnsSearch": None, "Binds": [ "/tmp:/var/lib/docker/registry", ], "ContainerIDFile": "", "LxcConf": None, "Privileged": False, "PortBindings": { "5000/tcp": [ { "HostPort": "11003", "HostIp": "0.0.0.0" } ] }, "Links": None, "PublishAllPorts": False, "Dns": None }, "VolumesRW": { "/var/lib/docker/registry": True, }, "Volumes": { "/var/lib/docker/registry": "/tmp", }, "NetworkSettings": { "Ports": { "5000/tcp": [ { "HostPort": "11003", "HostIp": "0.0.0.0" } ] }, "PortMapping": None, "Bridge": "docker0", "Gateway": "172.17.42.1", "IPPrefixLen": 16, "IPAddress": "172.17.0.31" }, "Image": "2e2d7133e4a578bd861e85e7195412201f765d050af78c7906841ea62eb6f7dd", "State": { "FinishedAt": "0001-01-01T00:00:00Z", "StartedAt": "2014-10-28T16:38:31.491949274Z", "ExitCode": 0, "Pid": 18785, "Paused": False, "Running": True }, "Config": { "OnBuild": None, "NetworkDisabled": False, "Entrypoint": None, "WorkingDir": "", "Volumes": { "/var/lib/docker/registry": {}, }, "Image": "registry:0.8.1", "Cmd": [ "/bin/sh", "-c", "exec docker-registry" ], "AttachStdin": False, "Cpuset": "", "CpuShares": 0, "MemorySwap": 0, "Memory": 0, "User": "", "Domainname": "", "Hostname": "private-registry", "AttachStdout": False, "AttachStderr": False, "PortSpecs": None, "ExposedPorts": { "5000/tcp": {} }, "Tty": False, "OpenStdin": False, "StdinOnce": False, "Env": [ "SETTINGS_FLAVOR=local", "STORAGE_PATH=/var/lib/docker/registry", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "DOCKER_REGISTRY_CONFIG=/docker-registry/config/config_sample.yml" ] }, "Args": [ "-c", "exec docker-registry" ], "Path": "/bin/sh", "Created": "2014-10-28T16:38:31.20825271Z", "Id": "758a155a0374fa7e163e4fc71e96cd1bd7de37674dd5f552b9183789366e91f7", "ResolvConfPath": "/etc/resolv.conf", "HostnamePath": "/var/lib/docker/containers/758a155a0374fa7e163e4fc71e96cd1bd7de37674dd5f552b9183789366e91f7/hostname", "HostsPath": "/var/lib/docker/containers/758a155a0374fa7e163e4fc71e96cd1bd7de37674dd5f552b9183789366e91f7/hosts", "Name": "/private-registry", "Driver": "devicemapper", "ExecDriver": "native-0.2", "MountLabel": "", "ProcessLabel": "" }) eq_(Manager.containerIsOutOfSync(container_def, container_info, img_info), False)
def set_pairs(self, keywords): for operon in self: pairs = Container() operon.pairs = pairs for k in keywords: setattr(operon.pairs, k, {})
def test_containerIsOutOfSync_hosts(self): container_def = ContainerDefinition.parseFile( os.path.join(self.EXAMPLE_DIR, "00-hosts.yaml")) ## blalor/docker-hosts:latest img_info = Image.fromJson({ "Size": 0, "Os": "linux", "Architecture": "amd64", "Id": "98e7ca605530c6ee637e175f08e692149a4d019b384e421e661bd35601b25975", "Parent": "15e3a43eb69d67df5a6ae1f3b3e87407f3b82157bf54fe8a5dc997cf2ce6528a", "Created": "2014-07-30T01:02:04.516066768Z", "Container": "5d7384258a7ac29d8eabe30b6b1d83dfe4a8925440f33982b439731906a087f2", "Docker_version": "1.1.1", "Author": "Brian Lalor <*****@*****.**>", "Config": { "OnBuild": [], "NetworkDisabled": False, "Entrypoint": ["/usr/local/bin/docker-hosts"], "WorkingDir": "", "Volumes": None, "Image": "15e3a43eb69d67df5a6ae1f3b3e87407f3b82157bf54fe8a5dc997cf2ce6528a", "Cmd": None, "AttachStdin": False, "Cpuset": "", "CpuShares": 0, "MemorySwap": 0, "Memory": 0, "User": "", "Domainname": "", "Hostname": "5ca9d941ba62", "AttachStdout": False, "AttachStderr": False, "PortSpecs": None, "ExposedPorts": None, "Tty": False, "OpenStdin": False, "StdinOnce": False, "Env": [ "HOME=/", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ] } }) container_info = Container.fromJson( "hosts", { "HostConfig": { "NetworkMode": "", "VolumesFrom": None, "DnsSearch": None, "Binds": [ "/var/run/docker.sock:/var/run/docker.sock:rw", "/var/lib/docker/hosts:/srv/hosts:rw" ], "ContainerIDFile": "", "LxcConf": None, "Privileged": False, "PortBindings": None, "Links": None, "PublishAllPorts": False, "Dns": None }, "VolumesRW": { "/var/run/docker.sock": True, "/srv/hosts": True }, "Volumes": { "/var/run/docker.sock": "/var/run/docker.sock", "/srv/hosts": "/var/lib/docker/hosts" }, "NetworkSettings": { "Ports": {}, "PortMapping": None, "Bridge": "docker0", "Gateway": "172.17.42.1", "IPPrefixLen": 16, "IPAddress": "172.17.0.17" }, "Image": "98e7ca605530c6ee637e175f08e692149a4d019b384e421e661bd35601b25975", "State": { "FinishedAt": "0001-01-01T00:00:00Z", "StartedAt": "2014-10-28T18:22:51.492441086Z", "ExitCode": 0, "Pid": 27669, "Paused": False, "Running": True }, "Config": { "OnBuild": None, "NetworkDisabled": False, "Entrypoint": ["/usr/local/bin/docker-hosts"], "WorkingDir": "", "Volumes": { "/var/run/docker.sock": {}, "/srv/hosts": {} }, "Image": "blalor/docker-hosts:latest", "Cmd": ["--domain-name=dev.docker", "/srv/hosts"], "AttachStdin": False, "Cpuset": "", "CpuShares": 0, "MemorySwap": 0, "Memory": 0, "User": "", "Domainname": "", "Hostname": "04bf6ca07d2c", "AttachStdout": False, "AttachStderr": False, "PortSpecs": None, "ExposedPorts": None, "Tty": False, "OpenStdin": False, "StdinOnce": False, "Env": [ "HOME=/", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ] }, "Args": ["--domain-name=dev.docker", "/srv/hosts"], "Path": "/usr/local/bin/docker-hosts", "Created": "2014-10-28T18:22:51.142918682Z", "Id": "04bf6ca07d2c610235f57b041e224c19b6fab51d400a599ee0f1b1c53e12201f", "ResolvConfPath": "/etc/resolv.conf", "HostnamePath": "/var/lib/docker/containers/04bf6ca07d2c610235f57b041e224c19b6fab51d400a599ee0f1b1c53e12201f/hostname", "HostsPath": "/var/lib/docker/containers/04bf6ca07d2c610235f57b041e224c19b6fab51d400a599ee0f1b1c53e12201f/hosts", "Name": "/hosts", "Driver": "devicemapper", "ExecDriver": "native-0.2", "MountLabel": "", "ProcessLabel": "" }) eq_( Manager.containerIsOutOfSync(container_def, container_info, img_info), False)
def test_containerIsOutOfSync(self): container_def = ContainerDefinition.parseFile( os.path.join(self.EXAMPLE_DIR, "00-private-registry.yaml")) img_info = Image.fromJson({ "Id": "2e2d7133e4a578bd861e85e7195412201f765d050af78c7906841ea62eb6f7dd", "Parent": "c79dab5561020bda9ce1b1cbe76283fc95f824cfb26a8a21a384993ed7f392bd", "Created": "2014-10-21T08:50:44.448455269Z", "Container": "b756100785c797b9f43d36f249b0d5688d88a1ca68df56d915cb436c4bfc7286", "Config": { "OnBuild": [], "NetworkDisabled": False, "Entrypoint": None, "WorkingDir": "", "Volumes": None, "Image": "c79dab5561020bda9ce1b1cbe76283fc95f824cfb26a8a21a384993ed7f392bd", "Cmd": ["/bin/sh", "-c", "exec docker-registry"], "AttachStdin": False, "Cpuset": "", "CpuShares": 0, "MemorySwap": 0, "Memory": 0, "User": "", "Domainname": "", "Hostname": "965c252e48c3", "AttachStdout": False, "AttachStderr": False, "PortSpecs": None, "ExposedPorts": { "5000/tcp": {} }, "Tty": False, "OpenStdin": False, "StdinOnce": False, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "DOCKER_REGISTRY_CONFIG=/docker-registry/config/config_sample.yml", "SETTINGS_FLAVOR=dev" ] }, }) container_info = Container.fromJson( "private-registry", { "HostConfig": { "NetworkMode": "", "VolumesFrom": None, "DnsSearch": None, "Binds": [ "/tmp:/var/lib/docker/registry", ], "ContainerIDFile": "", "LxcConf": None, "Privileged": False, "PortBindings": { "5000/tcp": [{ "HostPort": "11003", "HostIp": "0.0.0.0" }] }, "Links": None, "PublishAllPorts": False, "Dns": None }, "VolumesRW": { "/var/lib/docker/registry": True, }, "Volumes": { "/var/lib/docker/registry": "/tmp", }, "NetworkSettings": { "Ports": { "5000/tcp": [{ "HostPort": "11003", "HostIp": "0.0.0.0" }] }, "PortMapping": None, "Bridge": "docker0", "Gateway": "172.17.42.1", "IPPrefixLen": 16, "IPAddress": "172.17.0.31" }, "Image": "2e2d7133e4a578bd861e85e7195412201f765d050af78c7906841ea62eb6f7dd", "State": { "FinishedAt": "0001-01-01T00:00:00Z", "StartedAt": "2014-10-28T16:38:31.491949274Z", "ExitCode": 0, "Pid": 18785, "Paused": False, "Running": True }, "Config": { "OnBuild": None, "NetworkDisabled": False, "Entrypoint": None, "WorkingDir": "", "Volumes": { "/var/lib/docker/registry": {}, }, "Image": "registry:0.8.1", "Cmd": ["/bin/sh", "-c", "exec docker-registry"], "AttachStdin": False, "Cpuset": "", "CpuShares": 0, "MemorySwap": 0, "Memory": 0, "User": "", "Domainname": "", "Hostname": "private-registry", "AttachStdout": False, "AttachStderr": False, "PortSpecs": None, "ExposedPorts": { "5000/tcp": {} }, "Tty": False, "OpenStdin": False, "StdinOnce": False, "Env": [ "SETTINGS_FLAVOR=local", "STORAGE_PATH=/var/lib/docker/registry", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "DOCKER_REGISTRY_CONFIG=/docker-registry/config/config_sample.yml" ] }, "Args": ["-c", "exec docker-registry"], "Path": "/bin/sh", "Created": "2014-10-28T16:38:31.20825271Z", "Id": "758a155a0374fa7e163e4fc71e96cd1bd7de37674dd5f552b9183789366e91f7", "ResolvConfPath": "/etc/resolv.conf", "HostnamePath": "/var/lib/docker/containers/758a155a0374fa7e163e4fc71e96cd1bd7de37674dd5f552b9183789366e91f7/hostname", "HostsPath": "/var/lib/docker/containers/758a155a0374fa7e163e4fc71e96cd1bd7de37674dd5f552b9183789366e91f7/hosts", "Name": "/private-registry", "Driver": "devicemapper", "ExecDriver": "native-0.2", "MountLabel": "", "ProcessLabel": "" }) eq_( Manager.containerIsOutOfSync(container_def, container_info, img_info), False)
def _sizeof(self, context): if self.nested: context = Container(_=context) return sum(sc._sizeof(context) for sc in self.subcons)
def build_stream(self, obj, stream): """ Build an object directly into a stream. """ self._build(obj, stream, Container())