Esempio n. 1
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (string.Equals(
                    this.ParameterSetName,
                    Constants.InputObjectParameterSet))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ManagedNetworkObject.Id);
                this.ResourceGroupName  = resourceIdentifier.ResourceGroupName;
                this.ManagedNetworkName = resourceIdentifier.ResourceName;
            }

            var present = IsManagedNetworkGroupPresent(ResourceGroupName, ManagedNetworkName, Name);

            ConfirmAction(
                Force.IsPresent,
                string.Format(Constants.ConfirmOverwriteResource, Name),
                Constants.CreatingResource,
                Name,
                () =>
            {
                PSManagedNetworkGroup managedNetworkGroup = CreateManagedNetworkGroup();
                WriteObject(managedNetworkGroup);
            },
                () => present);
        }
Esempio n. 2
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            switch (this.ParameterSetName)
            {
            case ParameterSetNames.ResourceIdParameterSet:
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName  = resourceIdentifier.ResourceGroupName;
                this.ManagedNetworkName = resourceIdentifier.ParentResource.Split('/')[1];
                this.Name = resourceIdentifier.ResourceName;
                break;

            case ParameterSetNames.InputObjectParameterSet:
                resourceIdentifier      = new ResourceIdentifier(this.InputObject.Id);
                this.ResourceGroupName  = resourceIdentifier.ResourceGroupName;
                this.ManagedNetworkName = resourceIdentifier.ParentResource.Split('/')[1];
                this.Name = resourceIdentifier.ResourceName;
                break;

            case ParameterSetNames.ManagedNetworkObjectParameterSet:
                resourceIdentifier      = new ResourceIdentifier(this.ManagedNetworkObject.Id);
                this.ResourceGroupName  = resourceIdentifier.ResourceGroupName;
                this.ManagedNetworkName = resourceIdentifier.ResourceName;
                break;

            default:
                break;
            }

            var present = IsManagedNetworkGroupPresent(ResourceGroupName, ManagedNetworkName, Name);

            if (!present)
            {
                throw new Exception(string.Format(Properties.Resources.ManagedNetworkGroupDoesNotExist, this.Name, this.ManagedNetworkName, this.ResourceGroupName));
            }
            ConfirmAction(
                Force.IsPresent,
                string.Format(Properties.Resources.ConfirmOverwriteResource, Name),
                Properties.Resources.UpdatingResource,
                Name,
                () =>
            {
                PSManagedNetworkGroup managedNetworkGroup = UpdateManagedNetworkGroup();
                WriteObject(managedNetworkGroup);
            },
                () => present);
        }
Esempio n. 3
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            if (string.Equals(
                    this.ParameterSetName,
                    Constants.ResourceIdParameterSet))
            {
                var resourceIdentifier = new ResourceIdentifier(this.ResourceId);
                this.ResourceGroupName  = resourceIdentifier.ResourceGroupName;
                this.ManagedNetworkName = resourceIdentifier.ParentResource;
                this.Name = resourceIdentifier.ResourceName;
            }
            else if (string.Equals(
                         this.ParameterSetName,
                         Constants.InputObjectParameterSet))
            {
                var resourceIdentifier = new ResourceIdentifier(this.InputObject.Id);
                this.ResourceGroupName  = resourceIdentifier.ResourceGroupName;
                this.ManagedNetworkName = resourceIdentifier.ParentResource;
                this.Name = resourceIdentifier.ResourceName;

                this.ManagementGroupIds = this.ManagementGroupIds ?? this.InputObject.ManagementGroups.Select(resource => resource.Id).ToList();
                this.SubscriptionIds    = this.SubscriptionIds ?? this.InputObject.Subscriptions.Select(resource => resource.Id).ToList();
                this.VirtualNetworkIds  = this.VirtualNetworkIds ?? this.InputObject.VirtualNetworks.Select(resource => resource.Id).ToList();
                this.SubnetIds          = this.SubnetIds ?? this.InputObject.Subnets.Select(resource => resource.Id).ToList();
            }

            var present = IsManagedNetworkPeeringPolicyPresent(ResourceGroupName, ManagedNetworkName, Name);

            if (!present)
            {
                throw new Exception(string.Format(Constants.ManagedNetworkGroupDoesNotExist, this.Name, this.ManagedNetworkName, this.ResourceGroupName));
            }
            ConfirmAction(
                Force.IsPresent,
                string.Format(Constants.ConfirmOverwriteResource, Name),
                Constants.UpdatingResource,
                Name,
                () =>
            {
                PSManagedNetworkGroup managedNetworkGroup = UpdateManagedNetworkGroup();
                WriteObject(managedNetworkGroup);
            },
                () => present);
        }
Esempio n. 4
0
        private PSManagedNetworkGroup CreateManagedNetworkGroup()
        {
            PSManagedNetworkGroup psManagedNetworkGroup = new PSManagedNetworkGroup();

            if (this.ManagementGroupIdList != null)
            {
                psManagedNetworkGroup.ManagementGroups = this.ManagementGroupIdList.Select(id => new PSResourceId()
                {
                    Id = id
                }).ToList();
            }

            if (this.SubscriptionIdList != null)
            {
                psManagedNetworkGroup.Subscriptions = this.SubscriptionIdList.Select(id => new PSResourceId()
                {
                    Id = id
                }).ToList();
            }

            if (this.VirtualNetworkIdList != null)
            {
                psManagedNetworkGroup.VirtualNetworks = this.VirtualNetworkIdList.Select(id => new PSResourceId()
                {
                    Id = id
                }).ToList();
            }

            if (this.SubnetIdList != null)
            {
                psManagedNetworkGroup.Subnets = this.SubnetIdList.Select(id => new PSResourceId()
                {
                    Id = id
                }).ToList();
            }

            var sdkManagedNetworkGroup = ManagedNetworkResourceManagerProfile.Mapper.Map <ManagedNetworkGroup>(psManagedNetworkGroup);

            sdkManagedNetworkGroup.Location = this.Location;
            var putSdkResponse = this.ManagedNetworkManagementClient.ManagedNetworkGroups.CreateOrUpdate(sdkManagedNetworkGroup, this.ResourceGroupName, this.ManagedNetworkName, this.Name);
            var putPSResponse  = ManagedNetworkResourceManagerProfile.Mapper.Map <PSManagedNetworkGroup>(putSdkResponse);

            return(putPSResponse);
        }