Package archipel :: Module archipelVirtualMachine :: Class TNArchipelVirtualMachine
[hide private]
[frames] | no frames]

Class TNArchipelVirtualMachine

source code

                                                              object --+    
                                                                       |    
                            archipelcore.archipelEntity.TNArchipelEntity --+
                                                                           |
                                                              object --+   |
                                                                       |   |
                    archipelcore.archipelHookableEntity.TNHookableEntity --+
                                                                           |
                                                              object --+   |
                                                                       |   |
archipelcore.archipelAvatarControllableEntity.TNAvatarControllableEntity --+
                                                                           |
                                                              object --+   |
                                                                       |   |
                    archipelcore.archipelTaggableEntity.TNTaggableEntity --+
                                                                           |
                                                              object --+   |
                                                                       |   |
      archipelcore.archipelRosterQueryableEntity.TNRosterQueryableEntity --+
                                                                           |
                                                                          TNArchipelVirtualMachine

This class represents an Virtual Machine, XMPP Capable. This class needs to already have .... end of story ? TODO fix the details

Instance Methods [hide private]
 
__init__(self, jid, password, hypervisor, configuration, name, organizationInfo)
Contructor of the class.
source code
 
set_custom_vcard_information(self, vCard)
Put custom information in vCard
source code
 
get_custom_vcard_information(self, vCard)
Read custom info from vCard
source code
 
init_vocabulary(self)
This method registers for user messages.
source code
 
init_permissions(self)
Initialize the permissions.
source code
 
add_vm_definition_hook(self, method)
Add a new definition hook.
source code
 
register_handlers(self)
This method registers the events handlers.
source code
 
unregister_handlers(self)
Unregister the handlers.
source code
 
remove_folder(self)
Remove the folder of the virtual with all its contents.
source code
 
rename_virtual_machine(self, newname, publish=True)
Rename the virtual machine with the given name.
source code
 
set_automatic_libvirt_description(self, xmldesc)
Set the XML description's description of the VM.
source code
 
set_presence_according_to_libvirt_info(self)
Set XMPP status according to libvirt status.
source code
 
connect_domain(self, origin=None, user_info=None, arguments=None)
Initialize the connection to the libvirt first, and then to the domain by looking the uuid used as JID Node.
source code
 
on_domain_event(self, event, detail)
Called when a libvirt event is triggered.
source code
 
add_jid_hook(self, origin=None, user_info=None, arguments=None)
Hook to add a JID.
source code
 
define_hook(self, origin=None, user_info=None, arguments=None)
Hook for defining on hook
source code
 
control_create_hook(self, origin=None, user_info=None, arguments=None)
Hook for creating (starting) the vm
source code
 
_listen_migration_progress(self)
Will periodically update the VM XMPP status with the migration progress
source code
 
__process_iq_archipel_control(self, conn, iq)
Invoked when new archipel:vm:control IQ is received.
source code
 
__process_iq_archipel_definition(self, conn, iq)
Invoked when new archipel:define IQ is received.
source code
 
create(self)
Create the domain.
source code
 
shutdown(self)
Shutdown the domain.
source code
 
destroy(self)
Destroy the domain.
source code
 
reboot(self)
Reboot the domain.
source code
 
suspend(self)
Suspend (pause) the domain.
source code
 
resume(self)
Resume (unpause) the domain.
source code
string
screenshot(self, thumbnail=True, screen=0)
take a screenshot of the virtualmachine and return image as base64encoded PNG
source code
 
cputime_sampling_timer(self, interval)
Create a threaded timer to take timestamp,cputime samples from actual domain
source code
 
compute_cpu_usage(self)
Return the vm CPU usage in percent between two samples
source code
 
info(self)
Return info of a domain.
source code
 
network_info(self)
Get network statistics on the domain.
source code
 
setMemory(self, value)
Set memory value for running domain.
source code
 
memoryTimer(self, requestedMemory, retry=3)
Timer called by setMemory() to check if action has been done.
source code
 
setVCPUs(self, value)
Set the number of CPU for the domain.
source code
 
setAutostart(self, flag)
Set autostart for the domain.
source code
xmpp.Node
xmldesc(self, mask_description=True)
Get the XML description of the domain.
source code
xmpp.Node
define(self, xmldesc, sender=None)
Define the domain from given XML description.
source code
 
undefine(self)
Undefine the domain.
source code
 
undefine_and_disconnect(self)
Undefine the domain and disconnect from XMPP.
source code
 
clone(self, origin, user_info, parameters)
Clone a vm from another user_info is a dict that contains following keys:
source code
 
migrate(self, destination_jid)
Migrate a virtual machine from this host to another.
source code
 
migrate_running_step1(self, destination_jid)
This step asks for the destination_jid hypervisor what is his libvirt uri.
source code
 
migrate_running_step2(self, conn, resp)
Once received the remote hypervisor URI, start libvirt migration in a thread.
source code
 
migrate_running_step3(self, remote_hypervisor_uri)
Perform the migration.
source code
 
migrate_not_running_step1(self, destination_jid)
Migrate vm which is not running.
source code
 
migrate_not_running_step2(self, conn, resp)
After vm thread has been started and vm has been defined remotely, free locally.
source code
 
free(self)
Will run the hypervisor to free virtual machine.
source code
 
set_organization_info(self, organizationInfo, publish=True)
Set the vCard fields for the organization
source code
 
perform_threaded_cloning(self, src_path, newxml, parentvm)
Perform threaded copy of the virtual machine and then define it.
source code
 
terminate(self, clean_files=True)
This method is called by hypervisor when VM is freed.
source code
xmpp.Protocol.Iq
iq_migrate(self, iq)
Handle the migration request.
source code
xmpp.Protocol.Iq
iq_create(self, iq)
Create a domain using libvirt connection.
source code
xmpp.Protocol.Message
message_create(self, msg)
Handle message creation order.
source code
xmpp.Protocol.Iq
iq_shutdown(self, iq)
Shutdown a domain using libvirt connection.
source code
xmpp.Protocol.Message
message_shutdown(self, msg)
Handle message shutdown order.
source code
xmpp.Protocol.Iq
iq_destroy(self, iq)
Destroy a domain using libvirt connection.
source code
xmpp.Protocol.Message
message_destroy(self, msg)
Handle message destroy order.
source code
xmpp.Protocol.Iq
iq_reboot(self, iq)
Reboot a domain using libvirt connection.
source code
xmpp.Protocol.Message
message_reboot(self, msg)
Handle message reboot order.
source code
xmpp.Protocol.Iq
iq_suspend(self, iq)
Suspend (pause) a domain using libvirt connection.
source code
xmpp.Protocol.Message
message_suspend(self, msg)
Handle message suspend order.
source code
xmpp.Protocol.Iq
iq_resume(self, iq)
Resume (unpause) a domain using libvirt connection.
source code
xmpp.Protocol.Message
message_resume(self, msg)
Handle message resume order.
source code
xmpp.Protocol.Iq
iq_info(self, iq)
Return an IQ containing the info of the domain using libvirt connection.
source code
xmpp.Protocol.Message
message_info(self, msg)
Handle message info order.
source code
xmpp.Protocol.Iq
iq_xmldesc(self, iq)
Get the XML Desc of the virtual machine.
source code
xmpp.Protocol.Message
message_xmldesc(self, msg)
Handle message xmldesc order.
source code
xmpp.Protocol.Iq
iq_define(self, iq)
Define a virtual machine in the libvirt according to the XML data.
source code
xmpp.Protocol.Iq
iq_undefine(self, iq)
Undefine a virtual machine in the libvirt according to the XML data.
source code
xmpp.Protocol.Iq
iq_autostart(self, iq)
Set if machine should start with host.
source code
xmpp.Protocol.Iq
iq_memory(self, iq)
Balloon memory.
source code
xmpp.Protocol.Iq
iq_setvcpus(self, iq)
Set number of virtual cpus.
source code
xmpp.Protocol.Iq
iq_networkinfo(self, iq)
Return info about network.
source code
xmpp.Protocol.Message
message_networkinfo(self, msg)
Handle the message that asks for network information.
source code
xmpp.Protocol.Iq
iq_capabilities(self, iq)
Send the virtual machine's hypervisor capabilities.
source code
xmpp.Protocol.Iq
iq_nodeinfo(self, iq)
Send the virtual machine's hypervisor node informations.
source code
xmpp.Protocol.Message
message_insult(self, msg)
Handle insulting message.
source code
xmpp.Protocol.Message
message_hello(self, msg)
Handle the hello message.
source code
xmpp.Protocol.Iq
iq_setcpuspin(self, iq)
Set number of virtual cpus.
source code
xmpp.Protocol.Iq
iq_free(self, iq)
Free a virtual machine in the libvirt according to the XML data.
source code
xmpp.Protocol.Iq
iq_screenshot(self, iq)
Returns base64 encoded screenshot of the screen of the virtual machine
source code

Inherited from archipelcore.archipelEntity.TNArchipelEntity: add_jid, add_message_registrar_item, add_message_registrar_items, auth_xmpp, authorize, build_help, build_reply, change_presence, change_status, check_acp, check_perm, connect, connect_xmpp, did_receive_vcard, disconnect, filter_message, get_plugin, inband_registration, inband_unregistration, initialize_modules, iq_add_subscription, iq_get_permission, iq_list_permission, iq_remove_subscription, iq_set_permission, is_subscribed, loop, manage_vcard, on_new_admin_account_publication, process_inband_unregistration, process_message, process_permission_iq, process_presence, process_subscription_iq, push_change, recover_pubsubs, remove_jid, remove_pubsubs, send_update_vcard, set_vcard, shout, subscribe, unauthorize, unsubscribe

Inherited from archipelcore.archipelHookableEntity.TNHookableEntity: create_hook, perform_hooks, register_hook, remove_hook, unregister_hook

Inherited from archipelcore.archipelAvatarControllableEntity.TNAvatarControllableEntity: b64avatar_from_filename, get_available_avatars, iq_get_available_avatars, iq_set_available_avatars, process_avatar_iq, set_avatar

Inherited from archipelcore.archipelTaggableEntity.TNTaggableEntity: did_clean_old_tags, iq_set_tags, process_tags_iq, set_tags

Inherited from archipelcore.archipelRosterQueryableEntity.TNRosterQueryableEntity: iq_get_roster, message_roster, process_roster_iq

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, jid, password, hypervisor, configuration, name, organizationInfo)
(Constructor)

source code 

Contructor of the class.

Parameters:
  • jid - the jid of the client.
  • password - the password of the JID account.
  • configuration - the configuration object
  • name - the name of the entity
  • auto_register - if rTue, entity will try to create a XMPP account if needed
  • auto_reconnect - if True, entity will try to reconnect if disconnected
Overrides: object.__init__

init_vocabulary(self)

source code 

This method registers for user messages.

Overrides: archipelcore.archipelRosterQueryableEntity.TNRosterQueryableEntity.init_vocabulary

init_permissions(self)

source code 

Initialize the permissions.

Overrides: archipelcore.archipelRosterQueryableEntity.TNRosterQueryableEntity.init_permissions

add_vm_definition_hook(self, method)

source code 

Add a new definition hook. Methods registered here will be executed (random order) in order to let modules a chance to edit the XML description. The method will get the root <domain/> XML node and *MUST* return it.

Parameters:
  • method (function) - the method to run before defining the VM

register_handlers(self)

source code 

This method registers the events handlers. It is invoked by super class xmpp_connect() method.

Overrides: archipelcore.archipelRosterQueryableEntity.TNRosterQueryableEntity.register_handlers

unregister_handlers(self)

source code 

Unregister the handlers.

Overrides: archipelcore.archipelRosterQueryableEntity.TNRosterQueryableEntity.unregister_handlers

rename_virtual_machine(self, newname, publish=True)

source code 

Rename the virtual machine with the given name.

Parameters:
  • newname (String) - the new name of the VM
  • publish (Boolean) - If True, the vCard with new name will be published right away

connect_domain(self, origin=None, user_info=None, arguments=None)

source code 

Initialize the connection to the libvirt first, and then to the domain by looking the uuid used as JID Node. Exit on any error.

on_domain_event(self, event, detail)

source code 

Called when a libvirt event is triggered.

Parameters:
  • conn (libvirt.connection) - the libvirt connection
  • event (int) - the event
  • detail (int) - the detail associated to the event

__process_iq_archipel_control(self, conn, iq)

source code 

Invoked when new archipel:vm:control IQ is received. It understands IQ of type:

  • info
  • create
  • shutdown
  • destroy
  • reboot
  • suspend
  • resume
  • xmldesc
  • migrate
  • autostart
  • memory
  • networkinfo
Parameters:
  • conn (xmpp.Dispatcher) - ths instance of the current connection that send the message
  • iq (xmpp.Protocol.Iq) - the received IQ

__process_iq_archipel_definition(self, conn, iq)

source code 

Invoked when new archipel:define IQ is received. It understands IQ of type:

  • define (the domain xml must be sent as payload of IQ, and the uuid *MUST*, be the same as the JID of the client)
  • undefine (undefine a virtual machine domain)
  • capabilities
Parameters:
  • conn (xmpp.Dispatcher) - ths instance of the current connection that send the message
  • iq (xmpp.Protocol.Iq) - the received IQ

screenshot(self, thumbnail=True, screen=0)

source code 

take a screenshot of the virtualmachine and return image as base64encoded PNG

Parameters:
  • thumbnail (Boolean) - if True, will send a thumbnail of the screenshot
Returns: string
base64 encoded PNG data

setMemory(self, value)

source code 

Set memory value for running domain.

Parameters:
  • value (int) - the new amount of memory

memoryTimer(self, requestedMemory, retry=3)

source code 

Timer called by setMemory() to check if action has been done.

Parameters:
  • requestedMemory (int) - the requested memory amount to check
  • retry (int) - number of retry before considering the action has failed

setVCPUs(self, value)

source code 

Set the number of CPU for the domain.

Parameters:
  • value (int) - number of CPU to use

setAutostart(self, flag)

source code 

Set autostart for the domain.

Parameters:
  • flag (int) - the value of autostart (1 or 0)

xmldesc(self, mask_description=True)

source code 

Get the XML description of the domain.

Returns: xmpp.Node
the XML description

define(self, xmldesc, sender=None)

source code 

Define the domain from given XML description.

Parameters:
  • xmldesc (xmpp.Node) - the XML description
Returns: xmpp.Node
the XML description

clone(self, origin, user_info, parameters)

source code 

Clone a vm from another user_info is a dict that contains following keys:

  • definition : the xml object containing the libvirt definition
  • path : the vm path to clone (will clone * in it)
  • parentvm : the origin virtual machine object
Parameters:
  • origin (TNArchipelEntity) - the origin of the hook
  • user_info (object) - random user info
  • parameters (object) - runtime arguments

migrate(self, destination_jid)

source code 

Migrate a virtual machine from this host to another. This step check is virtual machine can be migrated. Then ask for the destination_jid hypervisor what is his libvirt uri.

perform_threaded_cloning(self, src_path, newxml, parentvm)

source code 

Perform threaded copy of the virtual machine and then define it.

Parameters:
  • src_path (string) - the path of the folder of the origin VM
  • newxml (xmpp.Node) - the origin XML description
  • parentvm (TNArchipelVirtualMachine) - the parent virtual machine object

terminate(self, clean_files=True)

source code 

This method is called by hypervisor when VM is freed. It will perform HOOK_VM_TERMINATE, close databases, close libvirt connection and remove own folder.

Parameters:
  • clean_files (boolean) - if True, remove the permission file and folder

iq_migrate(self, iq)

source code 

Handle the migration request.

Parameters:
  • iq (xmpp.Protocol.Iq) - the iq containing request information
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

iq_create(self, iq)

source code 

Create a domain using libvirt connection.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

message_create(self, msg)

source code 

Handle message creation order.

Parameters:
  • msg (xmpp.Protocol.Message) - the received message
Returns: xmpp.Protocol.Message
a ready to send Message containing the result of the action

iq_shutdown(self, iq)

source code 

Shutdown a domain using libvirt connection.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

message_shutdown(self, msg)

source code 

Handle message shutdown order.

Parameters:
  • msg (xmpp.Protocol.Message) - the received message
Returns: xmpp.Protocol.Message
a ready to send Message containing the result of the action

iq_destroy(self, iq)

source code 

Destroy a domain using libvirt connection.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

message_destroy(self, msg)

source code 

Handle message destroy order.

Parameters:
  • msg (xmpp.Protocol.Message) - the received message
Returns: xmpp.Protocol.Message
a ready to send Message containing the result of the action

iq_reboot(self, iq)

source code 

Reboot a domain using libvirt connection.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

message_reboot(self, msg)

source code 

Handle message reboot order.

Parameters:
  • msg (xmpp.Protocol.Message) - the received message
Returns: xmpp.Protocol.Message
a ready to send Message containing the result of the action

iq_suspend(self, iq)

source code 

Suspend (pause) a domain using libvirt connection.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

message_suspend(self, msg)

source code 

Handle message suspend order.

Parameters:
  • msg (xmpp.Protocol.Message) - the received message
Returns: xmpp.Protocol.Message
a ready to send Message containing the result of the action

iq_resume(self, iq)

source code 

Resume (unpause) a domain using libvirt connection.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

message_resume(self, msg)

source code 

Handle message resume order.

Parameters:
  • msg (xmpp.Protocol.Message) - the received message
Returns: xmpp.Protocol.Message
a ready to send Message containing the result of the action

iq_info(self, iq)

source code 

Return an IQ containing the info of the domain using libvirt connection.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

message_info(self, msg)

source code 

Handle message info order.

Parameters:
  • msg (xmpp.Protocol.Message) - the received message
Returns: xmpp.Protocol.Message
a ready to send Message containing the result of the action

iq_xmldesc(self, iq)

source code 

Get the XML Desc of the virtual machine.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

message_xmldesc(self, msg)

source code 

Handle message xmldesc order.

Parameters:
  • msg (xmpp.Protocol.Message) - the received message
Returns: xmpp.Protocol.Message
a ready to send Message containing the result of the action

iq_define(self, iq)

source code 

Define a virtual machine in the libvirt according to the XML data. domain passed in argument

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

iq_undefine(self, iq)

source code 

Undefine a virtual machine in the libvirt according to the XML data. domain passed in argument

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

iq_autostart(self, iq)

source code 

Set if machine should start with host.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

iq_memory(self, iq)

source code 

Balloon memory.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

iq_setvcpus(self, iq)

source code 

Set number of virtual cpus.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

iq_networkinfo(self, iq)

source code 

Return info about network.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

message_networkinfo(self, msg)

source code 

Handle the message that asks for network information.

Parameters:
  • msg (xmpp.Protocol.Message) - the received message
Returns: xmpp.Protocol.Message
a ready to send Message containing the result of the action

iq_capabilities(self, iq)

source code 

Send the virtual machine's hypervisor capabilities.

Parameters:
  • iq (xmpp.Protocol.Iq) - the sender request IQ
Returns: xmpp.Protocol.Iq
a ready-to-send IQ containing the results

iq_nodeinfo(self, iq)

source code 

Send the virtual machine's hypervisor node informations.

Parameters:
  • iq (xmpp.Protocol.Iq) - the sender request IQ
Returns: xmpp.Protocol.Iq
a ready-to-send IQ containing the results

message_insult(self, msg)

source code 

Handle insulting message.

Parameters:
  • msg (xmpp.Protocol.Message) - the received message
Returns: xmpp.Protocol.Message
a ready to send Message containing the result of the action

message_hello(self, msg)

source code 

Handle the hello message.

Parameters:
  • msg (xmpp.Protocol.Message) - the received message
Returns: xmpp.Protocol.Message
a ready to send Message containing the result of the action

iq_setcpuspin(self, iq)

source code 

Set number of virtual cpus.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

iq_free(self, iq)

source code 

Free a virtual machine in the libvirt according to the XML data.

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action

iq_screenshot(self, iq)

source code 

Returns base64 encoded screenshot of the screen of the virtual machine

Parameters:
  • iq (xmpp.Protocol.Iq) - the received IQ
Returns: xmpp.Protocol.Iq
a ready to send IQ containing the result of the action