Esempio n. 1
0
import ConfigParser
from synapse.logger import logger
from synapse.resources.resources import ResourceException

log = logger('cm_util')

# The different states of a virtual machine
VM_STATE_UNKNOWN = "unknown"
VM_STATE_RUNNING = "running"
VM_STATE_BLOCKED = "blocked"
VM_STATE_PAUSED = "paused"
VM_STATE_SHUTDOWN = "shutdown"
VM_STATE_SHUTOFF = "shutoff"
VM_STATE_CRASHED = "crashed"
VM_STATE_REBOOTING = "rebooting"
VM_STATE_RESUME = "resume"


def read_config_file(file_name):
    '''
    Returns a parsed configuration file.

    @param file_name: the path to the configuration file
    @type file_name: str
    '''
    config = ConfigParser.ConfigParser()

    try:
        ret = config.read(file_name)
        if not ret:
            raise ResourceException(
Esempio n. 2
0
import uuid
import time
import pika
import json
import socket

from M2Crypto import RSA, X509, EVP, m2

from synapse.config import config
from synapse.logger import logger
from synapse_exceptions import SynapseException


TIMEOUT = 5

log = logger(__name__)


def bootstrap(options):

    bootstrap_opts = get_bootstrap_config()

    if options.force:
        bootstrap_opts['register'] = True
        pem_list = ('cert', 'cacert', 'key', 'csr')
        for pem in pem_list:
            try:
                os.remove(config.paths[pem])
            except (IOError, OSError):
                pass
Esempio n. 3
0
from synapse.syncmd import exec_cmd
from synapse.synapse_exceptions import ResourceException
from synapse.logger import logger

log = logger('yum-pkg')


def install(name):
    ret = exec_cmd("/usr/bin/yum -q -y install %s" % name)
    if ret['returncode'] != 0:
        raise ResourceException(ret['stderr'])


def get_installed_packages():
    ret = exec_cmd("/bin/rpm -qa")
    return ret['stdout'].split('\n')


def remove(name):
    ret = exec_cmd("/usr/bin/yum -q -y remove %s" % name)
    if ret['returncode'] != 0:
        raise ResourceException(ret['stderr'])


def update(name):
    # We need to check first if the package is installed. yum update of a
    # non-existing package has a returncode of 0. We need to raise an exception
    # if the package is not installed !
    inst = is_installed(name)
    ret = exec_cmd("/usr/bin/yum -q -y update %s" % name)
Esempio n. 4
0
import cm_util
from synapse.config import config
from synapse.syncmd import exec_cmd
from synapse.resources.resources import ResourceException
import json
from restful_lib import Connection

import ConfigParser

from synapse.logger import logger
from synapse.syncmd import exec_cmd

# The configuration file of the cloud managers plugin
CLOUDMANAGERS_CONFIG_FILE = config.paths['config_path'] + "/plugins/cloudmanagers.conf"

log = logger("cm_openstack")

#-----------------------------------------------------------------------------

def _get_VMs(attributes):
    conn = Connection(attributes["cm_nova_url"], username="", password="")
    tenant_id, x_auth_token = _get_keystone_tokens(attributes)
    resp = conn.request_get("/" + tenant_id +"/servers", args={}, headers={'content-type':'application/json', 'accept':'application/json', 'x-auth-token':x_auth_token})
    status = resp[u'headers']['status']
    if status == '200' or status == '304':
        servers = json.loads(resp['body'])
        i = 0
        vms = []
        for r in servers['servers']:
            vms.append(r['name'])
            i = i+1
Esempio n. 5
0
import re

from synapse.logger import logger


perm_mapping = {"C": "create",
                "R": "read",
                "U": "update",
                "D": "delete",
                "-": ""}

log = logger(__name__)


def get(permission_file_path):
    """Reads the permissions file line by line and process them.
    Returns an array of permissions array.
    """

    permissions = []
    with open(permission_file_path, 'r') as fd:
        for index, line in enumerate(fd):
            # If line is blank, dont bother
            if not line.strip():
                continue
            try:
                permissions.append(process(line))
            except re.error:
                log.critical("There's a problem with your permissions config "
                             "file at line %d" % ((index + 1),))
                raise SystemExit
Esempio n. 6
0
import ConfigParser
from synapse.logger import logger
from synapse.resources.resources import ResourceException

log = logger('cm_util')


# The different states of a virtual machine
VM_STATE_UNKNOWN = "unknown"
VM_STATE_RUNNING = "running"
VM_STATE_BLOCKED = "blocked"
VM_STATE_PAUSED = "paused"
VM_STATE_SHUTDOWN = "shutdown"
VM_STATE_SHUTOFF = "shutoff"
VM_STATE_CRASHED = "crashed"
VM_STATE_REBOOTING = "rebooting"
VM_STATE_RESUME = "resume"


def read_config_file(file_name):
    '''
    Returns a parsed configuration file.

    @param file_name: the path to the configuration file
    @type file_name: str
    '''
    config = ConfigParser.ConfigParser()

    try:
        ret = config.read(file_name)
        if not ret: