Microsoft Hyper-V API

Published on Author Code Father1 Comment

How to connect Microsoft Hyper-v api:

What is Microsoft Hyper-V?

Microsoft Hyper-V is the latest virtualization product from Microsoft. The new hypervisor platform works with Windows Server 2008 to create and manage a virtual infrastructure. As with any virtualization platform, Hyper-V makes for a more efficient data center, maximizing resources and reducing costs.

Microsoft Hyper-V consists of a 64-bit hypervisor that can run 32-bit and 64-bit virtual machines concurrently. Hyper-V virtualization works with single and multi-processor virtual machines and includes tools such as snapshots, which capture the state of a running virtual machine.

Hypervisor-based virtualization with Microsoft’s newest offering promises more efficient virtual machine hosting as well, with new “synthetic” drivers.

Common methods are startVM([$id]), pauseVM([$id]) and stopVM([$id]).
$id are optional, if you have more VM’s, choose one…

Use the code below :


include_once('scm_curl.php');

$scmCurl = new scmCurl();
$scmCurl->panelurl('http://lllllllll.com/');
$scmCurl->username('somethingnotsecret');
$scmCurl->password('somethingsecret');

 if($_GET['action']=='start'){
  $scmCurl->startVM();
 }
 elseif($_GET['action']=='pause'){
  $scmCurl->pauseVM();
 }elseif($_GET['action']=='stop'){

$scmCurl->stopVM();

——————————————————————————————————
scm_curl.php

class scmCurl{

public $username = '';
public $password = '';
public $panelurl = 'http://llllllllllllllll.com/';
private $cookie = '';

 public function listVM(){
 return $this->getMachines();
 }

 public function startVM($id=0){
 if(empty($id)){
 $id = $this->getMachines();
 $id = $id[0];
 }

 $baseurl = $this->panelurl.'Service.asmx/StartVM';
 $cookiepage = $this->curlit($baseurl,false,true,true,'{"machineID":"'.$id.'"}');

 }

 public function pauseVM($id=0){
 if(empty($id)){
 $id = $this->getMachines();
 $id = $id[0];
 }

 $baseurl = $this->panelurl.'Service.asmx/PauseVM';
 $cookiepage = $this->curlit($baseurl,false,true,true,'{"machineID":"'.$id.'"}');

 }

 public function stopVM($id=0){
 if(empty($id)){
 $id = $this->getMachines();
 $id = $id[0];
 }

 $baseurl = $this->panelurl.'Service.asmx/StopVM';
 $cookiepage = $this->curlit($baseurl,false,true,true,'{"machineID":"'.$id.'"}');

 }

 private function getCookie(){
 $baseurl = $this->panelurl.'Default.aspx';
 $formpage = $this->curlit($baseurl,false,false,false,false,false);
 preg_match_all('#<input(.*type=.hidden.*)/>#isU',$formpage,$array,PREG_PATTERN_ORDER);
 $postargs='';
 foreach($array[1] as $arrayunique){
 $arrayunique1='';
 $arrayunique2='';
 preg_match_all('#name="(.*)"#isU',$arrayunique,$arrayunique1);
 preg_match_all('#value="(.*)"#isU',$arrayunique,$arrayunique2);
 $postargs = $postargs.$arrayunique1[1][0].'='.urlencode($arrayunique2[1][0]).'&';
 }

$postargs = $postargs.'rdoGrpPublicPrivate=rdoNoStoreCred&chkRememberChoice=on&loginControl%24UserName='.urlencode($this->username).'&loginControl%24Password='.urlencode($this->password).'&loginControl%24LoginButton=Se+connecter';

$cookiepage = $this->curlit($baseurl,true,true,false,$postargs,false);

preg_match_all('#Set-Cookie:(.*);#isU',$cookiepage,$cookie);
 $this->cookie = $cookie[1][0];
 return 1;
 }

private function curlit($url='',$header=false,$post=false,$json=false,$postfields=false,$getcookie=true){
 if(empty($url)){
 return -1;
 }

 $ch = curl_init();
 // -- If there's no cookies, creating one
 if($getcookie==true){
 if(empty($this->cookie)){
 $this->getCookie();}}

Comments

comments

One Response to Microsoft Hyper-V API

Leave a Reply

Your email address will not be published. Required fields are marked *