Ejemplo n.º 1
0
        /// <summary>
        /// TODO: GENERATOR Make use of the entity tags on the resource - we may need to add to the generated management client
        /// </summary>
        /// <param name="rules">The new set of network security rules</param>
        /// <returns>A network security group with the given set of rules merged with thsi one</returns>
        public ArmOperation <NetworkSecurityGroup> UpdateRules(NetworkSecurityGroupData model, CancellationToken cancellationToken = default, params SecurityRule[] rules)
        {
            foreach (var rule in rules)
            {
                // Note that this makes use of the
                var matchingRule = model.Model.SecurityRules.FirstOrDefault(r => ResourceIdentifier.Equals(r.Id, rule.Id));
                if (matchingRule != null)
                {
                    matchingRule.Access      = rule.Access;
                    matchingRule.Description = rule.Description;
                    matchingRule.DestinationAddressPrefix   = rule.DestinationAddressPrefix;
                    matchingRule.DestinationAddressPrefixes = rule.DestinationAddressPrefixes;
                    matchingRule.DestinationPortRange       = rule.DestinationPortRange;
                    matchingRule.DestinationPortRanges      = rule.DestinationPortRanges;
                    matchingRule.Direction             = rule.Direction;
                    matchingRule.Priority              = rule.Priority;
                    matchingRule.Protocol              = rule.Protocol;
                    matchingRule.SourceAddressPrefix   = rule.SourceAddressPrefix;
                    matchingRule.SourceAddressPrefixes = rule.SourceAddressPrefixes;
                    matchingRule.SourcePortRange       = rule.SourcePortRange;
                    matchingRule.SourcePortRanges      = rule.SourcePortRanges;
                }
                else
                {
                    model.Model.SecurityRules.Add(rule);
                }
            }

            return(new PhArmOperation <NetworkSecurityGroup, Azure.ResourceManager.Network.Models.NetworkSecurityGroup>(Operations.StartCreateOrUpdate(Id.ResourceGroup, Id.Name, model.Model),
                                                                                                                        n =>
            {
                Resource = new NetworkSecurityGroupData(n);
                return new NetworkSecurityGroup(ClientOptions, Resource as NetworkSecurityGroupData);
            }));
        }
Ejemplo n.º 2
0
 public async override Task <ArmResponse <NetworkSecurityGroup> > GetAsync(CancellationToken cancellationToken = default)
 {
     return(new PhArmResponse <NetworkSecurityGroup, Azure.ResourceManager.Network.Models.NetworkSecurityGroup>(await Operations.GetAsync(Id.ResourceGroup, Id.Name, null, cancellationToken),
                                                                                                                n =>
     {
         Resource = new NetworkSecurityGroupData(n);
         return new NetworkSecurityGroup(ClientOptions, Resource as NetworkSecurityGroupData);
     }));
 }
Ejemplo n.º 3
0
 public override ArmResponse <NetworkSecurityGroup> Get()
 {
     return(new PhArmResponse <NetworkSecurityGroup, Azure.ResourceManager.Network.Models.NetworkSecurityGroup>(Operations.Get(Id.ResourceGroup, Id.Name),
                                                                                                                n =>
     {
         Resource = new NetworkSecurityGroupData(n);
         return new NetworkSecurityGroup(ClientOptions, Resource as NetworkSecurityGroupData);
     }));
 }
Ejemplo n.º 4
0
        public async Task <ArmOperation <NetworkSecurityGroup> > StartAddTagAsync(string key, string value, CancellationToken cancellationToken = default)
        {
            var patchable = new TagsObject();

            patchable.Tags[key] = value;
            return(new PhArmOperation <NetworkSecurityGroup, Azure.ResourceManager.Network.Models.NetworkSecurityGroup>(await Operations.UpdateTagsAsync(Id.ResourceGroup, Id.Name, patchable, cancellationToken),
                                                                                                                        n =>
            {
                Resource = new NetworkSecurityGroupData(n);
                return new NetworkSecurityGroup(ClientOptions, Resource as NetworkSecurityGroupData);
            }));
        }
Ejemplo n.º 5
0
        public ArmOperation <NetworkSecurityGroup> StartAddTag(string key, string value)
        {
            var patchable = new TagsObject();

            patchable.Tags[key] = value;
            return(new PhArmOperation <NetworkSecurityGroup, Azure.ResourceManager.Network.Models.NetworkSecurityGroup>(Operations.UpdateTags(Id.ResourceGroup, Id.Name, patchable),
                                                                                                                        n =>
            {
                Resource = new NetworkSecurityGroupData(n);
                return new NetworkSecurityGroup(ClientOptions, Resource as NetworkSecurityGroupData);
            }));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructs an object used to create a subnet.
        /// </summary>
        /// <param name="subnetCidr"> The CIDR of the resource. </param>
        /// <param name="group"> The network security group of the resource. </param>
        /// <returns> A builder with <see cref="Subnet"/> and <see cref="Subnet"/>. </returns>
        public SubnetBuilder Construct(string subnetCidr, NetworkSecurityGroupData group = null)
        {
            var subnet = new Azure.ResourceManager.Network.Models.Subnet()
            {
                AddressPrefix = subnetCidr,
            };

            if (null != group)
            {
                subnet.NetworkSecurityGroup = group.Model;
            }

            return(new SubnetBuilder(this, new SubnetData(subnet)));
        }
        public ArmBuilder <Subnet, SubnetData> Construct(string name, string cidr, Location location = null, NetworkSecurityGroupData group = null)
        {
            var subnet = new Azure.ResourceManager.Network.Models.Subnet()
            {
                Name          = name,
                AddressPrefix = cidr,
            };

            if (null != group)
            {
                subnet.NetworkSecurityGroup = group.Model;
            }

            return(new ArmBuilder <Subnet, SubnetData>(this, new SubnetData(subnet, location ?? DefaultLocation)));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NetworkSecurityGroup"/> class.
 /// </summary>
 /// <param name="operations"> The client parameters to use in these operations. </param>
 /// <param name="resource"> The resource that is the target of operations. </param>
 internal NetworkSecurityGroup(ResourceOperationsBase operations, NetworkSecurityGroupData resource)
     : base(operations, resource.Id)
 {
     Data = resource;
 }
 /// <summary>
 /// Create an NSG with the given open TCP ports
 /// </summary>
 /// <param name="openPorts">The set of TCP ports to open</param>
 /// <returns>An NSG, with the given TCP ports open</returns>
 public static NetworkSecurityGroup NetworkSecurityGroup(this ResourceGroupOperations resourceGroup, NetworkSecurityGroupData networkSecurityGroup)
 {
     return(new NetworkSecurityGroup(resourceGroup.ClientOptions, networkSecurityGroup));
 }
 public NetworkSecurityGroup(AzureResourceManagerClientOptions options, NetworkSecurityGroupData resource)
     : base(options, resource.Id)
 {
     Data = resource;
 }