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


Python Host.list_initiators方法代码示例

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


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

示例1: HostInitiator

# 需要导入模块: from host import Host [as 别名]
# 或者: from host.Host import list_initiators [as 别名]
class HostInitiator(object):
    # Indentation START for the class

    '''
    /compute/initiators/search
    /compute/initiators/{id}
    /compute/initiators/{id}/deactivate
    /compute/initiators/{id}/exports
    '''
    # All URIs for the Host Initiator operations
    URI_INITIATOR_DETAILS = "/compute/initiators/{0}"
    URI_INITIATOR_DETAILS_BULK = "/compute/initiators/bulk"
    URI_HOST_LIST_INITIATORS = "/compute/hosts/{0}/initiators"
    URI_INITIATOR_DEACTIVATE = "/compute/initiators/{0}/deactivate"

    INITIATOR_PROTOCOL_LIST = ['FC', 'iSCSI']

    __hostObject = None

    def __init__(self, ipAddr, port):
        '''
        Constructor: takes IP address and port of the ViPR instance. These are
        needed to make http requests for REST API
        '''
        self.__ipAddr = ipAddr
        self.__port = port
        self.__hostObject = Host(self.__ipAddr, self.__port)

    '''
    Returns the initiator URI for matching the name of the initiator
    '''

    def query_by_name(self, initiatorName, hostName):

        hostUri = self.get_host_uri(hostName)
        initiatorList = self.get_host_object().list_initiators(hostUri)

        # Match the name and return uri
        for initiator in initiatorList:
            if(initiator['name'] == initiatorName):
                return initiator['id']

        raise SOSError(
            SOSError.NOT_FOUND_ERR,
            "Initiator with name '" +
            initiatorName +
            "' not found")

    '''
    Returns the initiator URI for matching the name of the initiator
    '''

    def query_by_portwwn(self, initiatorWWN, hostName):

        hostUri = self.get_host_uri(hostName)
        initiatorList = self.get_host_object().list_initiators(hostUri)
       
        # Match the name and return uri
        for initiator in initiatorList:
            initiatorDetails = self.show_by_uri(initiator['id'])

            if(initiatorDetails and
               initiatorDetails['initiator_port'] == initiatorWWN):
                return initiator['id']

        raise SOSError(
            SOSError.NOT_FOUND_ERR,
            "Initiator with WWN '" +
            initiatorWWN +
            "' not found")

    """
    Initiator create operation
    """

    def create(self, sync, hostlabel, protocol, initiatorwwn, portwwn, initname):

        hostUri = self.get_host_uri(hostlabel)
        request = {'protocol': protocol,
                   'initiator_port': portwwn,
                   'name': initname
                   }

        if(initiatorwwn):
            request['initiator_node'] = initiatorwwn

        body = json.dumps(request)
      
        (s, h) = common.service_json_request(
            self.__ipAddr, self.__port,
            "POST",
            HostInitiator.URI_HOST_LIST_INITIATORS.format(hostUri),
            body)
        o = common.json_decode(s)
        return self.check_for_sync(o, sync)
        
        

    """
    Initiator update operation
#.........这里部分代码省略.........
开发者ID:cloudscaling,项目名称:coprhd-controller,代码行数:103,代码来源:hostinitiators.py

示例2: Openstack

# 需要导入模块: from host import Host [as 别名]
# 或者: from host.Host import list_initiators [as 别名]

#.........这里部分代码省略.........
        Returns:
            host details in JSON
    '''
    def find_host(self, hostname):
        shortname = hostname[:hostname.find(".")]
        (s, h) = common.service_json_request(self.__ipAddr, self.__port,
                                             "GET",
                                             self.URI_HOST_SEARCH.format(shortname), 
                                             None)
        o = common.json_decode(s);
        ids = []
        for host in o['resource'] :
            ids.append(host['id'])
    
        body = json.dumps({'id' : ids})    
        (s, h) = common.service_json_request(self.__ipAddr, self.__port,
                                             "POST",
                                             self.URI_HOST_BULK, 
                                             body)
        o = common.json_decode(s)
        for host in o['host']:
            if (host['inactive']):
                continue
            if (hostname in host['host_name'] or host['host_name'] in hostname ):
                return host
               
    def get_localhost_initiator(self, protocol='iSCSI'):
        if (protocol == 'iSCSI'):
            wwpn = libvirt_utils.get_iscsi_initiator()
            initiator = {'wwpn' : wwpn}
            return initiator
    
    def find_initiator(self, host, wwpn):
        initiators = self._host.list_initiators(host)
        for initiator in initiators:
            if (initiator['name'] == wwpn):
                return initiator
        return None    
    
    def create_initiator(self, host, connector):
        initiator = self.find_initiator(host['name'], connector['wwpn'])
        if (not initiator): 
            initiator = self._hostinitiator.create(host['name'], 'iSCSI', None, connector['wwpn'])
        return common.show_by_href(self.__ipAddr, self.__port, initiator)
    
    '''
        Find network for a given network name. If network name is not specified 
    '''
    def find_iscsi_network(self, varray, network_name):
        if (network_name):
            try:
                return self._network.network_query(network_name, varray)
            except SOSError:
                # TODO: re-raise the exception with correct name. To be removed
                raise SOSError(SOSError.NOT_FOUND_ERR, "Network {0} not found".format(network_name))
            
        storage_ports = self.get_varray_iscsi_storageports(varray)
        for port in storage_ports:
            port_info = dict()
            port_info['native_guid'] = port['native_guid']
            port_info['port_name'] = port['port_name']
            try:
                ip_address = port['ip_address'] 
                port_info['ip_address'] = ip_address             
                if (self.is_ip_pingable(ip_address)):
                    network = port['network']
开发者ID:tylerbaker,项目名称:controller-openstack-cinder,代码行数:70,代码来源:openstack.py


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