Exemple #1
0
    def getcerts(self):
        res = self.callapi("getcerts", True, {}, use_certs=False)

        oldmask = os.umask(077)
        zipdata = zipfile.ZipFile(StringIO.StringIO(res))
        zipdata.extractall(path=self.confdir)
        client.conpaas_init_ssl_ctx(self.confdir, 'user')
        os.umask(oldmask)
Exemple #2
0
    def __init__(self):
        self.confdir = os.path.join(os.environ['HOME'], ".conpaas")

        if not os.path.isdir(self.confdir):
            os.mkdir(self.confdir, 0700)

        try:
            client.conpaas_init_ssl_ctx(self.confdir, 'user')
        except IOError:
            # We do not have the certificates yet. But we will get them soon: 
            # see getcerts()
            pass
Exemple #3
0
    def __init__(self, logger):
        self.logger = logger
        self.confdir = os.path.join(os.environ['HOME'], ".conpaas")
        if not os.path.isdir(self.confdir):
            os.mkdir(self.confdir, 0700)
        try:
            client.conpaas_init_ssl_ctx(self.confdir, 'user')
        except IOError:
            # We do not have the certificates yet.
            pass

        self.username = None
        self.password = None
        self.director_url = None
        self.debug = False
        self.services = None
Exemple #4
0
def callmanager(app_id, service_id, method, post, data, files=[]):
    """Call the manager API.

    'service_id': an integer holding the service id of the manager.
    'method': a string representing the API method name.
    'post': boolean value. True for POST method, false for GET.
    'data': a dictionary representing the data to be sent to the director.
    'files': sequence of (name, filename, value) tuples for data to be uploaded as files.

    callmanager loads the manager JSON response and returns it as a Python
    object.
    """
    client.conpaas_init_ssl_ctx('/etc/cpsdirector/certs', 'director')

    application = get_app_by_id(g.user.uid, app_id)

    if application is None:
        msg = "Application %s not found." % app_id
        log_error(msg)
        return error_response(msg)
    elif application.to_dict()['manager'] is None:
        msg = "Application %s has not started. Try to start it first." % app_id
        log_error(msg)
        return error_response(msg)

    application = application.to_dict()
    # File upload
    if files:
        data['service_id'] = service_id
        res = client.https_post(application['manager'], 443, '/', data, files)
    # POST
    elif post:
        res = client.jsonrpc_post(application['manager'], 443, '/', method, service_id, data)
    # GET
    else:
        res = client.jsonrpc_get(application['manager'], 443, '/', method, service_id, data)

    if res[0] == 200:
        try:
            data = simplejson.loads(res[1])
        except simplejson.decoder.JSONDecodeError:
            # Not JSON, simply return what we got
            return res[1]

        return data.get('result', data)

    raise Exception, "Call to method %s on %s failed: %s.\nParams = %s" % (method, application['manager'], res[1], data)
def main():
    client.conpaas_init_ssl_ctx('/etc/cpsmanager/certs', 'user')
    method = 'git_push_hook'
    manager_ip = '127.0.0.1'
    res = client.jsonrpc_post(manager_ip, 443, '/', method)

    if res[0] == 200:
        try:
            data = simplejson.loads(res[1])
        except simplejson.decoder.JSONDecodeError:
            # Not JSON, simply return what we got
            return res[1]

        return data.get('result', data)

    raise Exception("Call to method %s on %s failed with HTTP code %s: %s."
                    % (method, manager_ip, res[0], res[1]))
Exemple #6
0
def callmanager(service_id, method, post, data, files=[]):
    """Call the manager API.

    'service_id': an integer holding the service id of the manager.
    'method': a string representing the API method name.
    'post': boolean value. True for POST method, false for GET.
    'data': a dictionary representing the data to be sent to the director.
    'files': sequence of (name, filename, value) tuples for data to be uploaded as files.

    callmanager loads the manager JSON response and returns it as a Python
    object.
    """
    service = get_service(g.user.uid, service_id)

    client.conpaas_init_ssl_ctx('/etc/cpsdirector/certs', 'director')

    # File upload
    if files:
        res = client.https_post(service.manager, 443, '/', data, files)
    # POST
    elif post:
        res = client.jsonrpc_post(service.manager, 443, '/', method, data)
    # GET
    else:
        #res = client.jsonrpc_get(service.manager, 443, '/', method, data)
        if service.manager_port:
            node = service.manager_port.split(":")
            if len(node) == 2:
                _ip, _port = node
            else:
                _ip, _port = (service.manager, 443)
        res = client.jsonrpc_get(_ip, int(_port), '/', method, data)

    if res[0] == 200:
        try:
            data = simplejson.loads(res[1])
        except simplejson.decoder.JSONDecodeError:
            # Not JSON, simply return what we got
            return res[1]

        return data.get('result', data)

    raise Exception, "Call to method %s on %s failed: %s.\nParams = %s" % (
        method, service.manager, res[1], data)