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 attach(self, target_nic_uuids):
        added_l3_uuid = []
        for nic in target_nic_uuids:
            l3_uuid = test_lib.lib_get_l3_uuid_by_nic(nic)
            self._add_nic(l3_uuid, nic)
            #In zstack, need attach Nic's L3 to SG, before add Nic to SG
            # If SG has been attached to L3, it should not be attached again.
            if l3_uuid in added_l3_uuid:
                continue
            conditions = res_ops.gen_query_conditions('uuid', '=', self.security_group.uuid)
            sg = res_ops.query_resource(res_ops.SECURITY_GROUP, conditions)[0]
            if l3_uuid in sg.attachedL3NetworkUuids:
                added_l3_uuid.append(l3_uuid)
                continue
            added_l3_uuid.append(l3_uuid)
            
            net_ops.attach_security_group_to_l3(self.security_group.uuid, l3_uuid)

        net_ops.add_nic_to_security_group(self.security_group.uuid, target_nic_uuids)
        super(ZstackTestSecurityGroup, self).attach(target_nic_uuids)