Ejemplo n.º 1
0
        public async Task CreateBlobStorage(String containerName)
        {
            messageContainer.AddInformationMessage("Creating Blob Client...");
            blobClient = storageAccount.CreateCloudBlobClient();

            messageContainer.AddInformationMessage("Creating Blob Container...");
            blobContainer = blobClient.GetContainerReference(containerName);
            await blobContainer.CreateIfNotExistsAsync();

            messageContainer.AddInformationMessage("Blob Container " + blobContainer.Name + " created");

            messageContainer.AddInformationMessage("Setting Blob Permissions...");
            BlobContainerPermissions blobPermissions = new BlobContainerPermissions {
                PublicAccess = BlobContainerPublicAccessType.Blob
            };
            await blobContainer.SetPermissionsAsync(blobPermissions);
        }
Ejemplo n.º 2
0
 private void CreateResourceGroupIfNotExists()
 {
     if (!azureConnection.ResourceGroups.Contain(AzureConnectionUtility.ResourceGroup))
     {
         messageContainer.AddInformationMessage("Creating resource group with name - " + AzureConnectionUtility.ResourceGroup + " ...");
         azureConnection.ResourceGroups.Define(AzureConnectionUtility.ResourceGroup).WithRegion(AzureConnectionUtility.Region).Create();
         messageContainer.AddStatusMessage("Resource Group (" + AzureConnectionUtility.ResourceGroup + ") created...");
     }
 }
Ejemplo n.º 3
0
        public AzureBatchClient(String accountName = null, String accountKey = null, String accountURL = null, BlobStorage storage = null, String poolID = null, String jobID = null, int poolNodeCount = 2, String poolVMSize = null, SystemMessageContainer container = null)
        {
            if (accountName == null)
            {
                throw new NullReferenceException("Please provide a valid batch account name");
            }
            if (accountKey == null)
            {
                throw new NullReferenceException("Please provide a valid batch account key");
            }
            if (accountURL == null)
            {
                throw new NullReferenceException("Please provide a valid batch account URL");
            }
            if (storage == null)
            {
                throw new NullReferenceException("Please provide a valid blob storange reference");
            }

            batchAccountName = accountName;
            batchAccountKey  = accountKey;
            batchAccountURL  = accountURL;
            blobStorage      = storage;

            poolID     = (poolID == null ? AzureConnectionUtility.BuildProjectNameReference() + "-pool" : poolID);
            jobID      = (jobID == null ? AzureConnectionUtility.BuildProjectNameReference() + "-job" : jobID);
            poolVMSize = (poolVMSize == null ? "Basic_A1" : poolVMSize);

            messageContainer = (container == null ? new SystemMessageContainer() : container);

            messageContainer.AddInformationMessage("Creating batch client...");

            batchClient = BatchClient.Open(new BatchSharedKeyCredentials(batchAccountURL, batchAccountName, batchAccountKey));
            messageContainer.AddInformationMessage("Batch client created...");

            //Create the pool if it doesn't exist
            pool = CreatePoolIfNotExists(poolID, poolVMSize, poolNodeCount);
            job  = CreateJobIfNotExists(jobID, pool.Id);
        }
Ejemplo n.º 4
0
        public BlobStorage(String connectionString = null, SystemMessageContainer container = null)
        {
            if (connectionString == null)
            {
                throw new NullReferenceException("Please provide a connection string for creating blob storage on Azure");
            }

            messageContainer = (container == null ? new SystemMessageContainer() : container);

            if (CloudStorageAccount.TryParse(connectionString, out storageAccount))
            {
                messageContainer.AddInformationMessage("Successfully connected to storage account");
            }
            else //Failure - alert user in a friendly manner
            {
                messageContainer.AddErrorMessage("An error occurred in connecting to the storage account", "Attempted to use connection string: " + connectionString);
            }
        }
Ejemplo n.º 5
0
        private CloudJob CreateJobIfNotExists(String jobID, String poolID)
        {
            messageContainer.AddInformationMessage("Configuring job...");

            CloudJob cJob = null;

            try { cJob = batchClient.JobOperations.GetJob(jobID); } catch { }

            if (cJob == null)
            {
                messageContainer.AddInformationMessage("Creating job...");
                cJob    = batchClient.JobOperations.CreateJob();
                cJob.Id = jobID;
                cJob.PoolInformation = new PoolInformation {
                    PoolId = poolID
                };

                cJob.Commit();
                messageContainer.AddInformationMessage("Job created...");
            }
            messageContainer.AddInformationMessage("Job configured...");

            return(cJob);
        }
Ejemplo n.º 6
0
        public void CreateVM()
        {
            String region        = AzureConnectionUtility.Region;
            String resourceGroup = AzureConnectionUtility.ResourceGroup;

            IAvailabilitySet  availabilitySet  = CreateAvailabilitySetIfNotExists();
            IPublicIPAddress  publicIPAddress  = CreateIPIfNotExists();
            INetwork          network          = CreateNetworkIfNotExists();
            INetworkInterface networkInterface = CreateNetworkInterfaceIfNotExists(network, publicIPAddress);

            messageContainer.AddInformationMessage("Configuring virtual machine...");
            String machineName = "azureAutoEngine_VM";

            virtualMachine = azureConnection.AzureLink.VirtualMachines.GetByResourceGroup(AzureConnectionUtility.ResourceGroup, machineName);

            if (virtualMachine == null)
            {
                messageContainer.AddInformationMessage("Creating virtual machine...");
                virtualMachine = azureConnection.AzureLink.VirtualMachines.Define(machineName)
                                 .WithRegion(AzureConnectionUtility.Region)
                                 .WithExistingResourceGroup(AzureConnectionUtility.ResourceGroup)
                                 .WithExistingPrimaryNetworkInterface(networkInterface)
                                 .WithLatestLinuxImage("credativ", "Debian", "8")
                                 .WithRootUsername("azureUser")
                                 .WithRootPassword("Azure12345678")
                                 .WithComputerName("azureAutoEngineVM")
                                 .WithExistingAvailabilitySet(availabilitySet)
                                 .WithSize(VirtualMachineSizeTypes.BasicA1)
                                 .Create();
                messageContainer.AddInformationMessage("Virtual machine created...");
            }

            if (virtualMachine.PowerState != PowerState.Running)
            {
                SwitchOnVM();
            }

            messageContainer.AddInformationMessage("Virtual machine configured... feel free to inspect it on the portal...");
        }