本文整理汇总了Python中host.Host.create方法的典型用法代码示例。如果您正苦于以下问题:Python Host.create方法的具体用法?Python Host.create怎么用?Python Host.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类host.Host
的用法示例。
在下文中一共展示了Host.create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Openstack
# 需要导入模块: from host import Host [as 别名]
# 或者: from host.Host import create [as 别名]
class Openstack(object):
'''
The class definition for operations related to 'Openstack'.
'''
#Commonly used URIs for the 'Openstack' module
URI_HOST_SEARCH = '/compute/hosts/search?name={0}'
URI_HOST_BULK = '/compute/hosts/bulk'
URI_NETWORK_BULK = '/vdc/networks/bulk'
URI_NETWORK_PORTS = '/vdc/networks/{0}/storage-ports'
URI_STORAGEPORT_ALL = '/vdc/storage-ports'
URI_STORAGEPORT_BULK = '/vdc/storage-ports/bulk'
VIPR_CONFIG_FILE = '/etc/cinder/cinder.conf'
def __init__(self, ipAddr, port, verbose):
'''
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._host = Host(self.__ipAddr, self.__port)
self._hostinitiator = HostInitiator(self.__ipAddr, self.__port)
self._network = Network(self.__ipAddr, self.__port)
self._execute = utils.execute
self._vipr_info = ViPRInfo(self.VIPR_CONFIG_FILE)
self.set_logging(verbose)
def set_logging(self, verbose):
self._logger = logging.getLogger(__name__)
if (verbose):
self._logger.setLevel(logging.DEBUG)
else:
self._logger.setLevel(logging.INFO)
logging.basicConfig(format='%(asctime)s:%(levelname)s: %(message)s')
def get_logger(self):
return self._logger
def get_hostname(self, hostname = None):
if (not hostname):
return socket.getfqdn()
else:
return hostname
def get_vipr_info(self):
return self._vipr_info
#@retry_wrapper
def add_host(self, host_param, connector, vipr_param):
self._vipr_info.authenticate_user()
varray = vipr_param['varray']
# Find or create host.
host = self.create_host(host_param['hostname'], vipr_param['tenant'], vipr_param['project'])
self._logger.info('Created/found host %s', host['name'])
self._logger.debug('Details of host %s: %s', host_param['hostname'], host)
# Find or create initiator.
initiator = self.create_initiator(host, connector)
self._logger.info('Added initiator %s to host %s', initiator['initiator_port'], host['name'])
self._logger.debug('Details of initiator %s', initiator)
# Find network
network = self.find_iscsi_network(vipr_param['varray'], vipr_param['network'])
if (network):
self._logger.info('Found network %s in virtual array %s', network['name'], varray)
else:
self._logger('Cannot find a network in virtual array %s to place the initiator', varray)
exit(1)
# add initiator to network
if (initiator['initiator_port'] not in network['endpoints']):
self.add_initiator_to_network(host, initiator, network, vipr_param['varray'])
self._logger.info('Added initiator %s to network %s', initiator['initiator_port'], network['name'])
self._logger.debug('Network details %s: ', network)
@vipr_retry_wrapper
def create_host(self, hostname, tenant, project, ostype='Linux'):
# find host
host = self.find_host(hostname)
if (not host):
if (not ostype) :
ostype = "Linux"
# host not found, create a new one.
task_rep = self._host.create(hostname, ostype, hostname, tenant, None, None, None, None, None, None, None, None, None)
host = common.show_by_href(self.__ipAddr, self.__port, task_rep['resource'])
return host
'''
Find host by name of host object in ViPR, normally the hostname of the host.
Parameters:
name: name of the host
Returns:
host details in JSON
'''
def find_host(self, hostname):
shortname = hostname[:hostname.find(".")]
#.........这里部分代码省略.........