Ejemplo n.º 1
0
        public override void Execute()
        {
            base.Execute();
            PSVHubRouteTable hubRouteTableToDelete = null;

            if (ParameterSetName.Equals(CortexParameterSetNames.ByVHubRouteTableObject, StringComparison.OrdinalIgnoreCase))
            {
                hubRouteTableToDelete = this.InputObject;
                this.ResourceId       = this.InputObject.Id;
                if (string.IsNullOrWhiteSpace(this.ResourceId))
                {
                    throw new PSArgumentException(Properties.Resources.VHubRouteTableNotFound);
                }

                var parsedResourceId = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName  = parsedResourceId.ResourceGroupName;
                this.ParentResourceName = parsedResourceId.ParentResource.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();
                this.Name = parsedResourceId.ResourceName;
            }
            else
            {
                if (ParameterSetName.Equals(CortexParameterSetNames.ByVHubRouteTableResourceId, StringComparison.OrdinalIgnoreCase))
                {
                    var parsedResourceId = new ResourceIdentifier(this.ResourceId);
                    this.ResourceGroupName  = parsedResourceId.ResourceGroupName;
                    this.ParentResourceName = parsedResourceId.ParentResource.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();
                    this.Name = parsedResourceId.ResourceName;
                }
                else if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase))
                {
                    var parentResourceId       = this.ParentObject.Id;
                    var parsedParentResourceId = new ResourceIdentifier(parentResourceId);
                    this.ResourceGroupName  = parsedParentResourceId.ResourceGroupName;
                    this.ParentResourceName = parsedParentResourceId.ResourceName;
                }
            }

            // this will thorw if hub does not exist.
            IsParentVirtualHubPresent(this.ResourceGroupName, this.ParentResourceName);

            ConfirmAction(
                Force.IsPresent,
                string.Format(Properties.Resources.RemoveVHubRouteTableWarning),
                Properties.Resources.RemoveResourceMessage,
                this.Name,
                () =>
            {
                VHubRouteTableClient.Delete(this.ResourceGroupName, this.ParentResourceName, this.Name);
                if (PassThru)
                {
                    WriteObject(true);
                }
            });
        }
        public override void Execute()
        {
            base.Execute();

            if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase))
            {
                this.ResourceGroupName  = this.ParentObject.ResourceGroupName;
                this.ParentResourceName = this.ParentObject.Name;
            }
            else if (ParameterSetName.Contains(CortexParameterSetNames.ByVirtualHubResourceId))
            {
                var parsedResourceId = new ResourceIdentifier(this.ParentResourceId);
                this.ResourceGroupName  = parsedResourceId.ResourceGroupName;
                this.ParentResourceName = parsedResourceId.ResourceName;
            }

            if (this.IsVHubRouteTablePresent(this.ResourceGroupName, this.ParentResourceName, this.Name))
            {
                throw new PSArgumentException(string.Format(Properties.Resources.ChildResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName, this.ParentResourceName));
            }

            // this will thorw if hub does not exist.
            IsParentVirtualHubPresent(this.ResourceGroupName, this.ParentResourceName);

            PSVHubRouteTable hubRouteTable = new PSVHubRouteTable();

            hubRouteTable.Name   = this.Name;
            hubRouteTable.Routes = this.Route.ToList();
            hubRouteTable.Labels = this.Label.ToList();

            ConfirmAction(
                Properties.Resources.CreatingResourceMessage,
                this.Name,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                WriteObject(this.CreateOrUpdateVHubRouteTable(this.ResourceGroupName, this.ParentResourceName, this.Name, hubRouteTable));
            });
        }
        public override void Execute()
        {
            base.Execute();
            PSVHubRouteTable hubRouteTableToUpdate = null;

            if (ParameterSetName.Equals(CortexParameterSetNames.ByVHubRouteTableObject, StringComparison.OrdinalIgnoreCase))
            {
                hubRouteTableToUpdate = this.InputObject;
                this.ResourceId       = this.InputObject.Id;
                if (string.IsNullOrWhiteSpace(this.ResourceId))
                {
                    throw new PSArgumentException(Properties.Resources.VHubRouteTableNotFound);
                }

                var parsedResourceId = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName  = parsedResourceId.ResourceGroupName;
                this.ParentResourceName = parsedResourceId.ParentResource.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();
                this.Name = parsedResourceId.ResourceName;
            }
            else
            {
                if (ParameterSetName.Equals(CortexParameterSetNames.ByVHubRouteTableResourceId, StringComparison.OrdinalIgnoreCase))
                {
                    var parsedResourceId = new ResourceIdentifier(this.ResourceId);
                    this.ResourceGroupName  = parsedResourceId.ResourceGroupName;
                    this.ParentResourceName = parsedResourceId.ParentResource.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();
                    this.Name = parsedResourceId.ResourceName;
                }
                else if (ParameterSetName.Equals(CortexParameterSetNames.ByVirtualHubObject, StringComparison.OrdinalIgnoreCase))
                {
                    var parentResourceId       = this.ParentObject.Id;
                    var parsedParentResourceId = new ResourceIdentifier(parentResourceId);
                    this.ResourceGroupName  = parsedParentResourceId.ResourceGroupName;
                    this.ParentResourceName = parsedParentResourceId.ResourceName;
                }

                try
                {
                    hubRouteTableToUpdate = this.GetVHubRouteTable(this.ResourceGroupName, this.ParentResourceName, this.Name);
                }
                catch (Exception ex)
                {
                    if (ex is Microsoft.Azure.Management.Network.Models.ErrorException || ex is Rest.Azure.CloudException)
                    {
                        throw new PSArgumentException(Properties.Resources.VHubRouteTableNotFound);
                    }
                    throw;
                }
            }

            // this will thorw if hub does not exist.
            IsParentVirtualHubPresent(this.ResourceGroupName, this.ParentResourceName);

            if (this.Route != null)
            {
                hubRouteTableToUpdate.Routes = this.Route.ToList();
            }

            if (this.Label != null)
            {
                hubRouteTableToUpdate.Labels = this.Label.ToList();
            }

            ConfirmAction(
                Properties.Resources.SettingResourceMessage,
                this.Name,
                () =>
            {
                WriteVerbose(String.Format(Properties.Resources.CreatingLongRunningOperationMessage, this.ResourceGroupName, this.Name));
                WriteObject(this.CreateOrUpdateVHubRouteTable(this.ResourceGroupName, this.ParentResourceName, this.Name, hubRouteTableToUpdate));
            });
        }
        public PSVHubRouteTable CreateOrUpdateVHubRouteTable(string resourceGroupName, string virtualHubName, string routeTableName, PSVHubRouteTable hubRouteTable)
        {
            var hubRouteTableModel = NetworkResourceManagerProfile.Mapper.Map <MNM.HubRouteTable>(hubRouteTable);
            var routeTableCreated  = VHubRouteTableClient.CreateOrUpdate(resourceGroupName, virtualHubName, routeTableName, hubRouteTableModel);

            return(ToPsVHubRouteTable(routeTableCreated));
        }