# VNC password vnc_password = '' for i in range(9): vnc_password = vnc_password + random.choice(string.ascii_lowercase + string.ascii_lowercase) # VNC key vnc_key = generate_key(vnc_password) data.update({'RemoteDisplay.vnc.enabled': 'TRUE', 'RemoteDisplay.vnc.port': vnc_port, 'RemoteDisplay.vnc.password': vnc_password, 'RemoteDisplay.vnc.key': vnc_key}) # Prepare template for arg in data: template = append(template, '\n', space(arg, '='), '"', data[arg], '"') if 'mikrotik' in os_name: template = template.replace('scsi0', 'ide0') # Status write('status', '2:25') def delete(serve, machine): request = VI.Destroy_TaskRequestMsg() _this = request.new__this(machine._mor) _this.set_attribute_type(machine._mor.get_attribute_type()) request.set_element__this(_this)
except: response(False) if online: try: machine.power_off() except: response(False) try: machine.set_extra_config(settings) except: response(False) try: machine.power_on() except: response(False) # VNC address vnc_address = append(server_address, ':', first) try: os.system( space('bash', path(base, '..', '..', '..', 'web/console/utils/launch.sh'), '--vnc', vnc_address, '--listen', port, '> /dev/null 2>&1 &')) except: response(False) response(True, {'password': password})
output = result.output try: addresses = re.findall('(\d+\.\d+\.\d+\.\d+)', output) except: response(False) servers = {} for address in addresses: servers[address] = 0 for address in servers: try: result = ssh.run(['sh', '-c', space('esxcli network vm list | grep', address, "| awk '{print$1}' | xargs esxcli network vm port list -w | sed -e 's/Port\ ID://g' | head -n1 | awk '{print$1}' | xargs esxcli network port stats get -p")]) except: continue output = result.output try: stats = re.findall('Bytes\s*.*?\:\s*([0-9]+)', output) except Exception: continue try: first = stats.pop() except: continue
output = result.output try: result = re.search(append('([0-9]+).*', address, '.*'), output) except: response(False) machine = result.group(1) if not machine: response(False) try: result = ssh.run( ['sh', '-c', space('vim-cmd', 'vmsvc/get.summary', machine)]) except: response(False) output = result.output def get_property(name): try: result = re.search(append(name, '\s*=\s*([0-9]+)\,'), output) except: return None return result.group(1)