当前位置: 首页>>代码示例>>Python>>正文


Python utils.get_short_id函数代码示例

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


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


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