Exemple #1
0
#Kage Park
from klib.MODULE import MODULE
MODULE().Import('from klib.Type import Type')


def screen_kill(title):
    ids = screen_id(title)
    if len(ids) == 1:
        rc = rshell('''screen -X -S {} quit'''.format(ids[0]))
        if rc[0] == 0:
            return True
        return False


def screen_monitor(title, ip, ipmi_user, ipmi_pass, find=[], timeout=600):
    if type(title) is not str or not title:
        print('no title')
        return False
    scr_id = screen_id(title)
    if scr_id:
        print('Already has the title at {}'.format(scr_id))
        return False
    cmd = "ipmitool -I lanplus -H {} -U {} -P {} sol activate".format(
        ip, ipmi_user, ipmi_pass)
    # Linux OS Boot (Completely kernel loaded): find=['initrd0.img','\xff']
    # PXE Boot prompt: find=['boot:']
    # PXE initial : find=['PXE ']
    # DHCP initial : find=['DHCP']
    # ex: aa=screen_monitor('test','ipmitool -I lanplus -H <bmc ip> -U ADMIN -P ADMIN sol activate',find=['initrd0.img','\xff'],timeout=300)
    log_file = screen_logging(title, cmd)
    init_time = int_sec()
Exemple #2
0
#Kage Park
import socket, os
from klib.MODULE import MODULE

MODULE().Import('from klib.Type import Type')
MODULE().Import('from klib.DEV import *')
MODULE().Import('from klib.SHELL import SHELL')
MODULE().Import('from klib.IP import IP')
MODULE().Import('from klib.CONVERT import CONVERT')
MODULE().Import('import uuid')


class HOST:
    def __init__(self):
        pass

    def Name(self):
        return socket.gethostname()

    def NetIp(self, ifname):
        if os.path.isdir('/sys/class/net/{}'.format(ifname)) is False:
            return False
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            return socket.inet_ntoa(
                fcntl.ioctl(
                    s.fileno(),
                    0x8915,  # SIOCGIFADDR
                    struct.pack('256s', ifname[:15]))[20:24])
        except:
            try:
Exemple #3
0
#!/bin/python
# -*- coding: utf-8 -*-
# Kage personal stuff
#
from __future__ import print_function
import sys, os, re, copy
import tarfile
import tempfile
from os import close, remove
import random
import hashlib
from klib.MODULE import MODULE
MODULE().Import('from klib.Type import Type')
MODULE().Import('from klib.CONVERT import CONVERT')
MODULE().Import('from klib.GET import GET')
MODULE().Import('from klib.STR import STR')
MODULE().Import('from klib.OutFormat import OutFormat')
MODULE().Import('from klib.Abs import Abs')
MODULE().Import('from klib.Crc import Crc')
MODULE().Import('from klib.FILE import FILE')
#MODULE().Import('from klib.Get import Get')

ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
url_group = re.compile('^(https|http|ftp)://([^/\r\n]+)(/[^\r\n]*)?')
log_intro = 3
log_new_line = '\n'

cdrom_ko = [
    'sr_mod', 'cdrom', 'libata', 'ata_piix', 'ata_generic', 'usb-storage'
]
Exemple #4
0
#Kage Park
import syslog
from klib.MODULE import MODULE

MODULE().Import('from klib.Type import Type')
MODULE().Import('from klib.GET import GET')


class LOG:
    def __init__(self, src, log_limit=3, log_file=None, log_file_mode='a+'):
        self.src = src
        self.log_limit = log_limit
        self.log_file = log_file
        self.log_file_mode = log_file_mode

    def Format(self, *msg, **opts):
        log_date_format = opts.get('date_format', '[%m/%d/%Y %H:%M:%S]')
        func_name = opts.get('func_name', False)
        log_intro = opts.get('log_intro', 3)
        end_new_line = opts.get('end_new_line', '')
        start_new_line = opts.get('start_new_line', '\n')
        if len(msg) > 0:
            m_str = None
            intro = ''
            intro_space = ''
            if log_date_format:
                intro = format_time(tformat=log_date_format) + ' '
            if func_name or log_intro > 3:
                if type(func_name) is str:
                    intro = intro + '{0} '.format(func_name)
                else:
Exemple #5
0
#!/bin/python
# -*- coding: utf-8 -*-
# Kage personal stuff
#
from __future__ import print_function
import sys
import re
import ast
from pprint import pprint
from klib.MODULE import MODULE
MODULE().Import('from klib.Type import Type')
MODULE().Import('from klib.COLOR import COLOR')
MODULE().Import('from klib.STR import STR')


def space(space_num=0, _space_='   '):
    space_str = ''
    for ii in range(space_num):
        space_str = '{0}{1}'.format(space_str, _space_)
    return space_str


def printf(*msg, **opts):
    ansi_escape = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')
    color_db = opts.get(
        'color_db', {
            'blue': 34,
            'grey': 30,
            'yellow': 33,
            'green': 32,
            'cyan': 36,