def map_ci_resource(sid, rt_name):
    connect = uSysDB.connect()
    cursor = connect.cursor()
    cursor.execute("SELECT rt_id FROM resource_types WHERE rt_id in(SELECT rt_id FROM subs_resources WHERE sub_id = '%s') AND restype_name = '%s'" % sid, rt_name)
    cursor.close()
    connect.close()
    return cursor.fetchall()[0][0]
def generate_update(sub_id, rt_id, delta):
    connect = uSysDB.connect()
    cursor = connect.cursor()
    cursor.execute(
        "SELECT rt_instance_id FROM subs_resources WHERE rt_id = '%s' AND sub_id = '%s'" % (rt_id, sub_id))
    rti_id = cursor.fetchall()[0][0]
    cursor.close()
    connect.close()
    return "INSERT INTO resources_usage_log (rti_id, sub_id, time_from, time_to, usage_alter) values ('%s', '%s', '%s', '%s', '%s')" % (rti_id, sub_id, '2015-05-14', '2015-06-14', delta)
Пример #3
0
 def get_backnet_from_db(host_id, backnet_ip):
     con = uSysDB.connect()
     cur = con.cursor()
     cur.execute(
         "select ip_address::inet & netmask::inet, netmask::inet from configured_ips where ip_address::inet=%s::inet and host_id = %s",
         backnet_ip, host_id)
     rec = cur.fetchone()
     if not rec:
         raise NetworkNotFound(host_id, backnet_ip)
     return IPNetwork(rec[0] + '/' + rec[1])
Пример #4
0
    def get_ip_pool(self, name):
        """Get IP pool from database

        :returns: pool_id
        """
        con = uSysDB.connect()
        cur = con.cursor()
        cur.execute("SELECT pool_id, pool_name FROM ip_pools")
        pools = cur.fetchall()
        con.close()
        for pool in pools:
            if name == pool[1]:
                return pool[0]
        return None
Пример #5
0
def getHostsToUpdate(binfo, hosts, upgrade_instructions, newest_packages):
    newAgentHosts = []
    newPackagesHosts = []
    if not hosts: return newAgentHosts, newPackagesHosts
    newAgent = uSlaveUpdater.is_need_to_update_paagent(binfo)
    con = uSysDB.connect()
    for host in hosts:
        if uRoutines.getPkgsToInstall(con, host.host_id, upgrade_instructions,
                                      newest_packages):
            newAgentHosts.append(host)  # required to update repourl
            newPackagesHosts.append(host)
        elif newAgent:
            newAgentHosts.append(host)
    return newAgentHosts, newPackagesHosts
Пример #6
0
 def create_prov_brand(self, domain, exclusive_ip=False):
     con = uSysDB.connect()
     cur = con.cursor()
     cur.execute("SELECT brand_id FROM brands WHERE brand_name='" + str(domain) + "'")
     brand_id = cur.fetchall()
     con.close()
     if brand_id:
         return brand_id
     else:
         if exclusive_ip:
             brand_id = self.api_async_call_wait('pem.brandDomain',domain_name=domain,ip_type='exclusive')
         else:
             brand_id = self.api_async_call_wait('pem.brandDomain',domain_name=domain,ip_type='shared')
         return brand_id
Пример #7
0
    def get_ip_pool(self, name):
        """Get IP pool from database

        :returns: pool_id
        """
        con = uSysDB.connect()
        cur = con.cursor()
        cur.execute("SELECT pool_id, pool_name FROM ip_pools")
        pools = cur.fetchall()
        con.close()
        for pool in pools:
            if name == pool[1]:
                return pool[0]
        return None
Пример #8
0
def init():
    pba.init(bm_root)
    bapi = pba.pbaapi.PBAAPIRaw()

    dbconfig = DBConfig(pba.conf.get('environment', 'DB_HOST'),
                        pba.conf.get('environment', 'DB_NAME'),
                        pba.conf.get('environment', 'DB_USER'),
                        pba.conf.get('environment', 'DB_PASSWD'), 'PGSQL')
    uSysDB.init(dbconfig)
    con = uSysDB.connect()

    oaapihost, oaapiport = bapi.PEMGATE.PEMOptionsGet()['Result'][0]
    oaapihost = oaapihost.replace(" ", "")
    oapi = OaApi(oaapihost, oaapiport)

    return bapi, oapi, con
Пример #9
0
 def create_prov_brand(self, domain, exclusive_ip=False):
     con = uSysDB.connect()
     cur = con.cursor()
     cur.execute("SELECT brand_id FROM brands WHERE brand_name='" +
                 str(domain) + "'")
     brand_id = cur.fetchall()
     con.close()
     if brand_id:
         return brand_id
     else:
         if exclusive_ip:
             brand_id = self.api_async_call_wait('pem.brandDomain',
                                                 domain_name=domain,
                                                 ip_type='exclusive')
         else:
             brand_id = self.api_async_call_wait('pem.brandDomain',
                                                 domain_name=domain,
                                                 ip_type='shared')
         return brand_id
Пример #10
0
    def detect_proxy():
        privoxy = uPackaging.listInstalledPackages('PrivacyProxy', 'other')
        if not privoxy:
            return None
        privoxy_component = privoxy[0].component_id
        proxy_ip, proxy_port = None, None
        con = uSysDB.connect()
        cur = con.cursor()
        cur.execute(
            "select name, value from v_props where name in ('privoxy.backnet_ip', 'privoxy.port') and component_id=%s",
            privoxy_component)
        for name, value in cur.fetchall():
            if name == 'privoxy.backnet_ip':
                proxy_ip = str(value)
            elif name == 'privoxy.port':
                proxy_port = str(value)

        if proxy_ip and proxy_port:
            return 'http://%s:%s' % (proxy_ip, proxy_port)
        return None
Пример #11
0
    def get_host_ips(self, host_id):
        """Get host IPs and NICs from database

        :returns: [[ip, if_id],..]
        """
        con = uSysDB.connect()
        cur = con.cursor()
        cur.execute(
            """SELECT ip_address, if_id
            FROM configured_ips
            WHERE host_id = %s""", (host_id, ))
        ip0_ifs = cur.fetchall()
        con.close()
        # strip leading 0s from octets
        # 010 -> 10
        # 000 -> 0 !! The last zero should stay!
        ip_ifs = []
        for ip0, if_id in ip0_ifs:
            ip = '.'.join([o0.lstrip('0') or '0' for o0 in ip0.split('.')])
            ip_ifs.append([ip, if_id])
        return ip_ifs
Пример #12
0
    def get_host_ips(self, host_id):
        """Get host IPs and NICs from database

        :returns: [[ip, if_id],..]
        """
        con = uSysDB.connect()
        cur = con.cursor()
        cur.execute("""SELECT ip_address, if_id
            FROM configured_ips
            WHERE host_id = %s""",
            (host_id,))
        ip0_ifs = cur.fetchall()
        con.close()
        # strip leading 0s from octets
        # 010 -> 10
        # 000 -> 0 !! The last zero should stay!
        ip_ifs = []
        for ip0, if_id in ip0_ifs:
            ip = '.'.join([ o0.lstrip('0') or '0' for o0 in ip0.split('.')])
            ip_ifs.append([ip, if_id])
        return ip_ifs
#!/usr/bin/python

from poaupdater import uSysDB
from poaupdater import uLogging
from poaupdater import openapi

## Disable logging to the console
uLogging.log_to_console = False

## Show all tasks' numbers
con = uSysDB.connect()
cur = con.cursor()
print("\nThere are the following failed/rescheduled named tasks:")
cur.execute(
    "select task_id from tm_tasks where name like \'%pdate named%\' and status in ('f', 's')"
)
res = cur.fetchall()
for x in range(0, len(res)):
    print("--- %s ---" % res[x])

## Show all tasks with their outputs:
print("\nTask log for these tasks:")
cur.execute(
    "select task_id, action_output from tm_logs where task_id in (select task_id from tm_tasks where name like \'%pdate named%\' and status in ('f', 's'))"
)
res2 = cur.fetchall()
for x in range(0, len(res2)):
    print("Task #%s Output: \"%s\"" % (res2[x][0], res2[x][1]))

## Restart all of the tasks
print("\nPlease wait. The tasks are restarting...")
Пример #14
0
def _init(options):
    uLogging.init2(log_file='/var/log/pa/k8s.install.log',
                   log_file_rotation=False,
                   verbose=False)

    class PrintLogger(object):
        def __init__(self):
            self.terminal = sys.stdout

        def write(self, message):
            self.terminal.write(message)
            uLogging.debug(message)

        def flush(self):
            self.terminal.flush()

    sys.stdout = PrintLogger()

    uLogging.debug("Platform version is {0}".format(uPEM.get_major_version()))
    uLogging.debug("Command line %s " % (sys.argv))

    global _log_cmd, _log_stdout, _log_stderr

    def _log_cmd(msg):
        uLogging.info('\x1b[32m%s\x1b[0m' % msg)

    def _log_stdout(msg):
        uLogging.info(msg)

    def _log_stderr(msg):
        uLogging.info('\x1b[1m%s\x1b[0m', msg)

    global config
    config = uConfig.Config()
    openapi.initFromEnv(config)

    def use_option(key, attr, default=None, empty=True):
        if key in options:
            value = options[key]
            if value == "":
                value = empty
            setattr(config, attr, value)
        else:
            setattr(config, attr, default)

    use_option('--check', 'check')
    use_option('--install', 'install')
    use_option('--proxy', 'proxy', empty='')
    use_option('--dry-run', 'dry_run', False)
    use_option('--repo', 'prefix', default_helm_repo_prefix, empty='')
    use_option('--username', 'username', default_helm_repo_username, empty='')
    use_option('--password', 'password', default_helm_repo_password, empty='')
    use_option('--pod-network-cidr', 'pod_network_cidr',
               default_pod_networ_cidr)
    use_option('--service-cidr', 'service_cidr', default_service_cidr)

    uLogging.debug('Recognized config: \n' +
                   pprint.pformat(uUtil.stipPasswords(vars(config))))

    uSysDB.init(config)

    k8s_host = K8sHost(host_id=K8sHost.detectNodeInDB(uSysDB.connect()),
                       proxy=config.proxy,
                       dry_run=config.dry_run)
    k8s_host.set_network(pod_network_cidr=config.pod_network_cidr,
                         service_cidr=config.service_cidr)

    repo = Repo(prefix=config.prefix,
                username=config.username,
                password=config.password)

    return (k8s_host, repo)
Пример #15
0
__author__ = 'lexluter1988'
#!/bin/python

from poaupdater import uPEM, uSysDB, uLogging, uDBSchema, uPDLDBSchema, uDLModel, uUtil, uFakePackaging, uPackaging, uBuild, openapi, PEMVersion, uDialog, uCert

def map_public_incoming(sid)
    connect = uSysDB.connect()
    cursor = connect.cursor()
    cursor.execute("SELECT rt_id FROM resource_types WHERE rt_id in(SELECT rt_id FROM subs_resources WHERE sub_id = '%s') AND restype_name = 'CI iternal incoming traffic'" % sid)
    cursor.close()
    connect.close()
    return cursor.fetchall()[0][0]


def map_ci_resource(sid, rt_name):
    connect = uSysDB.connect()
    cursor = connect.cursor()
    cursor.execute("SELECT rt_id FROM resource_types WHERE rt_id in(SELECT rt_id FROM subs_resources WHERE sub_id = '%s') AND restype_name = '%s'" % sid, rt_name)
    cursor.close()
    connect.close()
    return cursor.fetchall()[0][0]


Пример #16
0
 def _getConnection(self):
     return uSysDB.connect()
                'resource_type_ids': [1000974, 1000975, 1000008, 1002129, 1000961, 1000962, 1002632, 1000956, 1000976, 1000963, 1000964, 1000959, 1000960, 1000958, 1002215, 1000970, 1000971, 1000967, 1000966, 1000972, 1000973, 1002213, 1002214, 1000968, 1000222, 1000223, 1000006],
                'from_time': 1427846401,
                'to_time': 1431475201}
    return api.execute('pem.getResourceUsageForPeriod', **params)

sub_id = int(sys.argv[1])
connection = connect_via_rpc("192.168.133.12")
api = Api(connection)

responce = get_resource_usage_for_period(sub_id,api)
rt_types_usg = responce['resource_type_usages']

for i in rt_types_usg:
    summa = 0
    print "resource_type_id:", i['resource_type_id']
    for j in i['usage_statistics']:
        summa += int(j['delta64'])
    print "usage:", summa



#!/bin/python

from poaupdater import uPEM, uSysDB, uLogging, uDBSchema, uPDLDBSchema, uDLModel, uUtil, uFakePackaging, uPackaging, uBuild, openapi, PEMVersion, uDialog, uCert

con = uSysDB.connect()
cur = con.cursor()
cur.execute("SELECT location_id FROM sc_instances")
cur.close()
con.close()