Module virt
[hide private]
[frames] | no frames]

Source Code for Module virt

  1  # 
  2  # Copyright (c) 2008--2013 Red Hat, Inc. 
  3  # 
  4  # This software is licensed to you under the GNU General Public License, 
  5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
  6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
  8  # along with this software; if not, see 
  9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
 10  # 
 11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
 12  # granted to use or replicate Red Hat trademarks that are incorporated 
 13  # in this software or its documentation. 
 14  # 
 15   
 16  import sys 
 17  from virtualization import support, errors 
 18   
 19  __rhnexport__ = [ 
 20      'refresh', 
 21      'shutdown', 
 22      'suspend', 
 23      'start', 
 24      'resume', 
 25      'reboot', 
 26      'destroy', 
 27      'setMemory', 
 28      'setVCPUs', 
 29      'schedulePoller'] 
 30   
 31  ## 
 32  # Refreshes the virtualization info for this host and any subdomains on the 
 33  # server. 
 34  # 
35 -def refresh(cache_only=None):
36 if cache_only: 37 return (0, "no-ops for caching", {}) 38 try: 39 support.refresh() 40 except errors.VirtualizationException: 41 ve = sys.exc_info()[1] 42 return (1, str(ve), {}) 43 return (0, "Virtualization Info refreshed.", {})
44
45 -def shutdown(uuid, cache_only=None):
46 if cache_only: 47 return (0, "no-ops for caching", {}) 48 try: 49 support.shutdown(uuid) 50 except errors.VirtualizationException: 51 ve = sys.exc_info()[1] 52 return (1, str(ve), {}) 53 return (0, "Domain %s shutdown." % str(uuid), {})
54
55 -def start(uuid, cache_only=None):
56 if cache_only: 57 return (0, "no-ops for caching", {}) 58 try: 59 support.start(uuid) 60 except errors.VirtualizationException: 61 ve = sys.exc_info()[1] 62 return (1, str(ve), {}) 63 return (0, "Domain %s started." % str(uuid), {})
64
65 -def suspend(uuid, cache_only=None):
66 if cache_only: 67 return (0, "no-ops for caching", {}) 68 try: 69 support.suspend(uuid) 70 except errors.VirtualizationException: 71 ve = sys.exc_info()[1] 72 return (1, str(ve), {}) 73 return (0, "Domain %s suspended." % str(uuid), {})
74
75 -def resume(uuid, cache_only=None):
76 if cache_only: 77 return (0, "no-ops for caching", {}) 78 try: 79 support.resume(uuid) 80 except errors.VirtualizationException: 81 ve = sys.exc_info()[1] 82 return (1, str(ve), {}) 83 return (0, "Domain %s resumed." % str(uuid), {})
84
85 -def reboot(uuid, cache_only=None):
86 if cache_only: 87 return (0, "no-ops for caching", {}) 88 try: 89 support.reboot(uuid) 90 except errors.VirtualizationException: 91 ve = sys.exc_info()[1] 92 return (1, str(ve), {}) 93 return (0, "Domain %s rebooted." % str(uuid), {})
94
95 -def destroy(uuid, cache_only=None):
96 if cache_only: 97 return (0, "no-ops for caching", {}) 98 try: 99 support.destroy(uuid) 100 except errors.VirtualizationException: 101 ve = sys.exc_info()[1] 102 return (1, str(ve), {}) 103 return (0, "Domain %s destroyed." % str(uuid), {})
104
105 -def setMemory(uuid, memory, cache_only=None):
106 if cache_only: 107 return (0, "no-ops for caching", {}) 108 try: 109 support.setMemory(uuid, memory) 110 except errors.VirtualizationException: 111 ve = sys.exc_info()[1] 112 return (1, str(ve), {}) 113 return (0, "Memory set to %s on %s." % (str(memory), str(uuid)), {})
114
115 -def setVCPUs(uuid, vcpus, cache_only=None):
116 if cache_only: 117 return (0, "no-ops for caching", {}) 118 try: 119 support.setVCPUs(uuid, vcpus) 120 except errors.VirtualizationException: 121 ve = sys.exc_info()[1] 122 return (1, str(ve), {}) 123 return (0, "VCPUs set to %s on %s." % (str(vcpus), str(uuid)), {})
124
125 -def schedulePoller(minute, hour, dom, month, dow, cache_only=None):
126 if cache_only: 127 return (0, "no-ops for caching", {}) 128 ret_val = support.schedulePoller(minute, hour, dom, month, dow) 129 return (ret_val[0], ret_val[1], {})
130 131 ############################################################################### 132 # Test Routine 133 ############################################################################### 134 135 if __name__ == "__main__": 136 import sys 137 import actions.virt 138 func = getattr(actions.virt, sys.argv[1]) 139 print(func(*tuple(sys.argv[2:]))) 140