예제 #1
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        ref = self.FIREWALL_POLICY_ARG.ResolveAsResource(args,
                                                         holder.resources,
                                                         with_project=False)
        org_firewall_policy = client.OrgFirewallPolicy(
            ref=ref,
            compute_client=holder.client,
            resources=holder.resources,
            version=six.text_type(self.ReleaseTrack()).lower())

        parent_id = None
        if args.IsSpecified('organization'):
            parent_id = 'organizations/' + args.organization
        if args.IsSpecified('folder'):
            parent_id = 'folders/' + args.folder
        if parent_id is None:
            log.error(
                'Must specify parent id with --organization=ORGANIZATION or'
                '--folder=FOLDER')
            sys.exit()
        fp_id = firewall_policies_utils.GetFirewallPolicyId(
            org_firewall_policy, ref.Name(), organization=args.organization)
        return org_firewall_policy.Move(only_generate_request=False,
                                        fp_id=fp_id,
                                        parent_id=parent_id)
예제 #2
0
 def Run(self, args):
     holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
     ref = self.FIREWALL_POLICY_ARG.ResolveAsResource(args,
                                                      holder.resources,
                                                      with_project=False)
     org_firewall_policy = client.OrgFirewallPolicy(
         ref=ref,
         compute_client=holder.client,
         resources=holder.resources,
         version=six.text_type(self.ReleaseTrack()).lower())
     fp_id = firewall_policies_utils.GetFirewallPolicyId(
         org_firewall_policy, ref.Name(), organization=args.organization)
     return org_firewall_policy.Delete(fp_id=fp_id,
                                       only_generate_request=False)
예제 #3
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        org_firewall_policy = client.OrgFirewallPolicy(
            compute_client=holder.client,
            resources=holder.resources,
            version=six.text_type(self.ReleaseTrack()).lower())

        if args.IsSpecified('organization'):
            parent_id = 'organizations/' + args.organization
        elif args.IsSpecified('folder'):
            parent_id = 'folders/' + args.folder
        firewall_policy = holder.client.messages.FirewallPolicy(
            description=args.description, displayName=args.short_name)
        return org_firewall_policy.Create(firewall_policy=firewall_policy,
                                          parent_id=parent_id,
                                          only_generate_request=False)
예제 #4
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        org_firewall_policy = client.OrgFirewallPolicy(
            compute_client=holder.client,
            resources=holder.resources,
            version=six.text_type(self.ReleaseTrack()).lower())

        name = None
        attachment_target = None
        replace_existing_association = False

        if args.IsSpecified('name'):
            name = args.name

        attachment_target = None
        if args.IsSpecified('folder'):
            attachment_target = 'folders/' + args.folder
            if name is None:
                name = 'folder-' + args.folder

        if args.IsSpecified('organization') and attachment_target is None:
            attachment_target = 'organizations/' + args.organization
            if name is None:
                name = 'organization-' + args.organization

        if attachment_target is None:
            log.error(
                'Must specify attachment target with --organization=ORGANIZATION or '
                '--folder=FOLDER')
            sys.exit()

        replace_existing_association = False
        if args.replace_association_on_target:
            replace_existing_association = True

        association = holder.client.messages.FirewallPolicyAssociation(
            attachmentTarget=attachment_target, name=name)

        firewall_policy_id = firewall_policies_utils.GetFirewallPolicyId(
            org_firewall_policy,
            args.firewall_policy,
            organization=args.organization)
        return org_firewall_policy.AddAssociation(
            association=association,
            firewall_policy_id=firewall_policy_id,
            replace_existing_association=replace_existing_association,
            only_generate_request=False)
예제 #5
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        org_firewall_policy = client.OrgFirewallPolicy(
            compute_client=holder.client,
            resources=holder.resources,
            version=six.text_type(self.ReleaseTrack()).lower())

        target_resource = None

        if args.IsSpecified('organization'):
            target_resource = 'organizations/' + args.organization

        elif args.IsSpecified('folder'):
            target_resource = 'folders/' + args.folder
        res = org_firewall_policy.ListAssociations(
            target_resource=target_resource, only_generate_request=False)
        if not res:
            return None
        return res[0].associations