本文整理汇总了Python中util.getDockerClient函数的典型用法代码示例。如果您正苦于以下问题:Python getDockerClient函数的具体用法?Python getDockerClient怎么用?Python getDockerClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getDockerClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, manager, component, link_config):
# The component that exports the link.
self.component = component
# The configuration for the component link.
self.link_config = link_config
# The kind of the link.
self.kind = 'http' if link_config.kind.lower() == 'http' else 'tcp'
# The port of the link inside the running container.
self.container_port = link_config.port
# The address of the link under the proxy (None if the link is not running).
self.address = None
# The port of the link under the proxy (None if the link is not running).
self.exposed_port = None
# Whether the link is currently running.
self.running = False
# Lookup the runtime information for the link.
client = getDockerClient()
container = component.getPrimaryContainer()
if container:
container_ip = containerutil.getContainerIPAddress(client, container)
self.address = client.inspect_container(container)['NetworkSettings']['Gateway'] # The host's IP address.
self.exposed_port = link_config.getHostPort()
self.running = True
示例2: update
def update(self):
""" Updates a running instance of the component. Returns True on success and False
otherwise.
"""
self.logger.debug('Updating component %s', self.getName())
client = getDockerClient()
# Get the list of currently running container(s).
existing_containers = self.getAllContainers(client)
existing_primary = self.getPrimaryContainer()
# Start the new instance.
container = self.start()
if not container:
return False
# Mark all the existing containers as draining.
for existing in existing_containers:
setContainerStatus(existing, 'draining')
# Update the port proxy to redirect the external ports to the new
# container.
report('Redirecting traffic to new container', component=self)
self.manager.adjustForUpdatingComponent(self, container)
# Signal the existing primary container to terminate
if existing_primary is not None:
self.manager.terminateContainer(existing_primary, self)
return True
示例3: update
def update(self):
""" Updates a running instance of the component. Returns True on success and False
otherwise.
"""
self.logger.debug("Updating component %s", self.getName())
client = getDockerClient()
# Get the list of currently running container(s).
existing_containers = self.getAllContainers(client)
existing_primary = self.getPrimaryContainer()
# Start the new instance.
container = self.start()
if not container:
return False
# Mark all the existing containers as draining.
for existing in existing_containers:
setContainerStatus(existing, "draining")
# Signal the existing primary container to terminate
self.elb_manager.deregisterContainer()
if existing_primary is not None:
self.manager.terminateContainer(existing_primary, self)
return True
示例4: updateProxy
def updateProxy(self):
""" Updates the proxy used for port mapping to conform to the current running container
list.
"""
client = getDockerClient()
# Clear all routes in the proxy.
# TODO: When this is in daemon mode, don't need do this. We could selectively
# edit it instead.
self.proxy.clear_routes()
# Add routes for the non-draining containers and collect the draining containers to
# watch.
report('Finding running containers...', level = ReportLevels.EXTRA)
draining_containers = []
starting_containers = []
for component in self.components.values():
for container in component.getAllContainers(client):
if getContainerStatus(container) != 'draining':
starting_containers.append(container)
for mapping in component.config.ports:
local_port = containerutil.getLocalPort(client, container, mapping.container)
route = Route(mapping.kind == 'http', mapping.external, 'localhost', local_port)
self.proxy.add_route(route)
else:
draining_containers.append(container)
# Commit the changes to the proxy.
if draining_containers or starting_containers:
report('Updating proxy...', level = ReportLevels.EXTRA)
self.proxy.commit()
else:
report('Shutting down proxy...', level = ReportLevels.EXTRA)
self.proxy.shutdown()
# Mark the starting containers as running.
for container in starting_containers:
setContainerStatus(container, 'running')
if draining_containers:
report('Starting monitoring...', level = ReportLevels.EXTRA)
# If there are any draining containers, add them to the watcher thread.
with self.watcher_lock:
self.containers_watched.extend(draining_containers)
# Call the event to wakeup the watcher thread.
if draining_containers:
self.watcher_event.set()
# If in local mode, then wait until all the containers have drained. This
# prevents the python debugger from shutting down, since the other threads
# are all daemon threads.
if not self.daemon_mode and draining_containers:
while True:
self.watcher_thread.join(10)
if not self.watcher_thread.isAlive():
break
示例5: isRunning
def isRunning(self):
""" Returns whether this component has at least one running container. Note that
this will return True for ALL possible containers of the component, including
deprecated ones.
"""
self.logger.debug('Checking if component %s is running', self.getName())
client = getDockerClient()
return len(self.getAllContainers(client)) > 0
示例6: pullRepo
def pullRepo(self):
""" Attempts to pull the repo for this component. On failure, returns False. """
try:
self.logger.debug('Attempting to pull repo for component %s: %s:%s', self.getName(), self.config.repo, self.config.tag)
client = getDockerClient()
client.pull(self.config.repo, tag = self.config.tag)
except Exception as e:
self.logger.exception(e)
return False
示例7: getLocalPort
def getLocalPort(self, container, container_port):
""" Returns the port on the local system for the given container port or 0 if none. """
client = getDockerClient()
try:
self.logger.debug('Looking up port %d for container %s', container_port, container)
return client.port(container, container_port)
except Exception as e:
self.logger.exception(e)
return 0
示例8: getContainerInformation
def getContainerInformation(self):
""" Returns the container status information for all containers. """
client = getDockerClient()
information = []
for container in self.getAllContainers(client):
information.append((container, getContainerStatus(container)))
return information
示例9: getImageId
def getImageId(self):
""" Returns the docker ID of the image used for this component. Note that this
will *not* return the *named* image, but rather the full UUID-like ID.
"""
client = getDockerClient()
named_image = self.config.getFullImage()
self.logger.debug('Finding image ID for component %s with named image %s', self.getName(), named_image)
result = client.inspect_image(named_image)
return result['Id']
示例10: getPrimaryContainer
def getPrimaryContainer(self):
""" Returns the container for this component that is not marked as draining or None if
none.
"""
client = getDockerClient()
for container in self.getAllContainers(client):
if getContainerStatus(container) != 'draining':
return container
return None
示例11: getPrimaryContainerImageId
def getPrimaryContainerImageId(self):
""" Returns the image id of the primary container for this component or None if none.
"""
container = self.getPrimaryContainer()
if container is None:
return None
client = getDockerClient()
return client.inspect_container(container)['Image']
示例12: getImageId
def getImageId(self):
""" Returns the docker ID of the image used for this component. Note that this
will *not* return the *named* image, but rather the full UUID-like ID.
"""
client = getDockerClient()
named_image = self.config.getFullImage()
self.logger.debug("Finding image ID for component %s with named image %s", self.getName(), named_image)
# ensure the image is available before inspection.
self.ensureImage(client)
result = client.inspect_image(named_image)
return result["Id"]
示例13: run
def run(self, container, report):
report('ExecTerminationSignal in container %s: %s' % (container['Id'][0:12], self.config.exec_command),
level=ReportLevels.EXTRA)
try:
client = getDockerClient()
response = client.exec_create(container, self.config.exec_command)
client.exec_start(response['Id'])
except Exception as exc:
self.logger.exception(exc)
return False
return True
示例14: getCommand
def getCommand(self):
""" Returns the command to run or None if none found. """
config_command = self.config.getCommand()
if config_command:
return config_command
client = getDockerClient()
named_image = self.config.getFullImage()
result = client.inspect_image(named_image)
container_cfg = result['Config']
if not 'Cmd' in container_cfg:
return None
return ' '.join(container_cfg['Cmd'])
示例15: pullRepo
def pullRepo(self):
""" Attempts to pull the repo for this component. On failure, returns False. """
try:
self.logger.debug(
"Attempting to pull repo for component %s: %s:%s", self.getName(), self.config.repo, self.config.tag
)
client = getDockerClient()
# put in the stream output to block the pull process
for line in client.pull(self.config.repo, tag=self.config.tag, stream=True):
self.logger.debug(json.dumps(json.loads(line), indent=4))
# client.pull(self.config.repo, tag=self.config.tag)
return True
except Exception as e:
self.logger.exception(e)
return False