当前位置: 首页>>代码示例>>Python>>正文


Python util.Util类代码示例

本文整理汇总了Python中lib.util.Util的典型用法代码示例。如果您正苦于以下问题:Python Util类的具体用法?Python Util怎么用?Python Util使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __query_server

    def __query_server(url, params=None):
        try:
            url_params = urllib.urlencode(params) if params else None

            if ETR.proxy:
                proxy_handler = urllib2.ProxyHandler({'http': ETR.proxy})
                opener = urllib2.build_opener(proxy_handler)
                urllib2.install_opener(opener)

            ws = urllib2.urlopen(url, url_params, timeout=ETR.timeout)
            response = ws.read()
            ws.close()

            return response

        except Exception, e:
            if hasattr(e, 'reason'):
                text = 'Error al intentar abrir la URL del host: ' + str(e.reason)
            else:
                text = 'Error al intentar abrir la URL del host: Tiempo de espera agotado'

            try:
                Util.write_error_log(getattr(params, 'linea'), getattr(params, 'parada'), text)
            except Exception, e:
                print 'Error al intentar guardar en el registro.'
开发者ID:stabora,项目名称:cuandollega,代码行数:25,代码来源:etr.py

示例2: infer

    def infer(self, params):
        window = {'tweets':[], 'start':0} # storing tweets

        """ User distribution updating """
        for tweet in self.tweets.stream():
            if type(tweet) == type({}) and 'timestamp' in tweet:
                current_time = Util.str_to_unixtime(Util.time_to_str(tweet['timestamp']))
                window['tweets'].append(tweet)
                if current_time - window['start'] > params['window_size']:
                    if params['tl']:
                        """ use tl-words """
                        tlwords = self.extract_local_words_(window['tweets'], params)
                    else:
                        """ dont use tl-words """
                        tlwords = Words()
                    self.update_user_distributions(window['tweets'], tlwords, params)
                    window = {'tweets':[], 'start':current_time}

        """ Location prediction using user distribution """
        for user in self.users.iter():
            if user['location_point'] == None:
                """ unlabeled user """
                if user['id'] in self.user_distributions and len(self.user_distributions[user['id']]) > 0:
                    inferred_city = self.predict(self.user_distributions[user['id']], params)
                    inferred_location = self.model.means_[inferred_city]
                    user['location_point'] = inferred_location
                else:
                    if params['default']:
                        """ no clues            """
                        """ predict using prior """
                        inferred_city = self.predict({}, params)
                        inferred_location = self.model.means_[inferred_city]
                        user['location_point'] = inferred_location
开发者ID:yamaguchiyuto,项目名称:location_inference,代码行数:33,代码来源:olimg.py

示例3: create_eth_if_in_service_profile

def create_eth_if_in_service_profile(ucsm_ssh, param, eth_cnt):
    test_bed = str(param['test_bed_id'])
    chassis = str(param['chassis_id'])
    cartridge = str(param['cartridge_id'])
    server = str(param['server_id'])
    
    param['tag_service_profile_name'] = get_service_profile_name(chassis, cartridge, server)
    
    current_eth_cnt = 0
    data_vlan_start = int(test_bed) * 100 + 20 + 3
    data_vlan_end   = data_vlan_start + eth_cnt
    eth_vlan_list = range(data_vlan_start, data_vlan_end)
    eth_vlan_list.insert(0, VLAN_ISCSI)
    eth_vlan_list.insert(0, VLAN_MEDUSA)
    eth_vlan_list.insert(0, VLAN_PXE)
    for eth_vlan in eth_vlan_list: 
        eth_id = str(current_eth_cnt).zfill(2) 
        param['tag_mac_address'] = get_mac_address(test_bed, chassis, cartridge, server, eth_id)
        param["tag_eth_name"] = ''.join([param["eth_pxe_name_prefix"], str(eth_vlan)])
        param["tag_eth_vlan"] = 'vlan' + str(eth_vlan)
        param['tag_eth_order'] = str(int(current_eth_cnt) + 1)
        if current_eth_cnt % 2 == 0:
            param["tag_eth_fabric"] = 'a'
        else:
            param["tag_eth_fabric"] = 'b'
        #pprint.pprint(param)
        file_text_step = Define.PATH_SNIC_TEXT_UCSM + "service_profile_eth_vlan.txt"   
        Util.run_text_step(ucsm_ssh, file_text_step, param)
        current_eth_cnt += 1
        if current_eth_cnt >= eth_cnt: 
            break
开发者ID:huhe56,项目名称:nj-snic,代码行数:31,代码来源:__init__.py

示例4: predict

    def predict(self, user_id):
        min_d = 100000000
        min_p = None
        p = self.user_locations[user_id]
        for follower_id in self.graph.get_followers(user_id):
            follower = self.users.get(follower_id)
            if follower != None:
                follower_p = follower['location_point']
                if follower_p != None:
                    d = Util.hubeny_distance(follower_p, p)
                    if min_d > d:
                        min_d = d
                        min_p = follower_p
        for friend_id in self.graph.get_friends(user_id):
            friend = self.users.get(friend_id)
            if friend != None:
                friend_p = friend['location_point']
                if friend_p != None:
                    d = Util.hubeny_distance(friend_p, p)
                    if min_d > d:
                        min_d = d
                        min_p = friend_p 
        for venue_name in self.venues.get_venues(user_id):
            venue_p = self.venues.get_point(venue_name)
            d = Util.hubeny_distance(venue_p, p)
            if min_d > d:
                min_d = d
                min_p = venue_p 


        return min_p
开发者ID:yamaguchiyuto,项目名称:location_inference,代码行数:31,代码来源:udi.py

示例5: create_iscsi_in_service_profile

def create_iscsi_in_service_profile(ucsm_ssh, param):
    test_bed = str(param['test_bed_id'])
    chassis = str(param['chassis_id'])
    cartridge = str(param['cartridge_id'])
    server = str(param['server_id'])
    param['tag_service_profile_name'] = get_service_profile_name(chassis, cartridge, server)
    file_text_step = Define.PATH_SNIC_TEXT_UCSM + "service_profile_iscsi.txt"   
    Util.run_text_step(ucsm_ssh, file_text_step, param)
开发者ID:huhe56,项目名称:nj-snic,代码行数:8,代码来源:__init__.py

示例6: execute_cmd

def execute_cmd(ucsm_ssh, param):
    chassis = str(param['chassis_id'])
    cartridge = str(param['cartridge_id'])
    server = str(param['server_id'])
    
    param['tag_service_profile_name'] = get_service_profile_name(chassis, cartridge, server)
    file_text_step = Define.PATH_SNIC_TEXT_UCSM + "service_profile_deletion.txt"   
    Util.run_text_step(ucsm_ssh, file_text_step, param)
开发者ID:huhe56,项目名称:nj-snic,代码行数:8,代码来源:__init__.py

示例7: reuse_local_lun

def reuse_local_lun(ucsm_ssh, param):
    chassis = str(param['chassis_id'])
    cartridge = str(param['cartridge_id'])
    server = str(param['server_id'])
    
    param['tag_service_profile_name'] = get_service_profile_name(chassis, cartridge, server)
    file_text_step = Define.PATH_SNIC_TEXT_UCSM + "local_lun_reuse.txt"   
    Util.run_text_step(ucsm_ssh, file_text_step, param)
开发者ID:huhe56,项目名称:nj-snic,代码行数:8,代码来源:__init__.py

示例8: stop_medusa

 def stop_medusa(self):
     file_json_step = Define.PATH_SNIC_JSON_LINUX + "medusa_stop.json"
     Util.run_step_list(self._ssh, file_json_step)
     
 
     
 
     
     
开发者ID:huhe56,项目名称:nj-snic,代码行数:3,代码来源:node_compute.py

示例9: start_medusa

 def start_medusa(self, lun_type):
     file_json_step = None
     if lun_type == 1:
         file_json_step = Define.PATH_SNIC_JSON_LINUX + "medusa_start_boot_lun.json"
     elif lun_type == 2:
         file_json_step = Define.PATH_SNIC_JSON_LINUX + "medusa_start_data_lun.json"
     elif lun_type == 3:
         file_json_step = Define.PATH_SNIC_JSON_LINUX + "medusa_start_all_lun.json"
         
     Util.run_step_list(self._ssh, file_json_step)
开发者ID:huhe56,项目名称:nj-snic,代码行数:10,代码来源:node_compute.py

示例10: create_ipmi_in_service_profile

def create_ipmi_in_service_profile(ucsm_ssh, param):
    chassis = str(param['chassis_id'])
    cartridge = str(param['cartridge_id'])
    server = str(param['server_id'])
    
    server_full_list = [chassis, cartridge, server]
    param['tag_service_profile_name'] = get_service_profile_name(chassis, cartridge, server)
    param['tag_server_full_id'] = '/'.join(server_full_list)
    
    file_text_step = Define.PATH_SNIC_TEXT_UCSM + "service_profile_ipmi.txt"   
    Util.run_text_step(ucsm_ssh, file_text_step, param)
开发者ID:huhe56,项目名称:nj-snic,代码行数:11,代码来源:__init__.py

示例11: power_cycle_service_profile

def power_cycle_service_profile(ucsm_ssh, param, wait=False):
    chassis = str(param['chassis_id'])
    cartridge = str(param['cartridge_id'])
    server = str(param['server_id'])
    
    param['tag_service_profile_name'] = get_service_profile_name(chassis, cartridge, server)
    param['tag_power_cycle_timing'] = 'immediate'
    if wait:
        param['tag_power_cycle_timing'] = 'wait'
    file_text_step = Define.PATH_SNIC_TEXT_UCSM + "service_profile_power_cycle.txt"   
    Util.run_text_step(ucsm_ssh, file_text_step, param)
开发者ID:huhe56,项目名称:nj-snic,代码行数:11,代码来源:__init__.py

示例12: set_vnic_no_vlan_in_service_profile

def set_vnic_no_vlan_in_service_profile(ucsm_ssh, param, vlan_number_list):
    test_bed = str(param['test_bed_id'])
    chassis = str(param['chassis_id'])
    cartridge = str(param['cartridge_id'])
    server = str(param['server_id'])
    param['tag_service_profile_name'] = get_service_profile_name(chassis, cartridge, server)
    
    for vlan_number in vlan_number_list:
        param['tag_eth_name'] = 'eth' + str(vlan_number)
        param['tag_vlan_name'] = 'vlan' + str(vlan_number)
        file_text_step = Define.PATH_SNIC_TEXT_UCSM + "service_profile_vnic_no_vlan.txt"   
        Util.run_text_step(ucsm_ssh, file_text_step, param)
开发者ID:huhe56,项目名称:nj-snic,代码行数:12,代码来源:__init__.py

示例13: set_server_ext_mgmt_ip

def set_server_ext_mgmt_ip(ucsm_ssh, param):
    file_text_step = Define.PATH_SNIC_TEXT_UCSM + "server_ext_mgmt_ip.txt"   
    ip_list = get_ip_list(param['tag_kvm_ip_start'], 16)
    for chassis_id, chassis in config.iteritems():
        if chassis_id != 1: continue
        for cartridge_id, cartridge in chassis.iteritems():
            for server_id, server in cartridge.iteritems():
                param['tag_server_id']   = '/'.join([str(chassis_id), str(cartridge_id), str(server_id)])
                param['tag_addr']        = ip_list.pop()
                param['tag_default_gw']  = param['tag_kvm_ip_gateway']
                param['tag_subnet']      = param['tag_kvm_ip_netmask']
                Util.run_text_step(ucsm_ssh, file_text_step, param)
开发者ID:huhe56,项目名称:nj-snic,代码行数:12,代码来源:__init__.py

示例14: set_vnic_adapter_policy_in_service_profile

def set_vnic_adapter_policy_in_service_profile(ucsm_ssh, param, adapter_policy_dict):
    test_bed = str(param['test_bed_id'])
    chassis = str(param['chassis_id'])
    cartridge = str(param['cartridge_id'])
    server = str(param['server_id'])
    param['tag_service_profile_name'] = get_service_profile_name(chassis, cartridge, server)
    
    for eth_name, adapter_policy in adapter_policy_dict.iteritems():
        param['tag_eth_name'] = eth_name
        param['tag_adapter_policy'] = adapter_policy
        file_text_step = Define.PATH_SNIC_TEXT_UCSM + "service_profile_vnic_adapter_policy.txt"   
        Util.run_text_step(ucsm_ssh, file_text_step, param)
开发者ID:huhe56,项目名称:nj-snic,代码行数:12,代码来源:__init__.py

示例15: create_boot_policy

def create_boot_policy(ucsm_ssh, param):
    
    param['tag_boot_policy'] = 'disk-pxe-legacy'
    param['tag_boot_mode'] = 'legacy'
    
    file_text_step = Define.PATH_SNIC_TEXT_UCSM + "boot_policy_order_disk_pxe.txt"   
    Util.run_text_step(ucsm_ssh, file_text_step, param)
    
    param['tag_boot_policy'] = 'disk-pxe-uefi'
    param['tag_boot_mode'] = 'uefi'
    
    file_text_step = Define.PATH_SNIC_TEXT_UCSM + "boot_policy_order_disk_pxe.txt"   
    Util.run_text_step(ucsm_ssh, file_text_step, param)
    
    param['tag_boot_policy'] = 'iscsi-pxe-legacy'
    param['tag_boot_mode'] = 'legacy'
    
    file_text_step = Define.PATH_SNIC_TEXT_UCSM + "boot_policy_order_iscsi_pxe.txt"   
    Util.run_text_step(ucsm_ssh, file_text_step, param)
    
    param['tag_boot_policy'] = 'iscsi-pxe-uefi'
    param['tag_boot_mode'] = 'uefi'
    
    file_text_step = Define.PATH_SNIC_TEXT_UCSM + "boot_policy_order_iscsi_pxe.txt"   
    Util.run_text_step(ucsm_ssh, file_text_step, param)
开发者ID:huhe56,项目名称:nj-snic,代码行数:25,代码来源:__init__.py


注:本文中的lib.util.Util类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。