pax_global_header 0000666 0000000 0000000 00000000064 13444400517 0014514 g ustar 00root root 0000000 0000000 52 comment=73a2600993a12576c45a9bb8de0e3bbdf9418e8c
cc-server-73a2600993a12576c45a9bb8de0e3bbdf9418e8c/ 0000775 0000000 0000000 00000000000 13444400517 0020413 5 ustar 00root root 0000000 0000000 cc-server-73a2600993a12576c45a9bb8de0e3bbdf9418e8c/.dockerignore 0000664 0000000 0000000 00000000154 13444400517 0023067 0 ustar 00root root 0000000 0000000 .git*
*.pyc
*~
*.swp
debsource
dist
venv
*.egg-info
*.coverage
*.cache
__pycache__
Dockerfile
.dockerignore
cc-server-73a2600993a12576c45a9bb8de0e3bbdf9418e8c/.gitignore 0000664 0000000 0000000 00000000103 13444400517 0022375 0 ustar 00root root 0000000 0000000 *.pyc
doc/_build/*
build
*.swp
*.swo
*.log
test_*.py
.ropeproject/
cc-server-73a2600993a12576c45a9bb8de0e3bbdf9418e8c/.gitlab-ci.yml 0000664 0000000 0000000 00000001471 13444400517 0023052 0 ustar 00root root 0000000 0000000 stages:
- build
.docker_build: &docker_build
stage: build
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
IMAGE_TAG: $CI_REGISTRY_IMAGE/ci:$CI_COMMIT_SHA
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE:master || true # Retrieve "master" version to use it as cache since the build is run using DinD
docker_ci_image:
<<: *docker_build
script:
- docker build --cache-from $CI_REGISTRY_IMAGE:master -t $IMAGE_TAG .
- docker push $IMAGE_TAG
docker_image:
<<: *docker_build
script:
- docker build --cache-from $CI_REGISTRY_IMAGE:master -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
only:
- master
- tags
cc-server-73a2600993a12576c45a9bb8de0e3bbdf9418e8c/COPYRIGHT 0000664 0000000 0000000 00000000040 13444400517 0021700 0 ustar 00root root 0000000 0000000 Copytight © 2010-2012 Smartjog
cc-server-73a2600993a12576c45a9bb8de0e3bbdf9418e8c/Dockerfile 0000664 0000000 0000000 00000002062 13444400517 0022405 0 ustar 00root root 0000000 0000000 FROM pypy:2-5.10-slim
RUN groupadd -r cc-server && useradd --no-log-init -r -g cc-server cc-server \
&& install -d -o cc-server -g cc-server /var/lib/cc-server
VOLUME ["/var/lib/cc-server"]
WORKDIR /opt/cc-server
COPY requirements.txt .
COPY README .
COPY setup.py .
COPY bin ./bin
COPY cloudcontrol ./cloudcontrol
RUN set -ex \
&& buildDeps=' \
build-essential \
git \
' \
&& apt-get -y update && apt-get install -y --no-install-recommends $buildDeps ssl-cert \
&& pip install --no-cache-dir -r requirements.txt -e . \
&& find /usr/local \
\( -type d -a -name test -o -name tests \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + \
&& apt-get purge -y --auto-remove $buildDeps \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
COPY docker-entrypoint.sh .
COPY etc/cc-server.conf.docker /etc/cc-server.conf
ENTRYPOINT ["./docker-entrypoint.sh"]
CMD ["pypy", "./bin/cc-server", "-s", "-f", "-u", "cc-server", "-g", "cc-server"]
EXPOSE 1984
cc-server-73a2600993a12576c45a9bb8de0e3bbdf9418e8c/LICENSE 0000664 0000000 0000000 00000016743 13444400517 0021433 0 ustar 00root root 0000000 0000000 GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
cc-server-73a2600993a12576c45a9bb8de0e3bbdf9418e8c/MANIFEST.in 0000664 0000000 0000000 00000000060 13444400517 0022145 0 ustar 00root root 0000000 0000000 recursive-include etc *
recursive-include doc *
cc-server-73a2600993a12576c45a9bb8de0e3bbdf9418e8c/README 0000664 0000000 0000000 00000000000 13444400517 0021261 0 ustar 00root root 0000000 0000000 cc-server-73a2600993a12576c45a9bb8de0e3bbdf9418e8c/bin/ 0000775 0000000 0000000 00000000000 13444400517 0021163 5 ustar 00root root 0000000 0000000 cc-server-73a2600993a12576c45a9bb8de0e3bbdf9418e8c/bin/cc-addaccount 0000775 0000000 0000000 00000006150 13444400517 0023603 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python
#coding=utf8
# This file is part of CloudControl.
#
# CloudControl is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# CloudControl is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with CloudControl. If not, see .
'''
Script used to create an account on cc-server account directory.
'''
import logging
import logging.handlers
import os
from getpass import getpass
from pwd import getpwnam
from grp import getgrnam
from optparse import OptionParser
from cloudcontrol.server.conf import CCConf
DEFAULT_ACCOUNT_DIRECTORY = '/var/lib/cc-server/'
DEFAULT_ROLE = 'cli'
UMASK = 0o0177
DEFAULT_CHOWN_USER = 'cc-server'
DEFAULT_CHOWN_GROUP = 'cc-server'
if __name__ == '__main__':
op = OptionParser(usage='%prog [options] login')
op.add_option('-d', '--directory', default=DEFAULT_ACCOUNT_DIRECTORY,
help='account directory')
op.add_option('-p', '--password', action='store_true',
help='ask for the password')
op.add_option('-c', '--copy', default=None,
help='copy this already existing account')
op.add_option('-r', '--role', default=None, choices=('cli', 'hv', 'host'),
help='specify the role (default %default)')
op.add_option('-u', '--user', default=DEFAULT_CHOWN_USER,
help='User running cc-server (default %default)')
op.add_option('-g', '--group', default=DEFAULT_CHOWN_GROUP,
help='Group running cc-server (default %default)')
options, args = op.parse_args()
if len(args) != 1:
op.error('a login must be provided')
if options.role is not None and options.copy is not None:
op.error('you can\'t specify a role for a copy')
if options.role is None:
role = DEFAULT_ROLE
else:
role = options.role
logger = logging.getLogger()
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
logger.addHandler(handler)
conf = CCConf(logger, options.directory)
if options.password:
password = getpass('Password: ')
password_again = getpass('Password (again): ')
if password != password_again:
op.error('password mismatch')
elif not password:
op.error('no password provided')
else:
password = None
os.umask(UMASK)
if options.copy is None:
conf.create_account(args[0], role, password)
else:
conf.copy_account(options.copy, args[0], password)
# Chown the files:
uid = getpwnam(options.user).pw_uid
gid = getgrnam(options.group).gr_gid
filename = os.path.join(options.directory, '%s.json' % args[0])
os.chown(filename, uid, gid)
cc-server-73a2600993a12576c45a9bb8de0e3bbdf9418e8c/bin/cc-server 0000775 0000000 0000000 00000016457 13444400517 0023017 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python
#coding=utf8
# This file is part of CloudControl.
#
# CloudControl is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# CloudControl is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with CloudControl. If not, see .
from cloudcontrol.common.helpers.logger import patch_logging; patch_logging()
import os
import sys
import atexit
import logging
import logging.handlers
import ConfigParser
import signal
from optparse import OptionParser
from pwd import getpwnam
from grp import getgrnam
from daemon import DaemonContext
from cloudcontrol.server.server import CCServer
from cloudcontrol.server import __version__
DEFAULT_CONFIG_FILE = '/etc/cc-server.conf'
DEFAULT_UMASK = 0o0177
DEFAULT_CONFIGURATION = {
'daemonize': False,
'user': '',
'group': '',
'pidfile': '',
'umask': '077',
'port': 1984,
'debug': False,
'account_db': None, # None = mandatory option
'interface': '127.0.0.1',
'ssl_cert': None,
'ssl_key': None,
'maxcon': 600,
'maxidle': 120,
}
# WORKAROUND ENCODING LOOKUP
import codecs
codecs.lookup('string-escape')
codecs.lookup('raw-unicode-escape')
# END OF WORKAROUND
class EncodingFormatter(logging.Formatter, object):
def __init__(self, fmt=None, datefmt=None, encoding='utf-8'):
super(EncodingFormatter, self).__init__(fmt, datefmt)
self._encoding = encoding
def formatException(self, ei):
expt = super(EncodingFormatter, self).formatException( ei)
if isinstance(expt, str):
expt = expt.decode(self._encoding, 'replace')
return expt
def format(self, record):
msg = super(EncodingFormatter, self).format(record)
if isinstance(msg, unicode):
msg = msg.encode(self._encoding, 'replace')
return msg
def run_server(options):
# Setup logging facility:
level = logging.INFO
if options['debug'] in (True, 'yes', 'true'):
level = logging.DEBUG
logger = logging.getLogger()
logger.setLevel(level)
if options['stdout']:
handler = logging.StreamHandler()
fmt = EncodingFormatter('[%(asctime)s] '
'\x1B[30;47m%(name)s\x1B[0m '
'\x1B[30;42m%(levelname)s\x1B[0m: '
'%(message)s')
else:
facility = logging.handlers.SysLogHandler.LOG_DAEMON
handler = logging.handlers.SysLogHandler(address='/dev/log',
facility=facility)
fmt = EncodingFormatter('%(name)s: %(levelname)s %(message)s')
handler.setFormatter(fmt)
logger.addHandler(handler)
server = CCServer(logger.getChild('cc-server'),
conf_dir=options['account_db'],
maxcon=int(options['maxcon']),
maxidle=int(options['maxidle']),
port=int(options['port']),
address=options['interface'],
keyfile=options['ssl_key'],
certfile=options['ssl_cert'])
def shutdown_handler(signum, frame):
'''
Handler called when SIGINT is emitted.
'''
server.rpc.shutdown()
logging.info('Server properly exited by SIGINT')
watcher_sigint = server.rpc.loop.signal(signal.SIGINT, shutdown_handler)
watcher_sigstop = server.rpc.loop.signal(signal.SIGTERM, shutdown_handler)
watcher_sigint.start()
watcher_sigstop.start()
try:
server.run()
except Exception as err:
logging.critical('Server failed: %s', err)
import traceback
traceback.print_exc(file=sys.stdout)
sys.exit(3)
if __name__ == '__main__':
op = OptionParser(version='%%prog v%s' % __version__)
op.add_option('-c', '--config', default=DEFAULT_CONFIG_FILE,
help='configuration file (default: %default)')
op.add_option('-d', '--daemonize', action='store_true',
help='run as a daemon')
op.add_option('-f', '--foreground', action='store_false', dest='daemonize',
help='don\'t run as a daemon')
op.add_option('-p', '--pidfile', help='write pidfile to the path')
op.add_option('-k', '--umask', help='set the umask of the process')
op.add_option('-u', '--user', help='run as user')
op.add_option('-g', '--group', help='run as group')
op.add_option('-s', '--stdout', action='store_true', default=False,
help='log in stdout instead of syslog')
cliopts, args = op.parse_args()
# Reading the config file:
config = ConfigParser.SafeConfigParser()
config.read(cliopts.config)
try:
options = dict(config.items('server'))
except ConfigParser.NoSectionError:
sys.stderr.write("Configuration error: 'server' section must exist "
"in '%s'\n" % cliopts.config)
sys.exit(1)
# Applying default config file options:
for opt, default in DEFAULT_CONFIGURATION.iteritems():
if opt not in options or not options[opt]:
if default is None:
sys.stderr.write("Configuration error: you must specify '%s' "
"option in '%s' !\n" % (opt, cliopts.config))
sys.exit(1)
else:
options[opt] = default
# Merge cli options and .conf file options:
for opt in ('daemonize', 'pidfile', 'umask', 'user', 'group', 'stdout'):
if getattr(cliopts, opt) is not None:
options[opt] = getattr(cliopts, opt)
# Create option set for the daemonization process:
daemon_opts = {}
daemonize = options['daemonize']
if isinstance(daemonize, str):
daemonize = daemonize in ('yes', 'true')
daemon_opts['detach_process'] = daemonize
daemon_opts['umask'] = int(options['umask'], 8)
if options['user']:
if options['user'].isdigit():
daemon_opts['uid'] = int(options['user'])
else:
daemon_opts['uid'] = getpwnam(options['user']).pw_uid
if options['group']:
if options['group'].isdigit():
daemon_opts['gid'] = int(options['group'])
else:
daemon_opts['gid'] = getgrnam(options['group']).gr_gid
if not daemonize:
daemon_opts['stderr'] = sys.stderr
daemon_opts['stdout'] = sys.stderr
# I've to write myself the pidfile because the daemon library write it
# after the privilege downgrade:
if options['pidfile']:
pidfile = open(cliopts.pidfile, 'w')
daemon_opts['files_preserve'] = [pidfile]
else:
pidfile = None
with DaemonContext(**daemon_opts):
if pidfile is not None:
pidfile.write('%s' % os.getpid())
pidfile.flush()
@atexit.register
def clean_pidfile():
pidfile.seek(0)
pidfile.truncate()
pidfile.flush()
run_server(options)
cc-server-73a2600993a12576c45a9bb8de0e3bbdf9418e8c/build-package.sh 0000775 0000000 0000000 00000002022 13444400517 0023436 0 ustar 00root root 0000000 0000000 #!/bin/bash
if [ "$1" == "" ]; then
echo "Usage: $0