示例#1
0
    def _create_user(self):
        user = '******'
        password = ''.join([choice(string.letters + string.digits) for i in range(20)])
        run_command(['useradd', '-m', 'node_agent'])
        enc_passwd = crypt.crypt(password, SALT)
        ret, out, err = run_command(['usermod', '-p', enc_passwd, 'node_agent'])

        #TO-DO: set permissions to user

        if ret:
            raise Exception('usermod error: %s'%err)

        return user, password
示例#2
0
    def process(self, parameters):
        try:
            code, cout, cerr = run_command(['reboot'])

            if code:
                raise Exception('Reboot operation failed: %s'%cerr)

            self.updateOperationProgress(100, ret_message='Node is rebooting now...')
        except Exception, err:
            self.updateOperationProgress(50, ret_message='Error occured: %s'%err, ret_code=1)
示例#3
0
    def _get_hardware_info(self):
        ret,out,err = run_command(['uname', '-p'])
        if ret:
            raise Exception('uname error: %s'%err)

        processor = out.strip()

        all_memory = open('/proc/meminfo').readlines()[0]
        all_memory = all_memory.split(':')[1]
        all_memory, mesure = all_memory.strip().split(' ')
        all_memory = int(all_memory)
        if mesure.lower() == 'kb':
            all_memory /= 1024
        elif mesure.lower() == 'gb':
            all_memory *= 1024

        return  processor, all_memory
示例#4
0
    def _set_new_hostname(self, uuid):
        hostname = self.__get_cmdline_hostname()

        if hostname is None:
            logger.info('Setting defaut hostname')
            hostname = 'NODE-%s' % uuid.split('-')[-1]
        else:
            logger.info('Hostname specified by kernel command line: %s'%hostname)

        run_command(['hostname', hostname])

        ret,out,err = run_command(['dhcpcd','--rebind', '--waitip', 'eth0'])
        if ret:
            raise Exception('dhcpcd eth0 error: %s'%err)

        run_command(['/etc/init.d/syslog-ng', 'reload'])
        run_command(['/etc/init.d/ntp-client', 'restart'])

        return hostname
os.system('/etc/init.d/boot-event-listener stop')
os.system('/etc/init.d/syslog-ng stop')
os.system('/etc/init.d/postgresql-9.0 restart')
os.system('/etc/init.d/syslog-ng start')
os.system('/etc/init.d/boot-event-listener start')

####################################
# Glusterfs share mounting
####################################
#run_command(['glusterfs', DISKLESS_HOME])

####################################
#database configuration
####################################

ret,out,err = run_command(['createdb', '-U',  'postgres',  'blik_cloud_db'])
if not ret:
    ret,out,err = run_command(['psql', '-U', 'postgres', '-d', 'blik_cloud_db', '-f', '/opt/blik/db/cloud_db_schema.sql'])
    if ret:
        print (err)
        sys.exit(1)

    ret,out,err = run_command(['psql', '-U', 'postgres', '-d', 'blik_cloud_db', '-f', '/opt/blik/db/logs_schema.sql'])
    if ret:
        print (err)
        sys.exit(1)


if len(sys.argv) > 1 and sys.argv[1] == '--skip-images':
    print ('Skiping images recreation...')
    sys.exit(0)
示例#6
0
    def _get_uuid(self):
        ret,out,err = run_command(['dmidecode', '-s', 'system-uuid'])
        if ret:
            raise Exception('dmidecode error: %s'%err)

        return out.strip()
示例#7
0
def change_base_node_params(request, node_id):
    if request.method != "POST":
        raise Exception("POST request expected for change base node parameters!")
    cur_user = get_current_user(request)
    node = NmNode.objects.get(id=node_id)

    url = "/configure_node/%s" % node_id

    # change hostname
    hostname = request.POST["hostname"]
    if not hostname:
        return inform_message("Hostname should be not empty!", url)

    if not re.match("[a-zA-Z][a-zA-Z0-9\-]+$", hostname):
        return inform_message('Hostname is invalid. Allowed characters are: a-z, A-Z, 0-9 and "-"', url)

    old_node_hostname = node.hostname
    if old_node_hostname != hostname:
        node.hostname = hostname

    # change node type
    node_type_id = request.POST["nodeType"]
    if not node_type_id:
        raise Exception("Node type id expected in POST message")

    if node.node_type.id != node_type_id:
        node.node_type = NmNodeType.objects.get(id=node_type_id)

    # change architecture
    arch = request.POST["architecture"]
    if not arch:
        raise Exception("Node architecture expected in POST message")
    if node.architecture != arch:
        node.architecture = arch

    # set optional parameters (used for node registration)
    if request.POST.has_key("clusterId"):
        cluster = NmCluster.objects.get(id=request.POST["clusterId"])
        node.cluster = cluster

    if request.POST.has_key("logicName"):
        node.logic_name = request.POST["logicName"]

    node.last_modifier_id = cur_user.id
    node.save()

    ret_message = "Parameters are installed for node!\n"

    if NODES_MANAGER_SUPPORT:
        # apply parameters
        code, out, err = run_command(
            [
                "change-node",
                "--node-type",
                node.node_type.type_sid,
                "--arch",
                node.architecture,
                "--hostname",
                node.hostname,
                "--uuid",
                node.node_uuid,
            ]
        )
        if code:
            return inform_message("New node parameters saved, but not installed!\nDetails: %s" % err, url)

        # reboot node
        ret_code, msg = reboot_node(old_node_hostname, cur_user.name)
        if ret_code:
            return inform_message("Node is not rebooted! Details: %s" % msg, url)

        ret_message += "Node rebooting for apply parameters..."

    else:
        ret_message += "Node is not rebooted because NodesManager is not supported in Console!"

    return inform_message(ret_message, url)