function getCloudService($jsonParams)
 {
     $arg1 = 'providername';
     $accountprovider = $jsonParams->{$arg1};
     $arg1 = 'domain';
     $domain = $jsonParams->{$arg1};
     $arg10 = 'cloudproviders';
     $cloudproviders = $jsonParams->{$arg10};
     $providerArray = json_decode($cloudproviders);
     $subscriptionid = "subscriptionid";
     $subscrid = $providerArray->{$accountprovider}->{$subscriptionid};
     loghandler(DEBUG, "Subscription id:" . $subscrid);
     $certpath = "ServiceManagementAPICertificate";
     $certfpath = $providerArray->{$accountprovider}->{$certpath};
     loghandler(DEBUG, "Certificate path:" . $certfpath);
     //$connectionString="SubscriptionID=".$subscrid.";CertificatePath=/var/cloudbox/azurecer/mycert.pem";
     $connectionString = "SubscriptionID=" . $subscrid . ";CertificatePath=/var/cloudbox/" . $domain . "/data/keys/" . $certfpath;
     loghandler(DEBUG, "Connection String:" . $connectionString);
     try {
         $serviceManagementRestProxy = ServicesBuilder::getInstance()->createServiceManagementService($connectionString);
         return $serviceManagementRestProxy;
     } catch (Exception $se) {
         $message = $se->getMessage();
         trigger_error($message, E_USER_ERROR);
     }
     return null;
 }
 function getAWSService($region, $accprov)
 {
     $providerArray = json_decode($this->getAppContext()->getCloudproviders());
     $awsacesskey = $providerArray->{$accprov}->accessKey;
     $secretkey = $providerArray->{$accprov}->secretKey;
     try {
         loghandler(DEBUG, "Creating service factory");
         //echo "\ncreating service factory ....................:";
         $aws = Aws::factory(array('key' => $awsacesskey, 'secret' => $secretkey, 'region' => $region));
         loghandler(DEBUG, "Got service factory");
         return $aws;
     } catch (Exception $se) {
         $message = $se->getMessage();
         trigger_error($message, E_USER_ERROR);
     }
     return null;
 }
 function getService($jsonParams)
 {
     $arg10 = 'cloudproviders';
     $cloudproviders = $jsonParams->{$arg10};
     $cloudproviders = json_decode($cloudproviders);
     $arg1 = 'providername';
     $provname = $jsonParams->{$arg1};
     loghandler(DEBUG, "Provider Name: " . $provname);
     $provtype = "providerType";
     if ($provname != null && strlen(trim($provname)) > 0) {
         $type = $cloudproviders->{$provname}->{$provtype};
         // $type="amazon";
         loghandler(DEBUG, "ProviderType: " . $type);
         switch ($type) {
             case "amazon":
                 require_once 'AWS/AWSServiceProvider.php';
                 $awsService = new AWSServiceProvider();
                 $cloudService = $awsService->getCloudService($jsonParams);
                 return $cloudService;
             case "azure":
                 require_once 'Azure/AzureServiceManagementProvider.php';
                 $azureService = new AzureServiceManagementProvider();
                 $cloudService = $azureService->getCloudService($jsonParams);
                 return $cloudService;
             case "vchs":
                 require_once 'VMWare/VMWareServiceProvider.php';
                 $vmwareService = new VMWareServiceProvider();
                 $cloudService = $vmwareService->getCloudService($jsonParams);
                 return $cloudService;
             case "VSO":
                 require_once 'VSO/VSOServiceProvider.php';
                 $vsoService = new VSOServiceProvider();
                 $cloudService = $vsoService->getCloudService($jsonParams);
                 return $cloudService;
             case "Jenkins":
                 require_once 'Jenkins/JenkinsServiceProvider.php';
                 $jenService = new JenkinsServiceProvider();
                 $cloudService = $jenService->getCloudService($jsonParams);
                 return $cloudService;
         }
     } else {
         return null;
     }
 }
 function getCloudService($jsonParams)
 {
     $arg1 = 'providername';
     $accountprovider = $jsonParams->{$arg1};
     loghandler(INFO, "Connecting to provider:" . $accountprovider);
     $arg10 = 'cloudproviders';
     $cloudproviders = $jsonParams->{$arg10};
     $providerArray = json_decode($cloudproviders);
     $password = $providerArray->{$accountprovider}->password;
     $username = "******";
     $user = $providerArray->{$accountprovider}->{$username};
     $serverurl = "serverURL";
     $serverurl = $providerArray->{$accountprovider}->{$serverurl};
     $serv = new VSOService();
     $serv->setUserName($user);
     $serv->setPassword($password);
     $serv->setServiceURL($serverurl);
     return $serv;
 }
 function getCloudService($jsonParams)
 {
     $arg1 = 'providername';
     $accountprovider = $jsonParams->{$arg1};
     $arg10 = 'region';
     $region = $jsonParams->{$arg10};
     $arg10 = 'cloudproviders';
     $cloudproviders = $jsonParams->{$arg10};
     $providerArray = json_decode($cloudproviders);
     $awsacesskey = $providerArray->{$accountprovider}->accessKey;
     $secretkey = $providerArray->{$accountprovider}->secretKey;
     try {
         loghandler(DEBUG, "Creating service factory");
         $aws = Aws::factory(array('key' => $awsacesskey, 'secret' => $secretkey, 'region' => $region));
         loghandler(DEBUG, "Got service factory");
         return $aws;
     } catch (Exception $se) {
         $message = $se->getMessage();
         trigger_error($message, E_USER_ERROR);
     }
     return null;
 }
 /**
  * This method process plugin input to retreive the provider details.
  * @param  $jsonParams Input parameters to the plugin in json format.
  * @return array $integrationdetails Array containing credentials to connect to the provider.
  *         
  */
 function getService($jsonParams)
 {
     $arg10 = 'cloudproviders';
     $cloudproviders = $jsonParams->{$arg10};
     $cloudproviders = json_decode($cloudproviders);
     $arg1 = 'providername';
     $provname = $jsonParams->{$arg1};
     loghandler(DEBUG, "Provider Name: " . $provname);
     $provtype = "providerType";
     if ($provname != null && strlen(trim($provname)) > 0) {
         $regfields = $cloudproviders->{$provname};
         // $integration= file_get_contents("integration.json");
         // $integration=json_decode($integration);
         // $regfields= $integration->$type->registrationFields;
         $integrationdetails = array();
         foreach ($regfields as $key => $value) {
             $integrationdetails[$key] = $cloudproviders->{$provname}->{$key};
         }
         return $integrationdetails;
     } else {
         return null;
     }
 }
 function getCloudService($jsonParams)
 {
     $arg1 = 'providername';
     $accountprovider = $jsonParams->{$arg1};
     loghandler(INFO, "Connecting to provider:" . $accountprovider);
     $arg10 = 'cloudproviders';
     $cloudproviders = $jsonParams->{$arg10};
     $providerArray = json_decode($cloudproviders);
     $password = $providerArray->{$accountprovider}->password;
     $serverurl = "server name";
     $server = $providerArray->{$accountprovider}->{$serverurl};
     $username = "******";
     $user = $providerArray->{$accountprovider}->{$username};
     $this->orgName = $providerArray->{$accountprovider}->Organisation;
     $datacenter = "Data center";
     $this->vdc = $providerArray->{$accountprovider}->{$datacenter};
     // Initialize parameters
     $httpConfig = array('ssl_verify_peer' => false, 'ssl_verify_host' => false);
     $sdkversion = "5.5";
     $auth = array('username' => $user, 'password' => $password);
     // Create a service object";
     $service = VMware_VCloud_SDK_Service::getService();
     try {
         // Login to the service portal, parameters are set from command line
         $service->login($server, $auth, $httpConfig, $sdkversion);
         $serv = new VMWareService();
         $serv->setService($service);
         $serv->setOrganisation($this->orgName);
         $serv->setDataCenter($this->vdc);
         $serv->setProviderName($accountprovider);
         return $serv;
     } catch (Exception $se) {
         $message = $se->getMessage();
         trigger_error($message, E_USER_ERROR);
     }
     return null;
 }
 public function performAppcompletion()
 {
     loghandler(INFO, "App completed successfully");
     $date_b = new DateTime();
     $interval = date_diff($this->stime, $date_b);
     loghandler(INFO, "Total time taken: " . $interval->format('%h:%i:%s'));
 }
 /**
 * Checks if server is up and running
 *
 * @param 	string dns 		: 	dns of target server 
 * @param    number sshport 	: 	ssh port to be used to check for connection
 * @return 	string Success 	: 	displays an appropriate message
 *			       Failure 	: 	exits with a failure status with an appropriate message
 */
 function checkConnect($dns, $sshport = 22)
 {
     $connectionTimeout = time();
     $connectionTimeout = $connectionTimeout + 10 * 10;
     do {
         if ($dns == null || $dns == '') {
             trigger_error("Invalid dns" . $dns, E_USER_ERROR);
         }
         loghandler(INFO, "Checking connectivity to: " . $dns);
         $connection = ssh2_connect($dns, $sshport);
         if (!$connection) {
             sleep(10);
         }
     } while (!$connection && time() < $connectionTimeout);
     if (!$connection) {
         trigger_error("Failed to connect to " . $dns, E_USER_ERROR);
     }
 }
 function notifyUsersInCloudmunch($serverurl, $message, $contextarray, $domain)
 {
     //	$url =$masterurl . "/cbdata.php?context=".$context."&username=CI&mode=update&domain=".$domain."&data=".$serverArray;
     // global $curl_verbose;
     $curl_verbose = 0;
     //var_dump($serverArray);
     $dataarray = json_encode($contextarray);
     $dataarray = urlencode($dataarray);
     $message = urlencode($message);
     //cbdata.php?action=NOTIFY&to=*&message=whatever message&usercontext={�project�:project name,�job�:jobname,�context�:�servers�,�id�:server name�}
     //$data = "data=" . json_encode($serverArray);
     $usercontext = "usercontext=" . $dataarray;
     //	$url = $serverurl . "/cbdata.php?action=NOTIFY&to=*&message=".$message."&usercontext=".$dataarray."&domain=" . $domain."&username=CI";
     $url = $serverurl . "/cbdata.php?action=NOTIFY&to=*&message=" . $message . "&domain=" . $domain . "&username=CI";
     //$url=urlencode($url);
     //echo "\nurl is:" . $url.PHP_EOL;
     $options = array(CURLOPT_HEADER => 0, CURLOPT_HTTPHEADER => array('Content-Type: application/x-www-form-urlencoded'), CURLOPT_URL => $url, CURLOPT_FOLLOWLOCATION => true, CURLOPT_FRESH_CONNECT => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FORBID_REUSE => 1, CURLOPT_TIMEOUT => 20, CURLOPT_FAILONERROR => 1, CURLOPT_POSTFIELDS => $usercontext, CURLOPT_POST => 1, CURLOPT_VERBOSE => $curl_verbose, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false);
     $post = curl_init();
     curl_setopt_array($post, $options);
     $result = curl_exec($post);
     $response_code = curl_getinfo($post, CURLINFO_HTTP_CODE);
     if ($result === FALSE) {
         trigger_error("Error in notifying to cloudmunch", E_USER_ERROR);
     } else {
         loghandler(INFO, "result:" . $result);
         loghandler(INFO, "Notification send");
         //echo "\nresult:" . $result.PHP_EOL;
     }
 }
 function deleteServer($serverName)
 {
     $deployArray = getDataForContext($this->appContext->getMasterURL(), "server", $this->appContext->getDomainName());
     $deployArray = json_decode($deployArray);
     if ($deployArray == null) {
         loghandler(INFO, 'Not able to read the server details');
         //sysout("ERROR", 'Not able to read the server details');
     } else {
         foreach ($deployArray as $i => $detailArray) {
             if (array_key_exists($serverName, $detailArray)) {
                 unset($deployArray[$i]);
             }
         }
         $deployArray = array_values($deployArray);
         updateContext($this->appContext->getMasterURL(), "server", $this->appContext->getDomainName(), $deployArray);
     }
 }