예제 #1
0
 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
예제 #2
0
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 scalarizr.externals.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
예제 #3
0
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 scalarizr.externals.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
예제 #4
0
 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
예제 #5
0
파일: base.py 프로젝트: golovast/scalarizr
 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
예제 #6
0
 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
예제 #7
0
 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
예제 #8
0
파일: base.py 프로젝트: golovast/scalarizr
 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)
예제 #9
0
 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)
예제 #10
0
 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
예제 #11
0
 def list(cls, api=None):
     api = api or ChefAPI.get_global()
     names = [name for name, url in api[cls.url].iteritems()]
     return ChefQuery(cls, names, api)
예제 #12
0
 def __init__(self, index, q='*:*', rows=1000, start=0, api=None):
     self.name = index
     self.api = api or ChefAPI.get_global()
     self._args = dict(q=q, rows=rows, start=start)
     self.url = self.__class__.url + '/' + self.name + '?' + urllib.urlencode(
         self._args)
예제 #13
0
파일: base.py 프로젝트: golovast/scalarizr
 def list(cls, api=None):
     """Return a :class:`ChefQuery` with the available objects of this type.
     """
     api = api or ChefAPI.get_global()
     names = [name for name, url in api[cls.url].iteritems()]
     return ChefQuery(cls, names, api)
예제 #14
0
 def list(cls, api=None):
     api = api or ChefAPI.get_global()
     names = [name for name, url in api[cls.url].iteritems()]
     return ChefQuery(cls, names, api)
예제 #15
0
 def __init__(self, index, q='*:*', rows=1000, start=0, api=None):
     self.name = index
     self.api = api or ChefAPI.get_global()
     self._args = dict(q=q, rows=rows, start=start)
     self.url = self.__class__.url + '/' + self.name + '?' + urllib.urlencode(self._args)
예제 #16
0
 def list(cls, api=None):
     """Return a :class:`ChefQuery` with the available objects of this type.
     """
     api = api or ChefAPI.get_global()
     names = [name for name, url in api[cls.url].iteritems()]
     return ChefQuery(cls, names, api)