本文整理汇总了Python中mcvirt.utils.get_hostname函数的典型用法代码示例。如果您正苦于以下问题:Python get_hostname函数的具体用法?Python get_hostname怎么用?Python get_hostname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_hostname函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
def delete(self, local_only=False):
"""Delete the logical volume for the disk"""
vm_object = self.get_virtual_machine()
# Ensure that the user has permissions to add delete storage
self._get_registered_object('auth').assert_permission(
PERMISSIONS.MODIFY_HARD_DRIVE,
vm_object
)
# If the storage backend is available on one to more nodes,
# ensure that the hard drive exists. Prefer local host
check_node = get_hostname() if get_hostname() in self.nodes else self.nodes[0]
if self._is_cluster_master or check_node == get_hostname():
self.ensure_exists(nodes=[check_node])
if vm_object:
vm_object.ensureUnlocked()
vm_object.ensure_stopped()
# Remove the hard drive from the MCVirt VM configuration
self.get_attachment_object().delete(local_only=local_only)
# Remove backing storage
self._removeStorage(local_only=local_only)
# Remove config
nodes = [get_hostname()] if local_only else self._get_registered_object(
'cluster').get_nodes(include_local=True)
self.remove_config(nodes=nodes)
示例2: create_id_volume
def create_id_volume(self, nodes=None):
"""Create identification volume on the storage backend"""
# Obtain volume object for ID volume
volume = self.get_volume(self._id_volume_name)
# If the storage backend is shared, then only needs to be created on
# a single node (prefer local host if in list of nodes). If not shared,
# ID volume will be created on all nodes
if nodes is None:
nodes = ([get_hostname()]
if get_hostname() in self.nodes else
[self.nodes[0]]) if self.shared else self.nodes
try:
# Create ID volume
volume.create(size=2 ** 20, nodes=nodes)
except ExternalStorageCommandErrorException:
raise ExternalStorageCommandErrorException(
('An error occured whilst adding storage backend: Either the storage '
'backend has no free space (at least 1MB required) or '
'shared storage is being used, but has not been specified'))
try:
# Ensure that ID volume exists on all nodes
volume.ensure_exists(nodes=self.nodes)
except VolumeDoesNotExistError:
raise ExternalStorageCommandErrorException(
('An error ocurred whilst verifying the storage backend: '
'A shared storage has been specified, but it is not'))
示例3: pre_check_network
def pre_check_network(self, name, interface):
"""Perform pre-limiary checks on node before determining
that a network can be added"""
self._get_registered_object('auth').assert_user_type('ConnectionUser', 'ClusterUser')
# Ensure that the physical interface exists
self.assert_interface_exists(interface)
# Ensure that there are no interfaces present on the MCVirt instance
# that match the network
if self.check_exists(name):
raise NetworkAlreadyExistsException('Network already exists on node: %s %s' %
(name, get_hostname()))
# Ensure that there is not already a network with the same name defined in
# libvirt
try:
self._get_registered_object(
'libvirt_connector'
).get_connection().networkLookupByName(name)
# If the libvirt connect did not throw an error that
# the network does not exist, raise an exception
# as the network must be pressent
# @TODO: do this more nicely. Get list of networks and
# assert that it's not in the list
raise NetworkAlreadyExistsException(
'Network already defined in libvirt on node: %s %s' %
(name, get_hostname()))
except libvirtError:
pass
示例4: undo
def undo(self):
"""Execute the undo method for the function"""
# If the local node is in the list of complete
# commands, then undo it first
if (get_hostname() in self.nodes and
self.nodes[get_hostname()]['complete'] and
hasattr(self.obj, self._undo_function_name)):
# Set current node
local_hostname = get_hostname()
self.current_node = local_hostname
Syslogger.logger().debug('Undo %s %s %s %s' %
(get_hostname(),
self._undo_function_name,
str(self.nodes[get_hostname()]['args']),
str(self.nodes[get_hostname()]['kwargs'])))
getattr(self.obj, self._undo_function_name)(
*self.nodes[get_hostname()]['args'],
**self.nodes[get_hostname()]['kwargs'])
# Iterate through nodes and undo
for node in self.nodes:
# Skip local node or if the function did not complete on the node
if node == get_hostname() or not self.nodes[node]['complete']:
continue
# Run the remote undo method
Syslogger.logger().debug('Undo %s %s %s %s' %
(node,
self.function.__name__,
str(self.nodes[node]['args']),
str(self.nodes[node]['kwargs'])))
self._call_function_remote(node=node, undo=True)
示例5: delete_id_volume
def delete_id_volume(self, nodes=None):
"""Delete the ID volume for the storage backend"""
# Obtain volume object for ID volume
volume = self.get_volume(self._id_volume_name)
# If the storage backend is shared, then only needs to be created on
# a single node (prefer local host if in list of nodes). If not shared,
# ID volume will be created on all nodes
if nodes is None:
nodes = ([get_hostname()]
if get_hostname() in self.nodes else
[self.nodes[0]]) if self.shared else self.nodes
# Create ID volume
volume.delete(nodes=nodes)
示例6: add_node_configuration
def add_node_configuration(self, node_name, ip_address,
connection_user, connection_password,
ca_key):
"""Add MCVirt node to configuration, generates a cluster user on the remote node
and stores credentials against node in the MCVirt configuration.
"""
self._get_registered_object('auth').assert_permission(PERMISSIONS.MANAGE_CLUSTER)
# Create CA file
ssl_object = self._get_registered_object(
'certificate_generator_factory').get_cert_generator(node_name)
ssl_object.ca_pub_file = ca_key
# Connect to node and obtain cluster user
remote = Connection(username=connection_user, password=connection_password,
host=node_name)
remote_user_factory = remote.get_connection('user_factory')
connection_user = remote_user_factory.get_user_by_username(connection_user)
remote.annotate_object(connection_user)
username, password = connection_user.create_cluster_user(host=get_hostname())
# Add node to configuration file
def add_node_config(mcvirt_config):
mcvirt_config['cluster']['nodes'][node_name] = {
'ip_address': ip_address,
'username': username,
'password': password
}
MCVirtConfig().update_config(add_node_config)
示例7: get_remote_factory
def get_remote_factory(self, node=None):
if node is None or node == get_hostname():
return self
node = self._get_registered_object('cluster').get_remote_node(node)
remote_factory = node.get_connection('iso_factory')
node.annotate_object(remote_factory)
return remote_factory
示例8: gitRemove
def gitRemove(self, message='', custom_file=None):
"""Remove and commits a configuration file"""
if self._checkGitRepo():
session_obj = self._get_registered_object('mcvirt_session')
username = ''
user = None
if session_obj:
try:
user = session_obj.get_proxy_user_object()
except UserDoesNotExistException:
pass
if user:
username = session_obj.get_proxy_user_object().get_username()
message += "\nUser: %s\nNode: %s" % (username, get_hostname())
try:
System.runCommand([self.GIT,
'rm',
'--cached',
self.config_file],
cwd=DirectoryLocation.BASE_STORAGE_DIR)
System.runCommand([self.GIT, 'commit', '-m', message],
cwd=DirectoryLocation.BASE_STORAGE_DIR)
System.runCommand([self.GIT,
'push'],
raise_exception_on_failure=False,
cwd=DirectoryLocation.BASE_STORAGE_DIR)
except Exception:
pass
示例9: __init__
def __init__(self):
"""Store required object member variables and create MCVirt object"""
# Initialise Pyro4 with flag to showing that the daemon is being started
Pyro4.current_context.STARTUP_PERIOD = True
# Store nameserver, MCVirt instance and create daemon
self.daemon_lock = DaemonLock()
Pyro4.config.USE_MSG_WAITALL = False
Pyro4.config.CREATE_SOCKET_METHOD = SSLSocket.create_ssl_socket
Pyro4.config.CREATE_BROADCAST_SOCKET_METHOD = SSLSocket.create_broadcast_ssl_socket
Pyro4.config.THREADPOOL_ALLOW_QUEUE = True
Pyro4.config.THREADPOOL_SIZE = 128
self.hostname = get_hostname()
# Ensure that the required SSL certificates exist
ssl_socket = CertificateGeneratorFactory().get_cert_generator('localhost')
ssl_socket.check_certificates(check_client=False)
ssl_socket = None
# Wait for nameserver
self.obtain_connection()
RpcNSMixinDaemon.DAEMON = BaseRpcDaemon(host=self.hostname)
self.register_factories()
# Ensure libvirt is configured
cert_gen_factory = RpcNSMixinDaemon.DAEMON.registered_factories[
'certificate_generator_factory']
cert_gen = cert_gen_factory.get_cert_generator('localhost')
cert_gen.check_certificates()
cert_gen = None
cert_gen_factory = None
示例10: ensure_active
def ensure_active(self):
"""Ensure that voljuem is active, otherwise, raise exception"""
if not self.is_active():
raise VolumeIsNotActiveException(
'Volume %s is not active on %s' %
(self.name, get_hostname())
)
示例11: getAllVmNames
def getAllVmNames(self, node=None):
"""Returns a list of all VMs within the cluster or those registered on a specific node"""
if node is not None:
ArgumentValidator.validate_hostname(node)
# If no node was defined, check the local configuration for all VMs
if node is None:
return [vm['name'] for vm in VirtualMachineConfig.get_global_config().values()]
elif node == get_hostname():
# @TODO - Why is this using libvirt?! Should use
# VM objects (i.e. config file to determine)
# and use a seperate function to get libvirt
# registered VMs
# Obtain array of all domains from libvirt
all_domains = self._get_registered_object(
'libvirt_connector').get_connection().listAllDomains()
return [vm.name() for vm in all_domains]
else:
# Return list of VMs registered on remote node
cluster = self._get_registered_object('cluster')
def remote_command(node_connection):
"""Get virtual machine names from remote node"""
virtual_machine_factory = node_connection.get_connection('virtual_machine_factory')
return virtual_machine_factory.getAllVmNames(node=node)
return cluster.run_remote_command(callback_method=remote_command, nodes=[node])[node]
示例12: get_all
def get_all(self, available_on_local_node=None, nodes=[], drbd=None,
storage_type=None, shared=None, nodes_predefined=False,
global_=None, default_location=None):
"""Return all storage backends, with optional filtering"""
storage_objects = []
for storage_id in self.get_config().keys():
# Obtain storage object
storage_object = self.get_object(storage_id)
# Check if storage backend is global or not
if global_ is not None and storage_object.is_global != global_:
continue
# Check if default location matches requested
if (default_location is not None and
storage_object.get_location(return_default=True) != default_location):
continue
# Check storage is available on local node
if (available_on_local_node and
get_hostname() not in storage_object.nodes):
continue
# If nodes are specified...
if nodes:
# Determine which nodes from the list are available
available_nodes = []
for node in nodes:
if node in storage_object.nodes:
available_nodes.append(node)
# If the list of nodes is required (predefined) and not all are
# present, skip storage backend
if nodes_predefined and len(nodes) != len(available_nodes):
continue
# Otherwise, (if the nodes are not required), ensure at least one
# is available, otherwise, skip
elif (not nodes_predefined) and not len(available_nodes):
continue
# If drbd is specified, ensure storage object is suitable to run DRBD
if drbd and not storage_object.is_drbd_suitable():
continue
# If storage_type is specified, ensure hat storage matches the object
if storage_type and not self.get_class(storage_type) != storage_object.__class__:
continue
# If a shared type is defined, determine if it matches the object, otherwise skip
if shared is not None and shared != storage_object.shared:
continue
# If all checks have passed, append to list of objects to return
storage_objects.append(storage_object)
return storage_objects
示例13: node_pre_check
def node_pre_check(cls, cluster, libvirt_config, location):
"""Ensure volume group exists on node"""
try:
cls.ensure_exists(location)
except InvalidStorageConfiguration, exc:
raise InvalidStorageConfiguration(
'%s on node %s' % (str(exc), get_hostname())
)
示例14: ensure_available
def ensure_available(self):
"""Ensure that the storage backend is currently available on the node"""
volume = self.get_volume(self._id_volume_name)
if (not self.check_exists()) or not volume.check_exists():
raise StorageBackendNotAvailableOnNode(
'Storage backend %s is not currently avaialble on node: %s' % (
self.name, get_hostname()))
示例15: insert_into_stat_db
def insert_into_stat_db(self):
"""Add statistics to statistics database"""
db_factory = self._get_registered_object('database_factory')
db_rows = [
(StatisticsDeviceType.HOST.value, get_hostname(),
StatisticsStatType.CPU_USAGE.value, self._cpu_usage,
"{:%s}".format(datetime.now())),
(StatisticsDeviceType.HOST.value, get_hostname(),
StatisticsStatType.MEMORY_USAGE.value, self._memory_usage,
"{:%s}".format(datetime.now()))
]
with db_factory.get_locking_connection() as db_inst:
db_inst.cursor.executemany(
"""INSERT INTO stats(
device_type, device_id, stat_type, stat_value, stat_date
) VALUES(?, ?, ?, ?, ?)""",
db_rows)