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


Python Error.response方法代码示例

本文整理汇总了Python中error.Error.response方法的典型用法代码示例。如果您正苦于以下问题:Python Error.response方法的具体用法?Python Error.response怎么用?Python Error.response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在error.Error的用法示例。


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

示例1: Utils

# 需要导入模块: from error import Error [as 别名]
# 或者: from error.Error import response [as 别名]
class Utils():
    
    # Class initializer
    def __init__(self):
        self.logger    = Logger()
        self.log       = self.logger.get_logger()
        self.log.info('Logger initialized')
        
        # Load the configuration file
        self.root      = os.path.abspath(os.path.join(os.path.realpath(__file__), '..', os.pardir))
        self.conf      = ConfigParser.ConfigParser()
        self.conf.read(self.root + '/cloud_init.ini')
        
        # Log configuration details
        self.log.info('Discovered cloud_init root: ' + self.root)
        self.log.info('Using configuration file: ' + self.root + '/cloud_init.ini')
        
        # Retrieve the callback server parameters
        self.cbs_host  = self.conf.get('callback', 'host')
        self.cbs_port  = self.conf.get('callback', 'port')
        self.cbs_proto = self.conf.get('callback', 'proto')
        self.cbs_path  = self.conf.get('callback', 'path')
        
        # Retrieve the metadata server parameters
        self.mds_host  = self.conf.get('metadata', 'host')
        self.mds_port  = self.conf.get('metadata', 'port')
        self.mds_proto = self.conf.get('metadata', 'proto')
        self.mds_path  = self.conf.get('metadata', 'path')
        
        # Get the cloud administrator account
        self.vm_admin  = self.conf.get('user', 'name')
        
        # Get the public and private network adapters
        self.if_pub    = self.conf.get('network', 'if_pub')
        self.if_priv   = self.conf.get('network', 'if_priv')
        self.ip_info   = None
        
        # Log the cloud administrator and IP information
        self.log.info('Using cloud administrator account: ' + self.vm_admin)
        self.log.info('Using network interfaces: public = ' + self.if_pub + ', private = ' + self.if_priv)
        
        # Root/administrator password
        self.passwd    = None
        
        # Define the callback and metadata server connect strings
        self.cbs       = "%s://%s:%s/%s/" % (self.cbs_proto, self.cbs_host, self.cbs_port, self.cbs_path)
        self.mds       = "%s://%s:%s/%s" % (self.mds_proto, self.mds_host, self.mds_port, self.mds_path)
        
        # Initialize the error handler
        self.error     = Error(self.cbs, self.log)
        
        # Retrieve core system properties
        self.sys_type  = platform.system()
        self.sys_arch  = platform.machine()
    
        # Log the callback and metadata servers, and machine information
        self.log.info('Using callback server: ' + self.cbs)
        self.log.info('Using metadata server: ' + self.mds)
        self.log.info('Discovered system type: ' + self.sys_type)
        self.log.info('Discovered system architecture: ' + self.sys_arch)
    
        # Linux instances
        if self.sys_type == 'Linux':
            
            # Find the OS type
            self.os_distro = platform.linux_distribution()
            self.os_type   = {'distro': self.os_distro[0],
                              'version': self.os_distro[1]}
            self.log.info('Discovered system OS distribution and version: ' + str(self.os_type))
                
        # Windows instances
        elif self.sys_type == 'Windows':
            
            # Find the windows version
            self.win32   = platform.win32_ver()
            self.os_type = {'distro': self.win32[0],
                            'version': self.win32[1]}
            self.log.info('Discovered system OS distribution and version: ' + str(self.os_type))
            
        # Invalid system type
        else:
            self.error(3, self.sys_type)
    
        # Try to fetch the metadata
        try:    self.meta_data = requests.get(self.mds)
        except: self.error.response(1)
    
        if self.os_type['distro'] == 'CentOS' \
        and re.match('^5\.[0-9]*$', self.os_type['version']):
            self.meta_json = self.meta_data.json
        else:
            self.meta_json = self.meta_data.json()
        self.meta_pass = None
    
        # Log the meta data JSON object
        self.log.info('Retrieved meta data JSON object: ' + str(self.meta_json))
    
    # Generate a random string of optional specified size
    def _rstring(self, size = 12):
        chars = string.ascii_uppercase + string.digits + string.ascii_lowercase
#.........这里部分代码省略.........
开发者ID:carriercomm,项目名称:VPLS-cloud-init,代码行数:103,代码来源:utils.py


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