• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.get_short_id函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shipyard.utils.get_short_id函数的典型用法代码示例。如果您正苦于以下问题:Python get_short_id函数的具体用法?Python get_short_id怎么用?Python get_short_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_short_id函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_containers

 def get_containers(self, show_all=False):
     c = client.Client(base_url='http://{0}:{1}'.format(self.hostname,
         self.port))
     key = self._generate_container_cache_key(show_all)
     containers = cache.get(key)
     container_ids = []
     if containers is None:
         try:
             containers = c.containers(all=show_all)
         except requests.ConnectionError:
             containers = []
         # update meta data
         for x in containers:
             # only get first 12 chars of id (for metatdata)
             c_id = utils.get_short_id(x.get('Id'))
             # ignore stopped containers
             meta = c.inspect_container(c_id)
             m, created = Container.objects.get_or_create(
                 container_id=c_id, host=self)
             m.is_running = meta.get('State', {}).get('Running', False)
             m.meta = json.dumps(meta)
             m.save()
             container_ids.append(c_id)
         # set extra containers to not running
         Container.objects.filter(host=self).exclude(
             container_id__in=container_ids).update(is_running=False)
         cache.set(key, containers, HOST_CACHE_TTL)
     return containers
开发者ID:valberg,项目名称:shipyard,代码行数:28,代码来源:models.py


示例2: get_containers

    def get_containers(self, show_all=False):
	c = self._get_client()
        key = self._generate_container_cache_key(show_all)
        containers = cache.get(key)
        container_ids = []
        if containers is None:
            try:
                containers = c.containers(all=show_all)
            except requests.ConnectionError:
                containers = []
            # update meta data
            for x in containers:
                # only get first 12 chars of id (for metatdata)
                c_id = utils.get_short_id(x.get('Id'))
                # ignore stopped containers
                meta = c.inspect_container(c_id)
                m, created = Container.objects.get_or_create(
                    container_id=c_id, host=self)
		from pprint import pprint
		pprint(json.dumps(meta))
                m.meta = json.dumps(meta)
                m.save()
                container_ids.append(c_id)
            cache.set(key, containers, HOST_CACHE_TTL)
        return containers
开发者ID:newrelic,项目名称:shipyard,代码行数:25,代码来源:models.py


示例3: destroy_container

 def destroy_container(self, container_id=None):
     c = self._get_client()
     c_id = utils.get_short_id(container_id)
     c.kill(c_id)
     c.remove_container(c_id)
     # remove metadata
     Container.objects.filter(container_id=c_id).delete()
     self._invalidate_container_cache()
开发者ID:valberg,项目名称:shipyard,代码行数:8,代码来源:models.py


示例4: stop_container

 def stop_container(self, container_id=None):
     c_id = utils.get_short_id(container_id)
     c = Container.objects.get(container_id=c_id)
     if c.protected:
         raise ProtectedContainerError(
             _('Unable to stop container.  Container is protected.'))
     c = self._get_client()
     c.stop(c_id)
     self._invalidate_container_cache()
开发者ID:errazudin,项目名称:shipyard,代码行数:9,代码来源:models.py


示例5: handle

 def handle(self, *args, **options):
     hosts = Host.objects.filter(enabled=True)
     all_containers = [x.container_id for x in Container.objects.all()]
     for host in hosts:
         host_containers = [utils.get_short_id(c.get('Id')) \
             for c in host.get_containers(show_all=True)]
         for c in all_containers:
             if c not in host_containers:
                 print('Removing {}'.format(c))
                 Container.objects.get(container_id=c).delete()
开发者ID:valberg,项目名称:shipyard,代码行数:10,代码来源:purge_containers.py


示例6: attach_container

def attach_container(request, host, container_id):
    h = Host.objects.get(name=host)
    c_id = utils.get_short_id(container_id)
    c = Container.objects.get(container_id=c_id)
    ctx = {
        'container_id': c_id,
        'container_name': c.description or c_id,
        'host_url': '{0}:{1}'.format(h.hostname, h.port),
    }
    return render_to_response("containers/attach.html", ctx,
        context_instance=RequestContext(request))
开发者ID:ikebrown,项目名称:shipyard,代码行数:11,代码来源:views.py


示例7: destroy_container

 def destroy_container(self, container_id=None):
     c_id = utils.get_short_id(container_id)
     c = Container.objects.get(container_id=c_id)
     if c.protected:
         raise ProtectedContainerError(
             _('Unable to destroy container.  Container is protected.'))
     c = self._get_client()
     c.kill(c_id)
     c.remove_container(c_id)
     # remove metadata
     Container.objects.filter(container_id=c_id).delete()
     self._invalidate_container_cache()
开发者ID:ikebrown,项目名称:shipyard,代码行数:12,代码来源:models.py


示例8: attach_container

def attach_container(request, host, container_id):
    h = Host.objects.get(name=host)
    c_id = utils.get_short_id(container_id)
    c = Container.objects.get(container_id=c_id)
    session_id = utils.generate_console_session(h, c)
    ctx = {
        'container_id': c_id,
        'container_name': c.description or c_id,
        'ws_url': 'ws://{0}/console/{1}/'.format(request.META['HTTP_HOST'], session_id),
    }
    return render_to_response("containers/attach.html", ctx,
        context_instance=RequestContext(request))
开发者ID:abathingchris,项目名称:shipyard,代码行数:12,代码来源:views.py


示例9: get_all_containers

 def get_all_containers(cls, show_all=False, owner=None):
     hosts = Host.objects.filter(enabled=True)
     containers = []
     # load containers
     if hosts:
         c_ids = []
         for h in hosts:
             for c in h.get_containers(show_all=show_all):
                 c_ids.append(utils.get_short_id(c.get('Id')))
         # return metadata objects
         containers = Container.objects.filter(container_id__in=c_ids).filter(
             Q(owner=None) | Q(owner=owner))
     return containers
开发者ID:errazudin,项目名称:shipyard,代码行数:13,代码来源:models.py


示例10: restart_container

 def restart_container(self, container_id=None):
     from applications.models import Application
     c = self._get_client()
     c.restart(container_id)
     self._invalidate_container_cache()
     # reload containers to get proper port
     self.get_containers()
     # update hipache
     container = Container.objects.get(
         container_id=utils.get_short_id(container_id))
     apps = Application.objects.filter(containers__in=[container])
     for app in apps:
         app.update_config()
开发者ID:errazudin,项目名称:shipyard,代码行数:13,代码来源:models.py


示例11: get_running

 def get_running(cls, user=None):
     hosts = Host.objects.filter(enabled=True)
     containers = []
     if hosts:
         c_ids = []
         for h in hosts:
             for c in h.get_containers():
                 c_ids.append(utils.get_short_id(c.get('Id')))
         # return metadata objects
         containers = Container.objects.filter(container_id__in=c_ids).filter(
             Q(owner=None))
         if user:
             containers = containers.filter(Q(owner=request.user))
     return containers
开发者ID:errazudin,项目名称:shipyard,代码行数:14,代码来源:models.py


示例12: _host_info

def _host_info(request):
    hosts = Host.objects.filter(enabled=True)
    # load containers
    cnt = [h.get_containers() for h in hosts][0]
    # get list of ids to filter Container metadata
    c_ids = [utils.get_short_id(x.get('Id')) for x in cnt]
    # return metadata objects
    containers = Container.objects.filter(container_id__in=c_ids).filter(
        Q(owner=None) | Q(owner=request.user))
    ctx = {
        'hosts': hosts,
        'containers': containers,
    }
    return render_to_response('dashboard/_host_info.html', ctx,
        context_instance=RequestContext(request))
开发者ID:YanLinAung,项目名称:shipyard,代码行数:15,代码来源:views.py


示例13: destroy_container

 def destroy_container(self, container_id=None):
     c_id = utils.get_short_id(container_id)
     c = Container.objects.get(container_id=c_id)
     if c.protected:
         raise ProtectedContainerError(
             _('Unable to destroy container.  Container is protected.'))
     c = self._get_client()
     try:
         c.kill(c_id)
         c.remove_container(c_id)
     except client.APIError:
         # ignore 404s from api if container not found
         pass
     # remove metadata
     Container.objects.filter(container_id=c_id).delete()
     self._invalidate_container_cache()
开发者ID:errazudin,项目名称:shipyard,代码行数:16,代码来源:models.py


示例14: obj_create

    def obj_create(self, bundle, request=None, **kwargs):
        """
        Override obj_create to launch containers and return metadata

        """
        # HACK: get host id -- this should probably be some type of
        # reverse lookup from tastypie
        host_urls = bundle.data.get("hosts")
        # remove 'hosts' from data and pass rest to create_container
        del bundle.data["hosts"]
        # launch on hosts
        for host_url in host_urls:
            host_id = host_url.split("/")[-2]
            host = Host.objects.get(id=host_id)
            data = bundle.data
            c_id, status = host.create_container(**data)
            bundle.obj = Container.objects.get(container_id=utils.get_short_id(c_id))
        bundle = self.full_hydrate(bundle)
        return bundle
开发者ID:jeffbaier,项目名称:shipyard,代码行数:19,代码来源:api.py


示例15: index

def index(request):
    hosts = Host.objects.filter(enabled=True)
    show_all = True if request.GET.has_key('showall') else False
    containers = None
    # load containers
    if hosts:
        c_ids = []
        for h in hosts:
            for c in h.get_containers(show_all=show_all):
                c_ids.append(utils.get_short_id(c.get('Id')))
        # return metadata objects
        containers = Container.objects.filter(container_id__in=c_ids).filter(
            Q(owner=None) | Q(owner=request.user))
    ctx = {
        'hosts': hosts,
        'containers': containers,
        'show_all': show_all,
    }
    return render_to_response('containers/index.html', ctx,
        context_instance=RequestContext(request))
开发者ID:ikebrown,项目名称:shipyard,代码行数:20,代码来源:views.py


示例16: get_containers

 def get_containers(self, show_all=False):
     c = client.Client(base_url='http://{0}:{1}'.format(self.hostname,
         self.port))
     key = self._generate_container_cache_key(show_all)
     containers = cache.get(key)
     container_ids = []
     if containers is None:
         containers = c.containers(all=show_all)
         # update meta data
         for x in containers:
             # only get first 12 chars of id (for metatdata)
             c_id = utils.get_short_id(x.get('Id'))
             # ignore stopped containers
             meta = c.inspect_container(c_id)
             m, created = Container.objects.get_or_create(
                 container_id=c_id, host=self)
             m.meta = json.dumps(meta)
             m.save()
             container_ids.append(c_id)
         cache.set(key, containers, HOST_CACHE_TTL)
     return containers
开发者ID:oss17888,项目名称:shipyard,代码行数:21,代码来源:models.py


示例17: get_containers

 def get_containers(self, show_all=False):
     c = self._get_client()
     key = self._generate_container_cache_key(show_all)
     containers = cache.get(key)
     container_ids = []
     if containers is None:
         try:
             containers = c.containers(all=show_all)
         except requests.ConnectionError:
             containers = []
         # update meta data
         for x in containers:
             # only get first 12 chars of id (for metatdata)
             c_id = utils.get_short_id(x.get('Id'))
             # ignore stopped containers
             self._load_container_data(c_id)
             container_ids.append(c_id)
         # set extra containers to not running
         Container.objects.filter(host=self).exclude(
             container_id__in=container_ids).update(is_running=False)
         cache.set(key, containers, HOST_CACHE_TTL)
     return containers
开发者ID:errazudin,项目名称:shipyard,代码行数:22,代码来源:models.py


示例18: clone_container

 def clone_container(self, container_id=None):
     c_id = utils.get_short_id(container_id)
     c = Container.objects.get(container_id=c_id)
     meta = c.get_meta()
     cfg = meta.get('Config')
     image = cfg.get('Image')
     command = ' '.join(cfg.get('Cmd'))
     # update port spec to specify the original NAT'd port
     port_mapping = meta.get('NetworkSettings').get('PortMapping')
     port_specs = []
     if port_mapping:
         for x,y in port_mapping.items():
             for k,v in y.items():
                 port_specs.append('{}/{}'.format(k,x.lower()))
     env = cfg.get('Env')
     mem = cfg.get('Memory')
     description = c.description
     volumes = cfg.get('Volumes')
     volumes_from = cfg.get('VolumesFrom')
     privileged = cfg.get('Privileged')
     owner = c.owner
     c_id, status = self.create_container(image, command, port_specs,
         env, mem, description, volumes, volumes_from, privileged, owner)
     return c_id, status
开发者ID:errazudin,项目名称:shipyard,代码行数:24,代码来源:models.py



注:本文中的shipyard.utils.get_short_id函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python shlex._cmd_quote函数代码示例发布时间:2022-05-27
下一篇:
Python api.flags4appversions函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap