2525import six
2626from six .moves .urllib import parse
2727
28+ from novaclient import api_versions
2829from novaclient import base
2930from novaclient import crypto
3031from novaclient .i18n import _
@@ -661,6 +662,7 @@ def remove_floating_ip(self, server, address):
661662 address = address .ip if hasattr (address , 'ip' ) else address
662663 self ._action ('removeFloatingIp' , server , {'address' : address })
663664
665+ @api_versions .wraps ('2.0' , '2.5' )
664666 def get_vnc_console (self , server , console_type ):
665667 """
666668 Get a vnc console for an instance
@@ -672,6 +674,7 @@ def get_vnc_console(self, server, console_type):
672674 return self ._action ('os-getVNCConsole' , server ,
673675 {'type' : console_type })[1 ]
674676
677+ @api_versions .wraps ('2.0' , '2.5' )
675678 def get_spice_console (self , server , console_type ):
676679 """
677680 Get a spice console for an instance
@@ -683,6 +686,7 @@ def get_spice_console(self, server, console_type):
683686 return self ._action ('os-getSPICEConsole' , server ,
684687 {'type' : console_type })[1 ]
685688
689+ @api_versions .wraps ('2.0' , '2.5' )
686690 def get_rdp_console (self , server , console_type ):
687691 """
688692 Get a rdp console for an instance
@@ -694,6 +698,7 @@ def get_rdp_console(self, server, console_type):
694698 return self ._action ('os-getRDPConsole' , server ,
695699 {'type' : console_type })[1 ]
696700
701+ @api_versions .wraps ('2.0' , '2.5' )
697702 def get_serial_console (self , server , console_type ):
698703 """
699704 Get a serial console for an instance
@@ -705,6 +710,54 @@ def get_serial_console(self, server, console_type):
705710 return self ._action ('os-getSerialConsole' , server ,
706711 {'type' : console_type })[1 ]
707712
713+ @api_versions .wraps ('2.6' )
714+ def get_vnc_console (self , server , console_type ):
715+ """
716+ Get a vnc console for an instance
717+
718+ :param server: The :class:`Server` (or its ID) to add an IP to.
719+ :param console_type: Type of vnc console to get ('novnc' or 'xvpvnc')
720+ """
721+
722+ return self ._console (server ,
723+ {'protocol' : 'vnc' , 'type' : console_type })[1 ]
724+
725+ @api_versions .wraps ('2.6' )
726+ def get_spice_console (self , server , console_type ):
727+ """
728+ Get a spice console for an instance
729+
730+ :param server: The :class:`Server` (or its ID) to add an IP to.
731+ :param console_type: Type of spice console to get ('spice-html5')
732+ """
733+
734+ return self ._console (server ,
735+ {'protocol' : 'spice' , 'type' : console_type })[1 ]
736+
737+ @api_versions .wraps ('2.6' )
738+ def get_rdp_console (self , server , console_type ):
739+ """
740+ Get a rdp console for an instance
741+
742+ :param server: The :class:`Server` (or its ID) to add an IP to.
743+ :param console_type: Type of rdp console to get ('rdp-html5')
744+ """
745+
746+ return self ._console (server ,
747+ {'protocol' : 'rdp' , 'type' : console_type })[1 ]
748+
749+ @api_versions .wraps ('2.6' )
750+ def get_serial_console (self , server , console_type ):
751+ """
752+ Get a serial console for an instance
753+
754+ :param server: The :class:`Server` (or its ID) to add an IP to.
755+ :param console_type: Type of serial console to get ('serial')
756+ """
757+
758+ return self ._console (server ,
759+ {'protocol' : 'serial' , 'type' : console_type })[1 ]
760+
708761 def get_password (self , server , private_key = None ):
709762 """
710763 Get admin password of an instance
@@ -1277,3 +1330,11 @@ def _action(self, action, server, info=None, **kwargs):
12771330 self .run_hooks ('modify_body_for_action' , body , ** kwargs )
12781331 url = '/servers/%s/action' % base .getid (server )
12791332 return self .api .client .post (url , body = body )
1333+
1334+ def _console (self , server , info = None , ** kwargs ):
1335+ """
1336+ Retrieve a console of a particular protocol -- vnc/spice/rdp/serial
1337+ """
1338+ body = {'remote_console' : info }
1339+ url = '/servers/%s/remote-consoles' % base .getid (server )
1340+ return self .api .client .post (url , body = body )
0 commit comments