示例#1
0
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from django.template import loader
from django.http import HttpResponse
from django.utils.translation import get_language
import json
from synnefo_branding.utils import render_to_string
from django.core.urlresolvers import reverse
from django.template import RequestContext

from synnefo.util.version import get_component_version

from synnefo.ui import settings as uisettings

SYNNEFO_JS_LIB_VERSION = get_component_version('app')

# UI preferences settings
TIMEOUT = getattr(settings, "TIMEOUT", 10000)
UPDATE_INTERVAL = getattr(settings, "UI_UPDATE_INTERVAL", 5000)
CHANGES_SINCE_ALIGNMENT = getattr(settings, "UI_CHANGES_SINCE_ALIGNMENT", 0)
UPDATE_INTERVAL_INCREASE = getattr(settings, "UI_UPDATE_INTERVAL_INCREASE",
                                   500)
UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT = \
    getattr(settings, "UI_UPDATE_INTERVAL_INCREASE_AFTER_CALLS_COUNT", 3)
UPDATE_INTERVAL_FAST = getattr(settings, "UI_UPDATE_INTERVAL_FAST", 2500)
UPDATE_INTERVAL_MAX = getattr(settings, "UI_UPDATE_INTERVAL_MAX", 10000)

# predefined values settings
VM_IMAGE_COMMON_METADATA = \
    getattr(settings, "UI_VM_IMAGE_COMMON_METADATA", ["OS", "users"])
示例#2
0
    def execute(self):
        """
        Given the command-line arguments, this figures out which subcommand is
        being run, creates a parser appropriate to that command, and runs it.
        """

        # --settings-dir option
        # will remove it later to avoid django commands from raising errors
        option_list = BaseCommand.option_list + (
            make_option('--settings-dir',
                action='store',
                dest='settings_dir',
                default=None,
                help='Load *.conf files from directory as settings'),)

        # Preprocess options to extract --settings and --pythonpath.
        # These options could affect the commands that are available, so they
        # must be processed early.
        parser = LaxOptionParser(usage="%prog subcommand [options] [args]",
                                 version=get_component_version('webproject'),
                                 option_list=option_list)
        self.autocomplete()
        try:
            options, args = parser.parse_args(self.argv)
            handle_default_options(options)
        except:
            pass  # Ignore any option errors at this point.

        # user provides custom settings dir
        # set it as environmental variable and remove it from self.argv
        if options.settings_dir:
            os.environ['SYNNEFO_SETTINGS_DIR'] = options.settings_dir
            for arg in self.argv:
                if arg.startswith('--settings-dir'):
                    self.argv.remove(arg)

        try:
            subcommand = self.argv[1]
        except IndexError:
            subcommand = 'help'  # Display help if no arguments were given.

        # Encode stdout. This check is required because of the way python
        # checks if something is tty:
        # https://bugzilla.redhat.com/show_bug.cgi?id=841152
        if not subcommand in ['test'] and not 'shell' in subcommand:
            sys.stdout = EncodedStdOut(sys.stdout)

        if subcommand == 'help':
            if len(args) > 2:
                self.fetch_command(args[2]).print_help(self.prog_name, args[2])
            else:
                parser.print_lax_help()
                sys.stdout.write(self.main_help_text() + '\n')
                sys.exit(1)
        # Special-cases: We want 'django-admin.py --version' and
        # 'django-admin.py --help' to work, for backwards compatibility.
        elif self.argv[1:] == ['--version']:
            # LaxOptionParser already takes care of printing the version.
            pass
        elif self.argv[1:] in (['--help'], ['-h']):
            parser.print_lax_help()
            sys.stdout.write(self.main_help_text() + '\n')
        else:
            self.fetch_command(subcommand).run_from_argv(self.argv)
示例#3
0
    def execute(self):
        """
        Given the command-line arguments, this figures out which subcommand is
        being run, creates a parser appropriate to that command, and runs it.
        """

        # --settings-dir option
        # will remove it later to avoid django commands from raising errors
        option_list = BaseCommand.option_list + (
            make_option(
                '--settings-dir',
                action='store',
                dest='settings_dir',
                default=None,
                help='Load *.conf files from directory as settings'),)

        # Preprocess options to extract --settings and --pythonpath.
        # These options could affect the commands that are available, so they
        # must be processed early.
        parser = LaxOptionParser(usage="%prog subcommand [options] [args]",
                                 version=get_component_version('webproject'),
                                 option_list=option_list)
        self.autocomplete()
        try:
            options, args = parser.parse_args(self.argv)
            handle_default_options(options)
        except:
            pass  # Ignore any option errors at this point.

        # user provides custom settings dir
        # set it as environmental variable and remove it from self.argv
        if options.settings_dir:
            os.environ['SYNNEFO_SETTINGS_DIR'] = options.settings_dir
            for arg in self.argv:
                if arg.startswith('--settings-dir'):
                    self.argv.remove(arg)

        try:
            subcommand = self.argv[1]
        except IndexError:
            subcommand = 'help'  # Display help if no arguments were given.

        # Encode stdout. This check is required because of the way python
        # checks if something is tty:
        # https://bugzilla.redhat.com/show_bug.cgi?id=841152
        if subcommand not in ['test'] and 'shell' not in subcommand:
            sys.stdout = EncodedStream(sys.stdout)
            sys.stderr = EncodedStream(sys.stderr)

        if subcommand == 'help':
            if len(args) > 2:
                self.fetch_command(args[2]).print_help(self.prog_name, args[2])
            else:
                parser.print_lax_help()
                sys.stdout.write(self.main_help_text() + '\n')
                sys.exit(1)
        # Special-cases: We want 'django-admin.py --version' and
        # 'django-admin.py --help' to work, for backwards compatibility.
        elif self.argv[1:] == ['--version']:
            # LaxOptionParser already takes care of printing the version.
            pass
        elif self.argv[1:] in (['--help'], ['-h']):
            parser.print_lax_help()
            sys.stdout.write(self.main_help_text() + '\n')
        else:
            sub_command = self.fetch_command(subcommand)
            # NOTE: This is an ugly workaround to bypass the problem with
            # the required permissions for the named pipes that Pithos backend
            # is creating in order to communicate with XSEG.
            if subcommand == 'test' or\
               subcommand.startswith('image-') or\
               subcommand.startswith('snapshot-') or\
               subcommand.startswith('file-'):
                # Set common umask for known commands
                os.umask(0o007)
            # Allow command to define a custom umask
            cmd_umask = getattr(sub_command, 'umask', None)
            if cmd_umask is not None:
                os.umask(cmd_umask)
            sub_command.run_from_argv(self.argv)
示例#4
0
def cloudbar(request):
    """
    Django context processor that applies all cloudbar settings in response
    context plus a ready to use pre rendered script html tag containing valid
    javascript code for cloudbar to display.

    To use it add ``synnefo.webproject.context_processors.cloudbar`` in your
    project's ``TEMPLATE_CONTEXT_PROCESSORS setting`` (snf-webproject already
    does).

    Then in your base html template::

        <html>
        ....
        <head>
        ...
        {% if CLOUDBAR_ACTIVE %}
            {{ CLOUDBAR_CODE }}
        {% endif %}
        </head>
        <body>
        ....
        </body>
        </html>


    """

    BRANDING_CSS = getattr(branding_settings, 'FONTS_CSS_URLS', [])

    CB_ACTIVE = getattr(settings, 'CLOUDBAR_ACTIVE', True)
    CB_LOCATION = getattr(settings, 'CLOUDBAR_LOCATION')
    CB_VERSION = version.get_component_version("webproject")

    CB_COOKIE_NAME = getattr(settings, 'CLOUDBAR_COOKIE_NAME',
            'okeanos_account')
    CB_SERVICES_URL = getattr(settings, 'CLOUDBAR_SERVICES_URL')
    CB_MENU_URL = getattr(settings, 'CLOUDBAR_MENU_URL')
    CB_HEIGHT = getattr(settings, 'CLOUDBAR_HEIGHT',
            '35')
    CB_BGCOLOR = getattr(settings, 'CLOUDBAR_BACKGROUND_COLOR',
            '#000000')

    CB_CODE = """
    <script type="text/javascript">
        var CLOUDBAR_VERSION = '%(version)s';
        var CLOUDBAR_LOCATION = "%(location)s";
        var CLOUDBAR_COOKIE_NAME = "%(cookie_name)s";
        var GET_SERVICES_URL = "%(services_url)s";
        var GET_MENU_URL = "%(menu_url)s";
        var CLOUDBAR_HEIGHT = '%(height)s';

        var CLOUDBAR_EXTRA_CSS = %(branding_css)s;

        $(document).ready(function(){
            $.getScript(CLOUDBAR_LOCATION + 'cloudbar.js?' + CLOUDBAR_VERSION);
        });

    </script>
    <style>
        body {
            border-top: %(height)spx solid %(bg_color)s;
        }
        body .cloudbar {
            height: %(height)spx;
        }
    </style>
""" % {'location': CB_LOCATION,
       'cookie_name': CB_COOKIE_NAME,
       'services_url': CB_SERVICES_URL,
       'menu_url': CB_MENU_URL,
       'height': str(CB_HEIGHT),
       'bg_color': CB_BGCOLOR,
       'version': CB_VERSION,
       'branding_css': json.dumps(BRANDING_CSS)}

    CB_CODE = mark_safe(CB_CODE)

    return {
        'CLOUDBAR_ACTIVE': CB_ACTIVE,
        'CLOUDBAR_LOCATION': CB_LOCATION,
        'CLOUDBAR_COOKIE_NAME': CB_COOKIE_NAME,
        'CLOUDBAR_SERVICES_URL': CB_SERVICES_URL,
        'CLOUDBAR_MENU_URL': CB_MENU_URL,
        'CLOUDBAR_CODE': CB_CODE
    }
示例#5
0
# The service favicon 
FAVICON_URL = getattr(settings, 'BRANDING_FAVICON_URL',
        	   		  IMAGE_MEDIA_URL+'favicon.ico')
# Logo used in Dashboard pages (Astakos)
DASHBOARD_LOGO_URL = getattr(settings, 'BRANDING_DASHBOARD_LOGO_URL', 
					 		 IMAGE_MEDIA_URL+'dashboard_logo.png')
# Logo used in Compute pages (Cyclades)
COMPUTE_LOGO_URL = getattr(settings, 'BRANDING_COMPUTE_LOGO_URL',
						   IMAGE_MEDIA_URL+'compute_logo.png')
# Logo used in Console page for VM (Cyclades)
CONSOLE_LOGO_URL = getattr(settings, 'BRANDING_CONSOLE_LOGO_URL',
						   IMAGE_MEDIA_URL+'console_logo.png')
# Logo used in Storage pages (Pithos)
STORAGE_LOGO_URL = getattr(settings, 'BRANDING_STORAGE_LOGO_URL',
						   IMAGE_MEDIA_URL+'storage_logo.png') 

## Copyright options
######################

# If True, Copyright message will appear at the footer of the Compute and 
# Dashboard UI 
SHOW_COPYRIGHT = getattr(settings, 'BRANDING_SHOW_COPYRIGHT', False)
copyright_period_default = '2011-%s' % (datetime.datetime.now().year)
copyright_message_default = 'Copyright (c) %s %s' % (copyright_period_default, 
											 COMPANY_NAME)
# Defaults to Copyright (c) 2011-<current_year> GRNET.
COPYRIGHT_MESSAGE = getattr(settings, 'BRANDING_COPYRIGHT_MESSAGE', 
						    copyright_message_default)
 
SYNNEFO_VERSION = get_component_version('common')
示例#6
0
def cloudbar(request):
    """
    Django context processor that applies all cloudbar settings in response
    context plus a ready to use pre rendered script html tag containing valid
    javascript code for cloudbar to display.

    To use it add ``synnefo.webproject.context_processors.cloudbar`` in your
    project's ``TEMPLATE_CONTEXT_PROCESSORS setting`` (snf-webproject already
    does).

    Then in your base html template::

        <html>
        ....
        <head>
        ...
        {% if CLOUDBAR_ACTIVE %}
            {{ CLOUDBAR_CODE }}
        {% endif %}
        </head>
        <body>
        ....
        </body>
        </html>


    """

    BRANDING_CSS = getattr(branding_settings, 'FONTS_CSS_URLS', [])

    CB_ACTIVE = getattr(settings, 'CLOUDBAR_ACTIVE', True)
    CB_LOCATION = getattr(settings, 'CLOUDBAR_LOCATION')
    CB_VERSION = version.get_component_version("webproject")

    CB_COOKIE_NAME = getattr(settings, 'CLOUDBAR_COOKIE_NAME',
                             'okeanos_account')
    CB_SERVICES_URL = getattr(settings, 'CLOUDBAR_SERVICES_URL')
    CB_MENU_URL = getattr(settings, 'CLOUDBAR_MENU_URL')
    CB_HEIGHT = getattr(settings, 'CLOUDBAR_HEIGHT', '35')
    CB_BGCOLOR = getattr(settings, 'CLOUDBAR_BACKGROUND_COLOR', '#000000')

    CB_CODE = """
    <script type="text/javascript">
        var CLOUDBAR_VERSION = '%(version)s';
        var CLOUDBAR_LOCATION = "%(location)s";
        var CLOUDBAR_COOKIE_NAME = "%(cookie_name)s";
        var GET_SERVICES_URL = "%(services_url)s";
        var GET_MENU_URL = "%(menu_url)s";
        var CLOUDBAR_HEIGHT = '%(height)s';

        var CLOUDBAR_EXTRA_CSS = %(branding_css)s;

        $(document).ready(function(){
            $.getScript(CLOUDBAR_LOCATION + 'cloudbar.js?' + CLOUDBAR_VERSION);
        });

    </script>
    <style>
        body {
            border-top: %(height)spx solid %(bg_color)s;
        }
        body .cloudbar {
            height: %(height)spx;
        }
    </style>
""" % {
        'location': CB_LOCATION,
        'cookie_name': CB_COOKIE_NAME,
        'services_url': CB_SERVICES_URL,
        'menu_url': CB_MENU_URL,
        'height': str(CB_HEIGHT),
        'bg_color': CB_BGCOLOR,
        'version': CB_VERSION,
        'branding_css': json.dumps(BRANDING_CSS)
    }

    CB_CODE = mark_safe(CB_CODE)

    return {
        'CLOUDBAR_ACTIVE': CB_ACTIVE,
        'CLOUDBAR_LOCATION': CB_LOCATION,
        'CLOUDBAR_COOKIE_NAME': CB_COOKIE_NAME,
        'CLOUDBAR_SERVICES_URL': CB_SERVICES_URL,
        'CLOUDBAR_MENU_URL': CB_MENU_URL,
        'CLOUDBAR_CODE': CB_CODE
    }
示例#7
0
文件: manage.py 项目: vgerak/synnefo
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys
import os
import errno
import grp
import pwd
from django.core.management import ManagementUtility
from django.core import management
from synnefo.util.version import get_component_version
from logging.config import dictConfig

# monkey patch to show synnefo version instead of django version
management.get_version = lambda: get_component_version('webproject')


class SynnefoManagementUtility(ManagementUtility):
    def main_help_text(self):
        return ManagementUtility.main_help_text(self, commands_only=True)


def configure_logging():
    try:
        from synnefo.settings import SNF_MANAGE_LOGGING_SETUP
        dictConfig(SNF_MANAGE_LOGGING_SETUP)
    except ImportError:
        import logging
        logging.basicConfig()
        log = logging.getLogger()
示例#8
0
文件: manage.py 项目: grnet/synnefo
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import sys
import os
import errno
import grp
import pwd
from django.core.management import ManagementUtility
from django.core import management
from synnefo.util.version import get_component_version
from logging.config import dictConfig

# monkey patch to show synnefo version instead of django version
management.get_version = lambda: get_component_version('webproject')


class SynnefoManagementUtility(ManagementUtility):

    def main_help_text(self):
        return ManagementUtility.main_help_text(self, commands_only=True)


def configure_logging():
    try:
        from synnefo.settings import SNF_MANAGE_LOGGING_SETUP
        dictConfig(SNF_MANAGE_LOGGING_SETUP)
    except ImportError:
        import logging
        logging.basicConfig()