예제 #1
0
        /// <summary>
        /// Gets the resource components for the Virtual machine resource in an ARM template
        /// </summary>
        /// <param name="resource">The object containing the resource</param>
        /// <param name="template">The object containing the ARM Template</param>
        /// <param name="paramValue">The object containing the values in the Parameter file</param>
        /// <param name="location">The Azure Location</param>
        /// <param name="cspCreds">CSP Account credentials object. This is not used in current version.</param>
        /// <param name="log">The object that will contain the exception messages</param>
        /// <returns> Returns the list of resource components</returns>
        public List <ResourceComponent> GetResourceComponents(Resource resource, ARMTemplate template, ARMParamValue paramValue, string location, CSPAccountCreds cspCreds, out StringBuilder log)
        {
            this.resource   = resource;
            this.template   = template;
            this.paramValue = paramValue;
            this.cspCreds   = cspCreds;
            this.location   = location;

            List <ResourceComponent> componentList = new List <ResourceComponent>();

            log = new StringBuilder(string.Empty);

            try
            {
                if (resource != null && resource.Name != null)
                {
                    // Get the name of the resource
                    this.nameOfResource = PropertyHelper.GetValueIfVariableOrParam(resource.Name, template.Variables, template.Parameters, paramValue.Parameters);
                }

                // Convert Resource Properties to VMProperties
                if (resource != null && resource.Properties != null)
                {
                    this.prop = resource.Properties.ToObject <VMProperties>();

                    if (this.prop != null)
                    {
                        // Fetch resource components for Compute Hours
                        componentList.AddRange(this.GetResourceComponentForComputeHours());

                        // Fetch resource components for Storage
                        componentList.AddRange(this.GetResourceComponentForStorage());

                        // Fetch resource components for Network
                        componentList.AddRange(this.GetResourceComponentForNetwork());

                        // Fetch resource components for VM Diagnostics
                        componentList.AddRange(this.GetResourceComponentForDiagnostics());
                    }
                    else
                    {
                        throw new Exception(ExceptionLogger.GenerateLoggerTextForFailedReadProperties(this.nameOfResource));
                    }
                }
                else
                {
                    throw new Exception(ExceptionLogger.GenerateLoggerTextForMissingField("Properties", this.nameOfResource));
                }
            }
            catch (Exception ex)
            {
                componentList = null;
                log.AppendLine(ex.Message);
            }

            return(componentList);
        }