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


Python api.ChefAPI类代码示例

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


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

示例1: chef_roledefs

def chef_roledefs(api=None, hostname_attr = 'fqdn'):
    """Build a Fabric roledef dictionary from a Chef server.

    Example:

        from fabric.api import env, run, roles
        from chef.fabric import chef_roledefs

        env.roledefs = chef_roledefs()

        @roles('web_app')
        def mytask():
            run('uptime')
            
    hostname_attr is the attribute in the chef node that holds the real hostname.
    to refer to a nested attribute, separate the levels with '.'.
    for example 'ec2.public_hostname'
    """
    api = api or ChefAPI.get_global() or autoconfigure()
    if not api:
        raise ChefError('Unable to load Chef API configuration')
    roledefs = {}
    for row in Search('role', api=api):
        name = row['name']
        roledefs[name] =  Roledef(name, api, hostname_attr)
    return roledefs
开发者ID:doat,项目名称:pychef,代码行数:26,代码来源:fabric.py

示例2: create

 def create(cls, name, api=None, **kwargs):
     api = api or ChefAPI.get_global()
     obj = cls(name, api, skip_load=True)
     for key, value in kwargs.iteritems():
         setattr(obj, key, value)
     api.api_request('POST', cls.url, data=obj)
     return obj
开发者ID:SeanOC,项目名称:pychef,代码行数:7,代码来源:base.py

示例3: get_api

    def get_api(self, mess):
        """Check to see if the user has selected a knife.rb

        If there is only one, it will be selected automatically

        :param mess: Errbot message object
        """
        configs = self.get_config_files()
        if len(configs) == 1:
            # there is only one config, so auto-select it
            self.set_config(mess, list(configs)[0])

        if self.USER_CONF.get(mess.frm.person):
            self.send(
                mess.frm,
                "/me Chef knife.rb: {}".format(self.USER_CONF[mess.frm.person]["knife_file"]),
                message_type=mess.type,
            )
        else:
            raise Exception(
                'You have not selected a knife.rb. Run "chef '
                'config list" to see a list of available '
                'configs and then use "chef config set '
                '<name>" to select one'
            )

        return ChefAPI.from_config_file(self.USER_CONF[mess.frm.person]["knife_file"])
开发者ID:EFXCIA,项目名称:err-chef,代码行数:27,代码来源:chef.py

示例4: __init__

 def __init__(self, index, q='*:*', sort='X_CHEF_id_CHEF_X asc', rows=1000, start=0, api=None):
     self.name = index
     self.api = api or ChefAPI.get_global()
     if not (sort.endswith(' asc') or sort.endswith(' desc')):
         sort += ' asc'
     self._args = dict(q=q, sort=sort, rows=rows, start=start)
     self.url = self.__class__.url + '/' + self.name + '?' + urllib.urlencode(self._args)
开发者ID:SeanOC,项目名称:pychef,代码行数:7,代码来源:search.py

示例5: chef_environment

def chef_environment(name, api=None):
    """A Fabric task to set the current Chef environment context.

    This task works alongside :func:`~chef.fabric.chef_roledefs` to set the
    Chef environment to be used in future role queries.

    Example::

        from chef.fabric import chef_environment, chef_roledefs
        env.roledefs = chef_roledefs()

    .. code-block:: bash

        $ fab env:production deploy

    The task can be configured slightly via Fabric ``env`` values.

    ``env.chef_environment_task_alias`` sets the task alias, defaulting to "env".
    This value must be set **before** :mod:`chef.fabric` is imported.

    ``env.chef_environment_validate`` sets if :class:`~chef.Environment` names
    should be validated before use. Defaults to True.

    .. versionadded:: 0.2
    """
    if env.get('chef_environment_validate', True):
        api = api or ChefAPI.get_global() or autoconfigure()
        if not api:
            raise ChefError('Unable to load Chef API configuration')
        chef_env = Environment(name, api=api)
        if not chef_env.exists:
            raise ChefError('Unknown Chef environment: %s' % name)
    env['chef_environment'] = name
开发者ID:juliomistral,项目名称:pychef,代码行数:33,代码来源:fabric.py

示例6: create

 def create(cls, name, api=None, admin=False):
     api = api or ChefAPI.get_global()
     obj = cls(name, api, skip_load=True)
     obj.admin = admin
     d = api.api_request('POST', cls.url, data=obj)
     obj.private_key = d['private_key']
     return obj
开发者ID:AsherBond,项目名称:python-chef-buildpackage,代码行数:7,代码来源:client.py

示例7: list

 def list(cls, api=None):
     """Return a :class:`ChefQuery` with the available objects of this type.
     """
     api = api or ChefAPI.get_global()
     cls._check_api_version(api)
     names = [name for name, url in api[cls.url].iteritems()]
     return ChefQuery(cls, names, api)
开发者ID:rkourtz,项目名称:pychef,代码行数:7,代码来源:base.py

示例8: start

 def start(cls, command, nodes, run_timeout=300, api=None):
     data = {
         'command': command,
         'nodes': nodes,
         'run_timeout': run_timeout
     }
     api = api or ChefAPI.get_global()
     return api.api_request('POST', cls.url, data=data)
开发者ID:stephenbm,项目名称:pychef,代码行数:8,代码来源:pushy.py

示例9: save

 def save(self, api=None):
     api = api or ChefAPI.get_global()
     try:
         api.api_request('PUT', self.url, data=self)
     except ChefServerNotFoundError, e:
         # If you get a 404 during a save, just create it instead
         # This mirrors the logic in the Chef code
         api.api_request('POST', self.__class__.url, data=self)
开发者ID:SeanOC,项目名称:pychef,代码行数:8,代码来源:base.py

示例10: _user_api

 def _user_api(cls, api=None):
     api = api or ChefAPI.get_global()
     url = '/'.join(api.url.split('/')[:3])
     api_args = (url, api.key, api.client)
     api_kwargs = {
         'version': api.version,
         'headers': api.headers,
         'ssl_verify': api.ssl_verify
     }
     return ChefAPI(*api_args, **api_kwargs)
开发者ID:stephenbm,项目名称:pychef,代码行数:10,代码来源:user.py

示例11: create

 def create(cls, name, api=None, **kwargs):
     """Create a new object of this type. Pass the initial value for any
     attributes as keyword arguments.
     """
     api = api or ChefAPI.get_global()
     obj = cls(name, api, skip_load=True)
     for key, value in kwargs.iteritems():
         setattr(obj, key, value)
     api.api_request("POST", cls.url, data=obj)
     return obj
开发者ID:needle,项目名称:pychef,代码行数:10,代码来源:base.py

示例12: __init__

    def __init__(self, object_type, name, api, skip_load=False):
        self._check_object_type(object_type)

        self.object_type = object_type
        self.name = name
        self.url = "/%s/%s/_acl/" % (object_type, name)
        self.api = api or ChefAPI.get_global()

        self.attributes_map = {}
        for t in self.ace_types:
            self.attributes_map[t] = Permissions()

        if (not skip_load) and self.is_supported():
            self.reload()
开发者ID:AudaxHealthInc,项目名称:lambda-chef-node-cleanup,代码行数:14,代码来源:acl.py

示例13: create

 def create(cls, bag, name, api=None, **kwargs):
     """Create a new data bag item. Pass the initial value for any keys as
     keyword arguments."""
     api = api or ChefAPI.get_global()
     obj = cls(bag, name, api, skip_load=True)
     for key, value in kwargs.iteritems():
         obj[key] = value
     obj['id'] = name
     api.api_request('POST', cls.url+'/'+str(bag), data=obj.raw_data)
     if isinstance(bag, DataBag) and name not in bag.names:
         # Mutate the bag in-place if possible, so it will return the new
         # item instantly
         bag.names.append(name)
     return obj
开发者ID:ampledata,项目名称:pychef,代码行数:14,代码来源:data_bag.py

示例14: __init__

 def __init__(self, name, api=None, skip_load=False):
     self.name = name
     self.api = api or ChefAPI.get_global()
     self.url = self.__class__.url + "/" + self.name
     self.exists = False
     data = {}
     if not skip_load:
         try:
             data = self.api[self.url]
         except ChefServerNotFoundError:
             pass
         else:
             self.exists = True
     self._populate(data)
开发者ID:needle,项目名称:pychef,代码行数:14,代码来源:base.py

示例15: fetch

 def fetch(cls, node=None, start_time=None, end_time=None, status=None, rows=10, api=None):
     search = node and 'nodes/%s' % node or 'org'
     api = api or ChefAPI.get_global()
     full_url = '/reports/%s/runs?' % (search)
     if start_time:
         full_url = full_url + ('from=%s' % cls._unix_stamp(start_time))
         full_url = full_url + ('&until=%s' % cls._unix_stamp(
             end_time or (datetime.now() + timedelta(days=1))))
     if rows:
         full_url = full_url + ('&rows=%s' % rows)
     return api.api_request('GET',
         full_url,
         headers={'X-Ops-Reporting-Protocol-Version': '0.1.0'}
     )
开发者ID:stephenbm,项目名称:pychef,代码行数:14,代码来源:report.py


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