Ejemplo n.º 1
0
    def Run(self, args):
        self.new_allowed = firewalls_utils.ParseAllowed(
            args.allow, self.messages)
        args_unset = (args.allow is None and args.description is None
                      and args.source_ranges is None
                      and args.source_tags is None
                      and args.target_tags is None)

        if args_unset:
            raise calliope_exceptions.ToolException(
                'At least one property must be modified.')

        return super(UpdateFirewall, self).Run(args)
Ejemplo n.º 2
0
    def CreateRequests(self, args):
        """Returns a list of requests necessary for adding firewall rules."""
        if not args.source_ranges and not args.source_tags:
            args.source_ranges = ['0.0.0.0/0']

        allowed = firewalls_utils.ParseAllowed(args.allow, self.messages)

        network_ref = self.CreateGlobalReference(args.network,
                                                 resource_type='networks')
        firewall_ref = self.CreateGlobalReference(args.name,
                                                  resource_type='firewalls')

        request = self.messages.ComputeFirewallsInsertRequest(
            firewall=self.messages.Firewall(allowed=allowed,
                                            name=firewall_ref.Name(),
                                            description=args.description,
                                            network=network_ref.SelfLink(),
                                            sourceRanges=args.source_ranges,
                                            sourceTags=args.source_tags,
                                            targetTags=args.target_tags),
            project=self.project)
        return [request]