Exemplo n.º 1
0
class PuppetClassifier(object):

    def __init__(self, ctx):
        self.ctx = ctx
        self.props = self.ctx.properties['puppet_config']

        self.set_properties()

        server=self.props['server']
        scheme = 'http'
        port = '1261'
        cert=key=cacert = None
        if self.use_ssl:
            scheme = 'https'
            port = '1262'
            # the location of these files is platform dependent.
            #TODO: set defaults based on platform (Linux, windows)
            config_certname = ctx['config_certname']
            default_cert = '/var/lib/puppet/ssl/certs/%s.pem' % config_certname
            default_key = '/var/lib/puppet/ssl/private_keys/%s.pem' % config_certname
            default_cacert = '/var/lib/puppet/ssl/certs/ca.pem'
            cert = self.group.get('cert', default_cert)
            key = self.group.get('key', default_key)
            cacert = self.group.get('cacert', default_cacert)

        puppet_endpoint_url = '{scheme}://{server}:{port}'.format(scheme=scheme, server=server, port=port)
        self.group_client = GroupClient(puppet_endpoint_url, cert, key, cacert)

    def set_properties(self):
        self.environment = self.props['environment']
        self.group = self.props.get('group')
        self.use_ssl = self.group.get('use_ssl')
        if self.group is not None:
            self.parent_id = self.group.get('parent_id')
            if self.parent_id is None:
                raise PuppetParamsError("parent_id value of group must be set.")
            self.classes = self.group.get('classes')
            if self.classes is None:
                raise PuppetParamsError("classes value of group must be set.")

    def classify(self):
        if self.group is not None:
            config_node_name = self.ctx['config_node_name']
            group_name = 'cloudify_%s' % config_node_name
            rule = ["and",["=","name",config_node_name]]
            variables = self.group.get('variables')
            new_group =  Group(
                    group_name,
                    self.parent_id,
                    rule,
                    self.classes,
                    variables=variables,
                    environment=self.environment
                )
            result_group = self.group_client.create(new_group)
            self.group_id = result_group.get('id')

    def declassify(self):
        if self.group_id is not None:
            self.group_client.delete(self.group_id)
Exemplo n.º 2
0
    def __init__(self, ctx):
        self.ctx = ctx
        self.props = self.ctx.properties['puppet_config']

        self.set_properties()

        server = self.props['server']
        scheme = 'http'
        port = '1261'
        cert = key = cacert = None
        if self.use_ssl:
            scheme = 'https'
            port = '1262'
            # the location of these files is platform dependent.
            #TODO: set defaults based on platform (Linux, windows)
            config_certname = ctx['config_certname']
            default_cert = '/var/lib/puppet/ssl/certs/%s.pem' % config_certname
            default_key = '/var/lib/puppet/ssl/private_keys/%s.pem' % config_certname
            default_cacert = '/var/lib/puppet/ssl/certs/ca.pem'
            cert = self.group.get('cert', default_cert)
            key = self.group.get('key', default_key)
            cacert = self.group.get('cacert', default_cacert)

        puppet_endpoint_url = '{scheme}://{server}:{port}'.format(
            scheme=scheme, server=server, port=port)
        self.group_client = GroupClient(puppet_endpoint_url, cert, key, cacert)
Exemplo n.º 3
0
class PuppetClassifier(object):
    def __init__(self, ctx):
        self.ctx = ctx
        self.props = self.ctx.properties['puppet_config']

        self.set_properties()

        server = self.props['server']
        scheme = 'http'
        port = '1261'
        cert = key = cacert = None
        if self.use_ssl:
            scheme = 'https'
            port = '1262'
            # the location of these files is platform dependent.
            #TODO: set defaults based on platform (Linux, windows)
            config_certname = ctx['config_certname']
            default_cert = '/var/lib/puppet/ssl/certs/%s.pem' % config_certname
            default_key = '/var/lib/puppet/ssl/private_keys/%s.pem' % config_certname
            default_cacert = '/var/lib/puppet/ssl/certs/ca.pem'
            cert = self.group.get('cert', default_cert)
            key = self.group.get('key', default_key)
            cacert = self.group.get('cacert', default_cacert)

        puppet_endpoint_url = '{scheme}://{server}:{port}'.format(
            scheme=scheme, server=server, port=port)
        self.group_client = GroupClient(puppet_endpoint_url, cert, key, cacert)

    def set_properties(self):
        self.environment = self.props['environment']
        self.group = self.props.get('group')
        self.use_ssl = self.group.get('use_ssl')
        if self.group is not None:
            self.parent_id = self.group.get('parent_id')
            if self.parent_id is None:
                raise PuppetParamsError(
                    "parent_id value of group must be set.")
            self.classes = self.group.get('classes')
            if self.classes is None:
                raise PuppetParamsError("classes value of group must be set.")

    def classify(self):
        if self.group is not None:
            config_node_name = self.ctx['config_node_name']
            group_name = 'cloudify_%s' % config_node_name
            rule = ["and", ["=", "name", config_node_name]]
            variables = self.group.get('variables')
            new_group = Group(group_name,
                              self.parent_id,
                              rule,
                              self.classes,
                              variables=variables,
                              environment=self.environment)
            result_group = self.group_client.create(new_group)
            self.group_id = result_group.get('id')

    def declassify(self):
        if self.group_id is not None:
            self.group_client.delete(self.group_id)
Exemplo n.º 4
0
    def __init__(self, ctx):
        self.ctx = ctx
        self.props = self.ctx.properties['puppet_config']

        self.set_properties()

        server=self.props['server']
        scheme = 'http'
        port = '1261'
        cert=key=cacert = None
        if self.use_ssl:
            scheme = 'https'
            port = '1262'
            # the location of these files is platform dependent.
            #TODO: set defaults based on platform (Linux, windows)
            config_certname = ctx['config_certname']
            default_cert = '/var/lib/puppet/ssl/certs/%s.pem' % config_certname
            default_key = '/var/lib/puppet/ssl/private_keys/%s.pem' % config_certname
            default_cacert = '/var/lib/puppet/ssl/certs/ca.pem'
            cert = self.group.get('cert', default_cert)
            key = self.group.get('key', default_key)
            cacert = self.group.get('cacert', default_cacert)

        puppet_endpoint_url = '{scheme}://{server}:{port}'.format(scheme=scheme, server=server, port=port)
        self.group_client = GroupClient(puppet_endpoint_url, cert, key, cacert)
Exemplo n.º 5
0
 def setUp(self):
     puppet_endpoint_url = os.environ['puppet_endpoint_url']
     cert = os.environ.get('cert')
     key = os.environ.get('key')
     cacert = os.environ.get('cacert')
     self.group_client = GroupClient(puppet_endpoint_url, cert, key, cacert)
Exemplo n.º 6
0
class TestGroups(unittest.TestCase):
    def setUp(self):
        puppet_endpoint_url = os.environ['puppet_endpoint_url']
        cert = os.environ.get('cert')
        key = os.environ.get('key')
        cacert = os.environ.get('cacert')
        self.group_client = GroupClient(puppet_endpoint_url, cert, key, cacert)

    def tearDown(self):
        pass

    def test_retrieve_all(self):
        status_code, groups = self.group_client.retrieve_all()
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(groups)
        self.assertTrue(isinstance(groups, list))
        self.assertGreater(len(groups), 0)
        self.assertTrue(isinstance(groups[0], dict))
        self.assertTrue(groups[0].has_key('id'))

    def test_retrieve_all_inherited(self):
        status_code, groups = self.group_client.retrieve_all(inherited=True)
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(groups)
        self.assertTrue(isinstance(groups, list))
        self.assertGreater(len(groups), 0)
        self.assertTrue(isinstance(groups[0], dict))
        self.assertTrue(groups[0].has_key('id'))

    def test_retrieve(self):
        status_code, groups = self.group_client.retrieve_all()
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(groups)
        self.assertTrue(isinstance(groups, list))
        self.assertGreater(len(groups), 0)
        self.assertTrue(isinstance(groups[0], dict))
        self.assertTrue(groups[0].has_key('id'))
        group_id = groups[0]['id']

        status_code, group = self.group_client.retrieve(group_id)
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(group)
        self.assertTrue(isinstance(group, dict))
        self.assertTrue(group.has_key('id'))

    def test_validate(self):
        status_code, groups = self.group_client.retrieve_all()
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(groups)
        self.assertTrue(isinstance(groups, list))
        self.assertGreater(len(groups), 0)
        self.assertTrue(isinstance(groups[0], dict))
        self.assertTrue(groups[0].has_key('id'))
        parent_id = groups[0]['id']

        group = Group('validation_test', parent_id,
                      ["and", ["~", "name", "^apache.*$"]], {"apache": {}})
        status_code, valid_group = self.group_client.validate(group)
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(valid_group)
        self.assertTrue(isinstance(valid_group, dict))
        self.assertTrue(valid_group.has_key('id'))

    def test_create(self):
        group_id = None
        try:
            status_code, groups = self.group_client.retrieve_all()
            self.assertEquals(status_code, 200)
            self.assertIsNotNone(groups)
            self.assertTrue(isinstance(groups, list))
            self.assertGreater(len(groups), 0)
            self.assertTrue(isinstance(groups[0], dict))
            self.assertTrue(groups[0].has_key('id'))
            parent_id = groups[0]['id']

            group = Group('create_test', parent_id,
                          ["and", ["~", "name", "^apache.*$"]], {"apache": {}})
            status_code, create_group = self.group_client.create(group)
            self.assertEquals(status_code, 200)
            self.assertIsNotNone(create_group)
            self.assertTrue(isinstance(create_group, dict))
            self.assertTrue(create_group.has_key('id'))
            group_id = create_group['id']
        finally:
            if group_id is not None:
                self.group_client.delete(group_id)

    def test_update(self):
        group_id = None
        try:
            status_code, groups = self.group_client.retrieve_all()
            self.assertEquals(status_code, 200)
            self.assertIsNotNone(groups)
            self.assertTrue(isinstance(groups, list))
            self.assertGreater(len(groups), 0)
            self.assertTrue(isinstance(groups[0], dict))
            self.assertTrue(groups[0].has_key('id'))
            parent_id = groups[0]['id']

            group = Group('update_test', parent_id,
                          ["and", ["~", "name", "^apache.*$"]], {"apache": {}})
            status_code, create_group = self.group_client.create(group)
            self.assertEquals(status_code, 200)
            self.assertIsNotNone(create_group)
            self.assertTrue(isinstance(create_group, dict))
            self.assertTrue(create_group.has_key('id'))
            group_id = create_group['id']
            self.assertTrue(create_group.has_key('classes'))
            classes = create_group['classes']
            self.assertTrue(classes.has_key('apache'))
            apache = classes['apache']
            apache['serveradmin'] = '*****@*****.**'

            status_code, update_group = self.group_client.update(
                create_group, group_id)
            self.assertEquals(status_code, 200)
            self.assertIsNotNone(update_group, group_id)
            self.assertTrue(isinstance(update_group, dict))
            self.assertTrue(update_group.has_key('classes'))
            classes = update_group['classes']
            self.assertTrue(classes.has_key('apache'))
            apache = classes['apache']
            self.assertTrue(apache.has_key('serveradmin'))
            serveradmin = apache['serveradmin']
            self.assertEquals(serveradmin, '*****@*****.**')
        finally:
            if group_id is not None:
                self.group_client.delete(group_id)

    def test_delete(self):
        status_code, groups = self.group_client.retrieve_all()
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(groups)
        self.assertTrue(isinstance(groups, list))
        self.assertGreater(len(groups), 0)
        self.assertTrue(isinstance(groups[0], dict))
        self.assertTrue(groups[0].has_key('id'))
        parent_id = groups[0]['id']

        group = Group('create_test', parent_id,
                      ["and", ["~", "name", "^apache.*$"]], {"apache": {}})
        status_code, create_group = self.group_client.create(group)
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(create_group)
        self.assertTrue(isinstance(create_group, dict))
        self.assertTrue(create_group.has_key('id'))
        group_id = create_group['id']

        status_code, body = self.group_client.delete(group_id)
        self.assertEquals(status_code, 204)
 def setUp(self):
     puppet_endpoint_url = os.environ['puppet_endpoint_url']
     cert = os.environ.get('cert')
     key = os.environ.get('key')
     cacert = os.environ.get('cacert')
     self.group_client = GroupClient(puppet_endpoint_url, cert, key, cacert)
class TestGroups(unittest.TestCase):

    def setUp(self):
        puppet_endpoint_url = os.environ['puppet_endpoint_url']
        cert = os.environ.get('cert')
        key = os.environ.get('key')
        cacert = os.environ.get('cacert')
        self.group_client = GroupClient(puppet_endpoint_url, cert, key, cacert)

    def tearDown(self):
        pass

    def test_retrieve_all(self):
        status_code, groups = self.group_client.retrieve_all()
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(groups)
        self.assertTrue(isinstance(groups, list))
        self.assertGreater(len(groups), 0)
        self.assertTrue(isinstance(groups[0], dict))
        self.assertTrue(groups[0].has_key('id'))

    def test_retrieve_all_inherited(self):
        status_code, groups = self.group_client.retrieve_all(inherited=True)
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(groups)
        self.assertTrue(isinstance(groups, list))
        self.assertGreater(len(groups), 0)
        self.assertTrue(isinstance(groups[0], dict))
        self.assertTrue(groups[0].has_key('id'))

    def test_retrieve(self):
        status_code, groups = self.group_client.retrieve_all()
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(groups)
        self.assertTrue(isinstance(groups, list))
        self.assertGreater(len(groups), 0)
        self.assertTrue(isinstance(groups[0], dict))
        self.assertTrue(groups[0].has_key('id'))
        group_id = groups[0]['id']

        status_code, group = self.group_client.retrieve(group_id)
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(group)
        self.assertTrue(isinstance(group, dict))
        self.assertTrue(group.has_key('id'))

    def test_validate(self):
        status_code, groups = self.group_client.retrieve_all()
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(groups)
        self.assertTrue(isinstance(groups, list))
        self.assertGreater(len(groups), 0)
        self.assertTrue(isinstance(groups[0], dict))
        self.assertTrue(groups[0].has_key('id'))
        parent_id = groups[0]['id']

        group = Group('validation_test', parent_id, ["and",["~","name","^apache.*$"]], {"apache": {}})
        status_code, valid_group = self.group_client.validate(group)
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(valid_group)
        self.assertTrue(isinstance(valid_group, dict))
        self.assertTrue(valid_group.has_key('id'))

    def test_create(self):
        group_id = None
        try:
            status_code, groups = self.group_client.retrieve_all()
            self.assertEquals(status_code, 200)
            self.assertIsNotNone(groups)
            self.assertTrue(isinstance(groups, list))
            self.assertGreater(len(groups), 0)
            self.assertTrue(isinstance(groups[0], dict))
            self.assertTrue(groups[0].has_key('id'))
            parent_id = groups[0]['id']

            group = Group('create_test', parent_id, ["and",["~","name","^apache.*$"]], {"apache": {}})
            status_code, create_group = self.group_client.create(group)
            self.assertEquals(status_code, 200)
            self.assertIsNotNone(create_group)
            self.assertTrue(isinstance(create_group, dict))
            self.assertTrue(create_group.has_key('id'))
            group_id = create_group['id']
        finally:
            if group_id is not None:
                self.group_client.delete(group_id)

    def test_update(self):
        group_id = None
        try:
            status_code, groups = self.group_client.retrieve_all()
            self.assertEquals(status_code, 200)
            self.assertIsNotNone(groups)
            self.assertTrue(isinstance(groups, list))
            self.assertGreater(len(groups), 0)
            self.assertTrue(isinstance(groups[0], dict))
            self.assertTrue(groups[0].has_key('id'))
            parent_id = groups[0]['id']

            group = Group('update_test', parent_id, ["and",["~","name","^apache.*$"]], {"apache": {}})
            status_code, create_group = self.group_client.create(group)
            self.assertEquals(status_code, 200)
            self.assertIsNotNone(create_group)
            self.assertTrue(isinstance(create_group, dict))
            self.assertTrue(create_group.has_key('id'))
            group_id = create_group['id']
            self.assertTrue(create_group.has_key('classes'))
            classes = create_group['classes']
            self.assertTrue(classes.has_key('apache'))
            apache = classes['apache']
            apache['serveradmin'] = '*****@*****.**'

            status_code, update_group = self.group_client.update(create_group, group_id)
            self.assertEquals(status_code, 200)
            self.assertIsNotNone(update_group, group_id)
            self.assertTrue(isinstance(update_group, dict))
            self.assertTrue(update_group.has_key('classes'))
            classes = update_group['classes']
            self.assertTrue(classes.has_key('apache'))
            apache = classes['apache']
            self.assertTrue(apache.has_key('serveradmin'))
            serveradmin = apache['serveradmin']
            self.assertEquals(serveradmin, '*****@*****.**')
        finally:
            if group_id is not None:
                self.group_client.delete(group_id)

    def test_delete(self):
        status_code, groups = self.group_client.retrieve_all()
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(groups)
        self.assertTrue(isinstance(groups, list))
        self.assertGreater(len(groups), 0)
        self.assertTrue(isinstance(groups[0], dict))
        self.assertTrue(groups[0].has_key('id'))
        parent_id = groups[0]['id']

        group = Group('create_test', parent_id, ["and",["~","name","^apache.*$"]], {"apache": {}})
        status_code, create_group = self.group_client.create(group)
        self.assertEquals(status_code, 200)
        self.assertIsNotNone(create_group)
        self.assertTrue(isinstance(create_group, dict))
        self.assertTrue(create_group.has_key('id'))
        group_id = create_group['id']

        status_code, body = self.group_client.delete(group_id)
        self.assertEquals(status_code, 204)