/**
  * @param  $instanceName
  * @param  $image
  * @param  $key
  * @param  $instanceType
  * @param  $groups
  * @return null|OpenStackNovaInstance
  */
 function createInstance($instanceName, $image, $key, $instanceType, $groups)
 {
     global $wgOpenStackManagerInstanceUserData;
     $data = array('server' => array());
     if ($key) {
         $data['key_name'] = $key;
     }
     $data['server']['flavorRef'] = $instanceType;
     $data['server']['imageRef'] = $image;
     $data['server']['name'] = $instanceName;
     if ($wgOpenStackManagerInstanceUserData) {
         $random_hash = md5(date('r', time()));
         $endl = OpenStackNovaController::getLineEnding();
         $boundary = '===============' . $random_hash . '==';
         $userdata = 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . $endl;
         $userdata .= 'MIME-Version: 1.0' . $endl;
         $boundary = '--' . $boundary;
         $userdata .= $endl;
         $userdata .= $boundary;
         if ($wgOpenStackManagerInstanceUserData['cloud-config']) {
             $userdata .= $endl . $this->getAttachmentMime(Spyc::YAMLDump($wgOpenStackManagerInstanceUserData['cloud-config']), 'text/cloud-config', 'cloud-config.txt');
             $userdata .= $endl . $boundary;
         }
         if ($wgOpenStackManagerInstanceUserData['scripts']) {
             foreach ($wgOpenStackManagerInstanceUserData['scripts'] as $scriptname => $script) {
                 wfSuppressWarnings();
                 $stat = stat($script);
                 wfRestoreWarnings();
                 if (!$stat) {
                     continue;
                 }
                 $scripttext = file_get_contents($script);
                 $userdata .= $endl . $this->getAttachmentMime($scripttext, 'text/x-shellscript', $scriptname);
                 $userdata .= $endl . $boundary;
             }
         }
         if ($wgOpenStackManagerInstanceUserData['upstarts']) {
             foreach ($wgOpenStackManagerInstanceUserData['upstarts'] as $upstartname => $upstart) {
                 wfSuppressWarnings();
                 $stat = stat($upstart);
                 wfRestoreWarnings();
                 if (!$stat) {
                     continue;
                 }
                 $upstarttext = file_get_contents($upstart);
                 $userdata .= $endl . $this->getAttachmentMime($upstarttext, 'text/upstart-job', $upstartname);
                 $userdata .= $endl . $boundary;
             }
         }
         $userdata .= '--';
         $data['server']['user_data'] = base64_encode($userdata);
     }
     $data['server']['security_groups'] = array();
     foreach ($groups as $group) {
         $data['server']['security_groups'][] = array('name' => $group);
     }
     $ret = $this->restCall('compute', '/servers', 'POST', $data);
     if ($ret['code'] !== 202) {
         return null;
     }
     $instance = new OpenStackNovaInstance($ret['body']->server, $this->getRegion());
     return $instance;
 }