ConvertAccountResourceToNewAccountContext() static private method

Create a new BAC and fill it in
static private ConvertAccountResourceToNewAccountContext ( BatchAccount resource ) : BatchAccountContext
resource BatchAccount Resource info returned by RP
return BatchAccountContext
示例#1
0
        /// <summary>
        /// Get details about the Batch account
        /// </summary>
        /// <param name="resourceGroupName">The name of the resource group the account is under. If unspecified, it will be looked up.</param>
        /// <param name="accountName">The account name</param>
        /// <returns>A BatchAccountContext object representing the account</returns>
        public virtual BatchAccountContext GetAccount(string resourceGroupName, string accountName)
        {
            // single account lookup - find its resource group if not specified
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetGroupForAccount(accountName);
            }
            var response = BatchManagementClient.Accounts.Get(resourceGroupName, accountName);

            return(BatchAccountContext.ConvertAccountResourceToNewAccountContext(response.Resource));
        }
示例#2
0
        /// <summary>
        /// Lists all accounts in a subscription or in a resource group if its name is specified
        /// </summary>
        /// <param name="resourceGroupName">The name of the resource group to search under for accounts. If unspecified, all accounts will be looked up.</param>
        /// <param name="tag">The tag to filter accounts on</param>
        /// <returns>A collection of BatchAccountContext objects</returns>
        public virtual IEnumerable <BatchAccountContext> ListAccounts(string resourceGroupName, Hashtable tag)
        {
            List <BatchAccountContext> accounts = new List <BatchAccountContext>();

            // no account name so we're doing some sort of list. If no resource group, then list all accounts under the
            // subscription otherwise all accounts in the resource group.
            var response = BatchManagementClient.Accounts.List(new AccountListParameters {
                ResourceGroupName = resourceGroupName
            });

            // filter out the accounts if a tag was specified
            IList <AccountResource> accountResources = new List <AccountResource>();

            if (tag != null && tag.Count > 0)
            {
                accountResources = Helpers.FilterAccounts(response.Accounts, tag);
            }
            else
            {
                accountResources = response.Accounts;
            }

            foreach (AccountResource resource in accountResources)
            {
                accounts.Add(BatchAccountContext.ConvertAccountResourceToNewAccountContext(resource));
            }

            var nextLink = response.NextLink;

            while (nextLink != null)
            {
                response = ListNextAccounts(nextLink);

                foreach (AccountResource resource in response.Accounts)
                {
                    accounts.Add(BatchAccountContext.ConvertAccountResourceToNewAccountContext(resource));
                }

                nextLink = response.NextLink;
            }

            return(accounts);
        }
示例#3
0
        /// <summary>
        /// Creates a new Batch account
        /// </summary>
        /// <param name="resourceGroupName">The name of the resource group in which to create the account</param>
        /// <param name="accountName">The account name</param>
        /// <param name="location">The location to use when creating the account</param>
        /// <param name="tags">The tags to associate with the account</param>
        /// <returns>A BatchAccountContext object representing the new account</returns>
        public virtual BatchAccountContext CreateAccount(string resourceGroupName, string accountName, string location, Hashtable[] tags)
        {
            // use the group lookup to validate whether account already exists. We don't care about the returned
            // group name nor the exception
            if (GetGroupForAccountNoThrow(accountName) != null)
            {
                throw new CloudException(Resources.NBA_AccountAlreadyExists);
            }

            Dictionary <string, string> tagDictionary = Helpers.CreateTagDictionary(tags, validate: true);

            var response = BatchManagementClient.Accounts.Create(resourceGroupName, accountName, new BatchAccountCreateParameters()
            {
                Location = location,
                Tags     = tagDictionary
            });

            var context = BatchAccountContext.ConvertAccountResourceToNewAccountContext(response.Resource);

            return(context);
        }
示例#4
0
        /// <summary>
        /// Updates an existing Batch account
        /// </summary>
        /// <param name="resourceGroupName">The name of the resource group the account is under. If unspecified, it will be looked up.</param>
        /// <param name="accountName">The account name</param>
        /// <param name="tags">New tags to associate with the account</param>
        /// <returns>A BatchAccountContext object representing the updated account</returns>
        public virtual BatchAccountContext UpdateAccount(string resourceGroupName, string accountName, Hashtable[] tags)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                // use resource mgr to see if account exists and then use resource group name to do the actual lookup
                resourceGroupName = GetGroupForAccount(accountName);
            }

            Dictionary <string, string> tagDictionary = Helpers.CreateTagDictionary(tags, validate: true);


            // need to the location in order to call
            var getResponse = BatchManagementClient.Accounts.Get(resourceGroupName, accountName);

            var response = BatchManagementClient.Accounts.Create(resourceGroupName, accountName, new BatchAccountCreateParameters()
            {
                Location = getResponse.Resource.Location,
                Tags     = tagDictionary
            });

            BatchAccountContext context = BatchAccountContext.ConvertAccountResourceToNewAccountContext(response.Resource);

            return(context);
        }