@@ -1750,22 +1750,31 @@ public void validateSystemTagInCreateMessage(APICreateMessage cmsg) {
17501750 String hostname = VmSystemTags .HOSTNAME .getTokenByTag (sysTag , VmSystemTags .HOSTNAME_TOKEN );
17511751
17521752 validateHostname (sysTag , hostname );
1753+
1754+ String l3Uuid = msg .getDefaultL3NetworkUuid ();
1755+ if (l3Uuid != null ) {
1756+ validateHostNameOnDefaultL3Network (sysTag , hostname , l3Uuid );
1757+ }
17531758 }
17541759 }
17551760 }
17561761
1757- @ Transactional (readOnly = true )
17581762 private List <SystemTagVO > querySystemTagsByL3 (String tag , String l3Uuid ) {
1759- String sql = "select t" +
1760- " from SystemTagVO t, VmInstanceVO vm, VmNicVO nic" +
1761- " where t.resourceUuid = vm.uuid" +
1762- " and vm.uuid = nic.vmInstanceUuid" +
1763- " and nic.l3NetworkUuid = :l3Uuid" +
1764- " and t.tag = :sysTag" ;
1765- TypedQuery <SystemTagVO > q = dbf .getEntityManager ().createQuery (sql , SystemTagVO .class );
1766- q .setParameter ("l3Uuid" , l3Uuid );
1767- q .setParameter ("sysTag" , tag );
1768- return q .getResultList ();
1763+ return new SQLBatchWithReturn <List <SystemTagVO >>() {
1764+ @ Override
1765+ protected List <SystemTagVO > scripts () {
1766+ String sql = "select t" +
1767+ " from SystemTagVO t, VmInstanceVO vm, VmNicVO nic" +
1768+ " where t.resourceUuid = vm.uuid" +
1769+ " and vm.uuid = nic.vmInstanceUuid" +
1770+ " and nic.l3NetworkUuid = :l3Uuid" +
1771+ " and t.tag = :sysTag" ;
1772+ TypedQuery <SystemTagVO > q = dbf .getEntityManager ().createQuery (sql , SystemTagVO .class );
1773+ q .setParameter ("l3Uuid" , l3Uuid );
1774+ q .setParameter ("sysTag" , tag );
1775+ return q .getResultList ();
1776+ }
1777+ }.execute ();
17691778 }
17701779
17711780 private void validateHostNameOnDefaultL3Network (String tag , String hostname , String l3Uuid ) {
@@ -1789,6 +1798,9 @@ public void validateSystemTag(String resourceUuid, Class resourceType, String sy
17891798 q .select (VmInstanceVO_ .defaultL3NetworkUuid );
17901799 q .add (VmInstanceVO_ .uuid , Op .EQ , resourceUuid );
17911800 String defaultL3Uuid = q .findValue ();
1801+ if (defaultL3Uuid != null ) {
1802+ validateHostNameOnDefaultL3Network (systemTag , hostname , defaultL3Uuid );
1803+ }
17921804 } else if (VmSystemTags .BOOT_ORDER .isMatch (systemTag )) {
17931805 validateBootOrder (systemTag );
17941806 }
0 commit comments