コード例 #1
0
def create_sg(sg_option, l3_uuid, nic_uuid):
    try:
        #create security group
        sg = net_ops.create_security_group(sg_option)
        #add rule
        net_ops.add_rules_to_security_group(sg.uuid, rules, session_uuid)

        #attach to l3
        net_ops.attach_security_group_to_l3(sg.uuid, l3_uuid, session_uuid)

        #attach to vm
        net_ops.add_nic_to_security_group(sg.uuid, [nic_uuid], session_uuid)
    except:
        exc_info.append(sys.exc_info())
コード例 #2
0
    def add_rule(self, target_rule_objs):
        rules = net_ops.add_rules_to_security_group(self.security_group.uuid, target_rule_objs).rules
        for rule in rules:
            if rule.protocol == inventory.TCP:
                if rule.type == inventory.INGRESS:
                    self._add_rule(rule, self.tcp_ingress_rule)
                else:
                    self._add_rule(rule, self.tcp_egress_rule)
            elif rule.protocol == inventory.UDP:
                if rule.type == inventory.INGRESS:
                    self._add_rule(rule, self.udp_ingress_rule)
                else:
                    self._add_rule(rule, self.udp_egress_rule)
            elif rule.protocol == inventory.ICMP:
                if rule.type == inventory.INGRESS:
                    self._add_rule(rule, self.icmp_ingress_rule)
                else:
                    self._add_rule(rule, self.icmp_egress_rule)

        return rules