Add a rule to the SecurityGroup object.  Note that this method
        only changes the local version of the object.  No information
        is sent to EC2.
353578
def add_rule(self, ip_protocol, from_port, to_port,
                 src_group_name, src_group_owner_id, cidr_ip):
        
        rule = IPPermissions(self)
        rule.ip_protocol = ip_protocol
        rule.from_port = from_port
        rule.to_port = to_port
        self.rules.append(rule)
        rule.add_grant(src_group_name, src_group_owner_id, cidr_ip)
1098272
def grant(self, source_cidr):
        
        self.manager.api.secgroup_rules.create(self.id, source_cidr)
389299
private void revokeClassicDbSecurityGroup(String groupName, String sourceCidr) throws CloudException, InternalException {
        Map<String,String> parameters = getProvider().getStandardRdsParameters(getProvider().getContext(), REVOKE_DB_SECURITY_GROUP_INGRESS);

        parameters.put("CIDRIP", sourceCidr);
        parameters.put("DBSecurityGroupName", groupName);
        EC2Method method = new EC2Method(SERVICE_ID, getProvider(), parameters);
        method.invoke();
    }
133941
def create_security_group
      aws_ec2 = ec2_obj

      name = nil

      loop do
        name = 'chef-workflow-' + (0..rand(10).to_i).map { rand(0..9).to_s }.join("")

        if_debug(3) do
          $stderr.puts "Seeing if security group name #{name} is taken"
        end

        break unless aws_ec2.security_groups.filter('group-name', [name]).first
        sleep 0.3
      end

      group = aws_ec2.security_groups.create(name)

      security_group_open_ports.each do |port|
        group.authorize_ingress(:tcp, port)
        group.authorize_ingress(:udp, port)
      end

      group.authorize_ingress(:tcp, (0..65535), group)
      group.authorize_ingress(:udp, (0..65535), group)

      # XXX I think the name should be enough, but maybe this'll cause a problem.
      File.binwrite(security_group_setting_path, Marshal.dump([name]))
      return [name]
    end
824988
public void bindInstanceToSecurityGroup(BindSecurityGroupRequest request) {
        checkNotNull(request, "request should not be null.");
        checkStringNotEmpty(request.getInstanceId(), "request instanceId should not be empty.");
        checkStringNotEmpty(request.getSecurityGroupId(), "request securityGroupId should not be empty.");
        InternalRequest internalRequest = this.createRequest(
                request, HttpMethodName.PUT, INSTANCE_PREFIX, request.getInstanceId());
        internalRequest.addParameter(InstanceAction.bind.name(), null);
        fillPayload(internalRequest, request);
        this.invokeHttpClient(internalRequest, AbstractBceResponse.class);
    }
1124688
def show_security_group_rule(self, security_group_rule, **_params):
        """"""
        return self.get(self.security_group_rule_path % (security_group_rule),
                        params=_params)
1149698
def create_secgroup(self, name, description):
        
        return self.ec2.create_security_group(name, description)
        log.debug("... created group %s" % name)
1028511
def setup(self):
        self.client = self._get_client()
        sg = self._create_isolation_security_group()
        if self.exists is not True:
            acl = self._create_network_acl()
            self._add_network_acl_entries(acl)
            self._add_security_group_rule(sg)
        self._add_security_group_to_instance(sg)

        """"""
        if self.dry_run is not False:
            self._add_security_group_rule(sg)
            self._add_security_group_to_instance(sg)
924771
def remove(env, securitygroup_id, rule_id):
    """"""
    mgr = SoftLayer.NetworkManager(env.client)

    ret = mgr.remove_securitygroup_rule(securitygroup_id, rule_id)

    if not ret:
        raise exceptions.CLIAbort("Failed to remove security group rule")

    table = formatting.Table(REQUEST_BOOL_COLUMNS)
    table.add_row([ret['requestId']])

    env.fout(table)
1090490
def security_group_rule_delete(auth=None, **kwargs):
    '''
    

    '''
    cloud = get_operator_cloud(auth)
    kwargs = _clean_kwargs(**kwargs)
    return cloud.delete_security_group_rule(**kwargs)
1308290
def filter_existing_rules(self, rules, group):
        
        tmp = []
        for rule in rules:

            def eq(x):
                # returns True if this existing AWS rule matches the one we want to create
                assert isinstance(x, boto.ec2.securitygroup.IPPermissions)
                # these are simple catches that determine if we can rule out
                # the existing rule
                group_match = False
                if rule.group_name:
                    logger.debug("Checking for possible group name match %s", x.grants[0].group_id)

                if rule.group_name and x.grants[0].group_id \
                    and rule.group_name != self.get_group(x.grants[0].group_id).name:
                    logger.debug("Group name %s didn't match %s", rule.group_name, x.grants[0].name)
                    return False

                if x.ip_protocol != rule.protocol:
                    logger.debug("ruled out due to protocol: %s vs %s", x.ip_protocol, rule.protocol)
                    return False

                if int(x.from_port) != int(rule.from_port):
                    logger.debug("ruled out due to from_port: %s vs %s", int(x.from_port), int(rule.from_port))
                    return False

                if int(x.to_port) != (rule.to_port):
                    logger.debug("ruled out due to to_port: %s vs %s", int(x.to_port), int(rule.to_port))
                    return False

                # final checks - if one of these rules matches we already have a matching rule
                # and we return True
                if rule.address and not filter(lambda y: y.cidr_ip == rule.address, x.grants ):
                    logger.debug("%s not found in grants", rule.address)
                    return False

                logger.debug("%s %s ok", rule.address, rule.group_name)
                logger.debug("port_from: %s %s", rule.from_port, x.from_port)
                logger.debug("port_to: %s %s", rule.to_port, x.to_port)
                logger.debug("group: %s %s", rule.group_name, x.to_port)
                return True

            logger.debug("Applying rules for %s", group.name)
            filtered = filter(eq, group.rules)

            if not filtered:
                logger.debug(filtered)
                logger.debug("Applying rule %s against %s", rule, group.rules)
                tmp.append(rule)
        return tmp
767396
def create_secgroup(self, name, desc):
        
        self.nova.security_groups.create(name, desc)
868367
def apply(self, vpc):
        
        assert vpc is not None
        # make sure we're up to date
        self.reload_remote_groups()

        vpc_groups = self.vpc_groups(vpc)
        self._apply_groups(vpc)

        # reloads groups from AWS, the authority
        self.reload_remote_groups()
        vpc_groups = self.vpc_groups(vpc)


        groups = {k.name:k for k in vpc_groups}

        for x,y in self.config.items():
            # process 1 security group at a time
            group = groups[x]
            if y.get('rules'):
                # apply all rule changes
                rules = [Rule.parse(rule) for rule in y.get('rules')]
                rules = list(itertools.chain(*rules))

                rules = self.filter_existing_rules(rules, group)
                # need to use chain because multiple rules can be created for a single stanza
                for rule in rules:
                    group_name = groups.get(rule.group_name, None)
                    if group_name and rule.address:
                        raise Exception("Can't auth an address and a group")

                    logger.debug("Authorizing %s %s %s to address:%s name:%s", rule.protocol,
                                 rule.from_port, rule.to_port, rule.address, rule.group_name)

                    group_to_authorize = groups.get(rule.group_name, None)

                    try:
                        group.authorize(rule.protocol,
                                    rule.from_port,
                                    rule.to_port,
                                    rule.address,
                                    group_to_authorize, None)
                    except Exception as e:
                        print "could not authorize group %s" % group_to_authorize
                        raise

                # apply rules

        return self
289989
public void setSecurityGroups(java.util.Collection<SecurityGroup> securityGroups) {
        if (securityGroups == null) {
            this.securityGroups = null;
            return;
        }

        this.securityGroups = new java.util.ArrayList<SecurityGroup>(securityGroups);
    }
1189442
def cli(env, securitygroup_id):
    """"""
    mgr = SoftLayer.NetworkManager(env.client)
    if not mgr.delete_securitygroup(securitygroup_id):
        raise exceptions.CLIAbort("Failed to delete security group")
444340
private void authorizeClassicDbSecurityGroup(String groupName, String sourceCidr) throws CloudException, InternalException {
        Map<String,String> parameters = getProvider().getStandardRdsParameters(getProvider().getContext(), AUTHORIZE_DB_SECURITY_GROUP_INGRESS);
        parameters.put("DBSecurityGroupName", groupName);
        parameters.put("CIDRIP", sourceCidr);
        EC2Method method = new EC2Method(SERVICE_ID, getProvider(), parameters);
        try {
            method.invoke();
        }
        catch( EC2Exception e ) {
            String code = e.getCode();
            if( code != null && code.equals("AuthorizationAlreadyExists") ) {
                return;
            }
            throw new CloudException(e);
        }
    }
1167102
def parse_security_group(self, global_params, region, security_group):
        
        name = security_group.pop('ClusterSecurityGroupName')
        security_group['name'] = name
        self.security_groups['name'] = security_group