/// <summary> /// Initializes a new instance of the <see cref="PSRecoveryServicesClient" /> class with /// required current subscription. /// </summary> /// <param name="azureSubscription">Azure Subscription</param> public PSRecoveryServicesClient(AzureProfile azureProfile, AzureSubscription azureSubscription) { this.Profile = azureProfile; this.cloudServicesClient = AzureSession.ClientFactory.CreateClient <CloudServiceManagementClient>(azureProfile, azureSubscription, AzureEnvironment.Endpoint.ResourceManager); System.Configuration.Configuration siteRecoveryConfig = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location); System.Configuration.AppSettingsSection appSettings = (System.Configuration.AppSettingsSection)siteRecoveryConfig.GetSection("appSettings"); string resourceNamespace = ""; if (appSettings.Settings.Count == 0) { resourceNamespace = "Microsoft.SiteRecovery"; // ProviderNameSpace for Production is taken as default } else { resourceNamespace = appSettings.Settings["ProviderNamespace"].Value; } Utilities.UpdateVaultSettingsProviderNamespace(resourceNamespace); this.recoveryServicesClient = AzureSession.ClientFactory.CreateCustomClient <RecoveryServicesManagementClient>( asrVaultCreds.ResourceNamespace, cloudServicesClient.Credentials, Profile.Context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)); }
protected void SetupManagementClients() { CloudServiceManagementClient = GetCloudServicesManagementClient(); RecoveryServicesMgmtClient = GetRecoveryServicesManagementClient(); SiteRecoveryMgmtClient = GetSiteRecoveryManagementClient(); helper.SetupManagementClients(CloudServiceManagementClient, RecoveryServicesMgmtClient, SiteRecoveryMgmtClient); }
public StorSimpleClient(AzureSubscription currentSubscription) { // Temp code to be able to test internal env. ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };//IgnoreCertificateErrorHandler;//delegate { return true; }; this.cloudServicesClient = AzureSession.ClientFactory.CreateClient <CloudServiceManagementClient>(currentSubscription, AzureEnvironment.Endpoint.ServiceManagement); ResourceCachetimeoutPolicy.AbsoluteExpiration = DateTimeOffset.Now.AddHours(1.0d); }
public ScalingAgent(string subscriptionID, string subscriptionManagementCertificateThumbprint, StoreLocation storeLocation) { X509Certificate2 managementCert = subscriptionManagementCertificateThumbprint.FindX509CertificateByThumbprint(storeLocation); SubscriptionCloudCredentials creds = new CertificateCloudCredentials(subscriptionID, managementCert); this.computeManagementClient = CloudContext.Clients.CreateComputeManagementClient(creds); this.storageManagementClient = CloudContext.Clients.CreateStorageManagementClient(creds); this.cloudServiceManagementClient = CloudContext.Clients.CreateCloudServiceManagementClient(creds); this.managementClient = CloudContext.Clients.CreateManagementClient(creds); }
private static bool JobCollectionAlreadyExists() { var cloudServiceManagementClient = new CloudServiceManagementClient(Credentials); var cloudService = cloudServiceManagementClient.CloudServices.Get(JobsCloudServiceName); var collectionAlreadyExists = cloudService.Resources .Any(x => x.Name == JobsCollectionName && x.ResourceProviderNamespace == SchedulerResourceNamespace); return(collectionAlreadyExists); }
/// <summary> /// Creates new Scheduler Management Convenience Client /// </summary> /// <param name="subscription">Subscription containing websites to manipulate</param> public SchedulerMgmntClient(WindowsAzureSubscription subscription) { currentSubscription = subscription; csmClient = subscription.CreateClient <CloudServiceManagementClient>(); schedulerManagementClient = subscription.CreateClient <SchedulerManagementClient>(); //Get RP properties IDictionary <string, string> dict = schedulerManagementClient.GetResourceProviderProperties().Properties; //Get available regions string val = string.Empty; if (dict.TryGetValue(SupportedRegionsKey, out val)) { AvailableRegions = new List <string>(); val.Split(',').ToList().ForEach(s => AvailableRegions.Add(s)); } //Store global counts for max jobs and min recurrence for each plan if (dict.TryGetValue(FreeMaxJobCountKey, out val)) { FreeMaxJobCountValue = Convert.ToInt32(dict[FreeMaxJobCountKey]); } if (dict.TryGetValue(FreeMinRecurrenceKey, out val)) { FreeMinRecurrenceValue = TimeSpan.Parse(dict[FreeMinRecurrenceKey]); } if (dict.TryGetValue(StandardMaxJobCountKey, out val)) { StandardMaxJobCountValue = Convert.ToInt32(dict[StandardMaxJobCountKey]); } if (dict.TryGetValue(StandardMinRecurrenceKey, out val)) { StandardMinRecurrenceValue = TimeSpan.Parse(dict[StandardMinRecurrenceKey]); } if (dict.TryGetValue(PremiumMaxJobCountKey, out val)) { PremiumMaxJobCountValue = Convert.ToInt32(dict[PremiumMaxJobCountKey]); } if (dict.TryGetValue(PremiumMinRecurrenceKey, out val)) { PremiumMinRecurrenceValue = TimeSpan.Parse(dict[PremiumMinRecurrenceKey]); } }
public SchedulerService(ServiceConfiguration serviceConfiguration) : base(serviceConfiguration) { CloudServiceManagementClient = new CloudServiceManagementClient(CertificateCloudCredentials); SchedulerManagementClient = new SchedulerManagementClient(CertificateCloudCredentials); try { System.Diagnostics.Trace.TraceInformation("Registering Schedluer Resource"); SchedulerManagementClient.RegisterResourceProvider(); } catch (Hyak.Common.CloudException) { // Probably it is registered before // but TODO: do some logging in case it isn't the expected error System.Diagnostics.Trace.TraceInformation("Schedluer Resource already registered"); } }
public static void CreateCloudClient(string cloudServiceName, string geoRegion, CertificateCloudCredentials credentials) { try { var cloudServiceClient = new CloudServiceManagementClient(credentials); cloudServiceClient.CloudServices.Delete(cloudServiceName); var result = cloudServiceClient.CloudServices.Create(cloudServiceName, new CloudServiceCreateParameters() { Description = cloudServiceName, GeoRegion = geoRegion, Label = cloudServiceName }); Console.WriteLine("CreateCloudClient :\n" + result.Status); Console.WriteLine("CreateCloudClient :\n" + result.HttpStatusCode); } catch (Exception e) { Console.WriteLine("CreateCloudClient Exception :\n" + e.Message); throw; } }
// retrieve the windows azure managment certificate from current user public ApprenticeShipSchedular() { var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); var certificate = store.Certificates.Find(X509FindType.FindByThumbprint, "CA4716F85EC0962E2B69BB7D626CC16B924E550D", false)[0]; store.Close(); // // create management credencials and cloud service management client var credentials = new CertificateCloudCredentials("bd27a79c-de25-4097-a874-3bb35f2b926a", certificate); var cloudServiceMgmCli = new CloudServiceManagementClient(credentials); // create cloud service var cloudServiceCreateParameters = new CloudServiceCreateParameters { Description = "sfaarmscheduler", Email = "*****@*****.**", GeoRegion = "West Europe", Label = "sfaarmscheduler" }; var cloudService = cloudServiceMgmCli.CloudServices.Create("sfaarmscheduler", cloudServiceCreateParameters); // create job collection var schedulerMgmCli = new SchedulerManagementClient(credentials); var jobCollectionIntrinsicSettings = new JobCollectionIntrinsicSettings { //Add Credentials for X.509 Plan = JobCollectionPlan.Free, Quota = new JobCollectionQuota { MaxJobCount = 5, MaxJobOccurrence = 1, MaxRecurrence = new JobCollectionMaxRecurrence { Frequency = JobCollectionRecurrenceFrequency.Hour, Interval = 1 } } }; var jobCollectionCreateParameters = new JobCollectionCreateParameters { IntrinsicSettings = jobCollectionIntrinsicSettings, Label = "sfajobcollection" }; var jobCollectionCreateResponse = schedulerMgmCli.JobCollections.Create("sfaarmscheduler", "sfajobcollection", jobCollectionCreateParameters); var schedulerClient = new SchedulerClient("sfaarmscheduler", "sfajobcollection", credentials); var jobAction = new JobAction { Type = JobActionType.StorageQueue, QueueMessage = new JobQueueMessage() { Message = "test", QueueName = "vacancysummaryqueueitem", SasToken = "?sv=2017-04-17&ss=bfqt&srt=sco&sp=rwdlacup&se=2017-09-01T21:58:06Z&st=2017-09-01T13:58:06Z&spr=https&sig=r0u1A01ytcN213lsWO47Td7DUaU7lo3aQTPNTCrHRxU%3D", StorageAccountName = "sfabetastorage" } //Request = new JobHttpRequest //{ // Uri = new Uri("http://blog.shaunxu.me"), // Method = "GET" //} }; var jobRecurrence = new JobRecurrence { Frequency = JobRecurrenceFrequency.Hour, Interval = 1 }; var jobCreateOrUpdateParameters = new JobCreateOrUpdateParameters { Action = jobAction, Recurrence = jobRecurrence }; var jobCreateResponse = schedulerClient.Jobs.CreateOrUpdate("poll_blog", jobCreateOrUpdateParameters); var jobGetHistoryParameters = new JobGetHistoryParameters { Skip = 0, Top = 100 }; var history = schedulerClient.Jobs.GetHistory("poll_blog", jobGetHistoryParameters); foreach (var action in history) { Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", action.Status, action.Message, action.RetryCount, action.RepeatCount, action.Timestamp); } }
/// <summary> /// Creates new Scheduler Management Convenience Client /// </summary> /// <param name="subscription">Subscription containing websites to manipulate</param> public SchedulerMgmntClient(WindowsAzureSubscription subscription) { csmClient = subscription.CreateClient <CloudServiceManagementClient>(); schedulerManagementClient = subscription.CreateClient <SchedulerManagementClient>(); }
// retrieve the windows azure managment certificate from current user public Schedular() { var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); var certificate = store.Certificates.Find(X509FindType.FindByThumbprint, "<ThumbPrint>", false)[0]; store.Close(); // // create management credencials and cloud service management client var credentials = new CertificateCloudCredentials("8cb918af-59d0-4b24-893c-15661d048f16", certificate); var cloudServiceMgmCli = new CloudServiceManagementClient(credentials); // create cloud service var cloudServiceCreateParameters = new CloudServiceCreateParameters() { Description = "schedulerdemo1", Email = "microsoft.com", GeoRegion = "Southeast Asia", Label = "schedulerdemo1" }; var cloudService = cloudServiceMgmCli.CloudServices.Create("schedulerdemo1", cloudServiceCreateParameters); // create job collection var schedulerMgmCli = new SchedulerManagementClient(credentials); var jobCollectionIntrinsicSettings = new JobCollectionIntrinsicSettings() { Plan = JobCollectionPlan.Free, Quota = new JobCollectionQuota() { MaxJobCount = 5, MaxJobOccurrence = 1, MaxRecurrence = new JobCollectionMaxRecurrence() { Frequency = JobCollectionRecurrenceFrequency.Hour, Interval = 1 } } }; var jobCollectionCreateParameters = new JobCollectionCreateParameters() { IntrinsicSettings = jobCollectionIntrinsicSettings, Label = "jc1" }; var jobCollectionCreateResponse = schedulerMgmCli.JobCollections.Create("schedulerdemo1", "jc1", jobCollectionCreateParameters); var schedulerClient = new SchedulerClient("schedulerdemo1", "jc1", credentials); var jobAction = new JobAction() { Type = JobActionType.Http, Request = new JobHttpRequest() { Uri = new Uri("http://blog.shaunxu.me"), Method = "GET" } }; var jobRecurrence = new JobRecurrence() { Frequency = JobRecurrenceFrequency.Hour, Interval = 1 }; var jobCreateOrUpdateParameters = new JobCreateOrUpdateParameters() { Action = jobAction, Recurrence = jobRecurrence }; var jobCreateResponse = schedulerClient.Jobs.CreateOrUpdate("poll_blog", jobCreateOrUpdateParameters); var jobGetHistoryParameters = new JobGetHistoryParameters() { Skip = 0, Top = 100 }; var history = schedulerClient.Jobs.GetHistory("poll_blog", jobGetHistoryParameters); foreach (var action in history) { Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", action.Status, action.Message, action.RetryCount, action.RepeatCount, action.Timestamp); } }
private static void CreateSchedulerJob(AzureDetails details) { // retrieve the windows azure managment certificate from current user var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); var certificate = store.Certificates.Find(X509FindType.FindByThumbprint, "<THUMBPRINT of CERTIFICATE>", false)[0]; store.Close(); // create management credencials and cloud service management client var credentials = new CertificateCloudCredentials("<Your subscription ID>", certificate); var cloudServiceMgmCli = new CloudServiceManagementClient(credentials); // create job collection var schedulerMgmCli = new SchedulerManagementClient(credentials); var jobCollectionIntrinsicSettings = new JobCollectionIntrinsicSettings() { Plan = JobCollectionPlan.Free, Quota = new JobCollectionQuota() { MaxJobCount = 5, MaxJobOccurrence = 1, MaxRecurrence = new JobCollectionMaxRecurrence() { Frequency = JobCollectionRecurrenceFrequency.Hour, Interval = 24 } } }; var jobCollectionCreateParameters = new JobCollectionCreateParameters() { IntrinsicSettings = jobCollectionIntrinsicSettings, Label = "RunBackupJob" }; var jobCollectionCreateResponse = schedulerMgmCli.JobCollections.Create(details.ResourceGroup, "RunBackupJob", jobCollectionCreateParameters); //generate sas token var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("AzureWebJobsStorage")); //Set the expiry time and permissions for the container. //In this case no start time is specified, so the shared access signature becomes valid immediately. var sasConstraints = new SharedAccessAccountPolicy { SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddYears(1), Permissions = SharedAccessAccountPermissions.Add | SharedAccessAccountPermissions.Create | SharedAccessAccountPermissions.Delete | SharedAccessAccountPermissions.ProcessMessages | SharedAccessAccountPermissions.Read | SharedAccessAccountPermissions.Write }; var token = storageAccount.GetSharedAccessSignature(sasConstraints); // create job var schedulerClient = new SchedulerClient(details.ResourceGroup, "RunBackupJob", credentials); var jobAction = new JobAction() { Type = JobActionType.StorageQueue, QueueMessage = new JobQueueMessage { Message = details.PairName, QueueName = "get-containers", SasToken = sasConstraints.ToString(), StorageAccountName = "queuefunction" } }; var jobRecurrence = new JobRecurrence() { Frequency = JobRecurrenceFrequency.Hour, Interval = 24 }; var jobCreateOrUpdateParameters = new JobCreateOrUpdateParameters() { Action = jobAction, Recurrence = jobRecurrence }; var jobCreateResponse = schedulerClient.Jobs.CreateOrUpdate(details.ResourceGroup, jobCreateOrUpdateParameters); }