/// <summary> /// Initializes a new instance of the <see cref="CloudshareClient"/> class. /// Constructs a CloudshareClient. /// </summary> /// <param name="account"> /// Cloudshare account information /// </param> public CloudshareClient(CloudshareAccount account) { this.client = new RestClient(account.ServerUrl); // To debug with fiddler use line below // this.client.Proxy = new WebProxy("localhost", 8888); this.apiId = account.ApiId; this.apiKey = account.ApiKey; }
public static void InstallZipOnCloudshare(string filename, string blueprintName, string snapshotName) { var ac = new CloudshareAccount(); ac.ApiId = ConfigurationManager.AppSettings["ApiId"]; ac.ApiKey = ConfigurationManager.AppSettings["ApiKey"]; ac.ServerUrl = ConfigurationManager.AppSettings["ServerUrl"]; client = new CloudshareAPIWrapper.CloudshareClient(ac); var environmentStates = CloudshareManager.client.GetAllAvailableBlueprints(); cloudFoldersInfo = CloudshareManager.client.GetCloudFoldersInfo(); var blueprints = (from data in environmentStates.data from blueprint in data.Blueprints orderby blueprint.Name select blueprint.Name).Distinct().ToList(); var snapshots = (from data in environmentStates.data from blueprint in data.Blueprints from snapshot in blueprint.Snapshots where blueprint.Name == blueprintName orderby snapshot.Name select snapshot.Name).ToList(); var selectedSnapshot = (from data in environmentStates.data from blueprint in data.Blueprints from snapshot in blueprint.Snapshots where snapshot.IsLatest == true && blueprint.Name == blueprintName select snapshot).FirstOrDefault(); var selectedBluprint = (from data in environmentStates.data from blueprint in data.Blueprints from snapshot in blueprint.Snapshots where snapshot.IsLatest == true && blueprint.Name == blueprintName select blueprint).FirstOrDefault(); var selectedData = (from data in environmentStates.data from blueprint in data.Blueprints from snapshot in blueprint.Snapshots where snapshot.IsLatest == true && blueprint.Name == blueprintName select data).FirstOrDefault(); CloudshareManager.client = new CloudshareAPIWrapper.CloudshareClient(ac); var environmentName = string.Format("CloudahreAutomation{0}", DateTime.Now.Ticks); var a = CloudshareManager.client.CreateBlueprintFromSnapshot(selectedData.EnvironmentPolicyId, selectedSnapshot.SnapshotId, environmentName, selectedBluprint.Name, selectedData.EnvironmentPolicyDuration); CloudshareManager.UploadFile(filename); var env = client.GetEnvironmentsList(); var envId = (from data in env.data where data.name == environmentName select data.envId).FirstOrDefault(); var networkFolder = CloudshareManager.client.Mount(envId); var vms = client.GetEnvironmentState(envId); var vmId = (from dat in vms.data.vms select vms.data.vms[0].vmId).FirstOrDefault(); var fileName = Path.GetFileName(filename); var req = WebRequest.Create(@"http://" + vms.data.vms[0].FQDN + @"/CloudshareAgent/Install.ashx?zip=" + fileName + @"&subfolder=" + CloudshareManager.remoteUserFolderName.Replace(" ", "-").Replace("'", "-").Replace("(", "-").Replace(")", "-") + @"&username="******"&password="******"GET"; //TODO: response checker if anything is OK var response = req.GetResponse(); var executedPath = client.ExecutePath(envId, vmId, @"c:\installer\Jetstream.bat"); Thread.Sleep(1800000); var resp = client.TakeSnapshot(envId, "Jestream " + DateTime.Now.ToString("yyyyMMdd"), "Jetstream cloudshare created on " + DateTime.Now.ToShortDateString(), false); Console.WriteLine(resp.status_text); }
private void InitData() { var cloudshareAccount = new CloudshareAccount { ApiId = ConfigurationManager.AppSettings["ApiId"], ApiKey = ConfigurationManager.AppSettings["ApiKey"], ServerUrl = ConfigurationManager.AppSettings["ServerUrl"] }; this.client = new CloudshareAPIWrapper.CloudshareClient(cloudshareAccount); this.environmentStates = this.client.GetAllAvailableBlueprints(); this.cloudFoldersInfo = this.client.GetCloudFoldersInfo(); var env = client.GetEnvironmentsList(); _blueprints = (from data in this.environmentStates.data from blueprint in data.Blueprints orderby blueprint.Name select blueprint.Name).Distinct().ToList(); _snapshots = (from data in this.environmentStates.data from blueprint in data.Blueprints from snapshot in blueprint.Snapshots where blueprint.Name == this.BlueprintsComboBox.SelectedItem orderby snapshot.Name select snapshot.Name).ToList(); _aliveEnvironments = (from data in env.data where data.status_code == 0 && data.owner == tbOwner.Text select data.name).Distinct().ToList(); }