@Override protected String useTagFormat() { return TagUtils.tagPatternToSqlPattern(tagFormat); }
public Map<String, String> getTokensByTag(String tag) { return TagUtils.parseIfMatch(tagFormat, tag); }
public Map<String, List<String>> getSecondaryNetworksFromSystemTags(List<String> systemTags) { Map<String, List<String>> ret = new HashMap<>(); if (systemTags == null) { return ret; } for (String sysTag : systemTags) { if(!VmSystemTags.DUAL_STACK_NIC.isMatch(sysTag)) { continue; } Map<String, String> token = TagUtils.parse(VmSystemTags.DUAL_STACK_NIC.getTagFormat(), sysTag); String primaryL3 = token.get(VmSystemTags.DUAL_STACK_NIC_PRIMARY_L3_TOKEN); String secondaryL3 = token.get(VmSystemTags.DUAL_STACK_NIC_SECONDARY_L3_TOKEN); List<String> l3List = ret.get(primaryL3); if (l3List == null) { l3List = new ArrayList<>(); ret.put(primaryL3, l3List); l3List.add(primaryL3); } l3List.add(secondaryL3); } return ret; }
@Override public boolean isMatch(String tag) { return TagUtils.isMatch(tagFormat, tag); }
public Map<String, String> getStaticIpbySystemTag(List<String> systemTags) { Map<String, String> ret = new HashMap<>(); if (systemTags == null) { return ret; } for (String sysTag : systemTags) { if(!VmSystemTags.STATIC_IP.isMatch(sysTag)) { continue; } Map<String, String> token = TagUtils.parse(VmSystemTags.STATIC_IP.getTagFormat(), sysTag); String l3Uuid = token.get(VmSystemTags.STATIC_IP_L3_UUID_TOKEN); String ip = token.get(VmSystemTags.STATIC_IP_TOKEN); ip = IPv6NetworkUtils.ipv6TagValueToAddress(ip); ret.put(l3Uuid, ip); } return ret; }
public static String tagPatternToSqlPattern(Enum tag) { return tagPatternToSqlPattern(tag.toString()); }
Map<String, String> token = TagUtils.parse(FlatNetworkSystemTags.L3_NETWORK_DHCP_IP.getTagFormat(), sysTag); dhcpServerIp = token.get(FlatNetworkSystemTags.L3_NETWORK_DHCP_IP_TOKEN); if (dhcpServerIp == null) {
public List<Map<String, String>> getTokensOfTagsByResourceUuid(String resourceUuid, Class resourceClass) { List<Map<String, String>> res = new ArrayList<>(); List<String> tags = getTags(resourceUuid, resourceClass); for (String tag : tags) { res.add(TagUtils.parseIfMatch(tagFormat, tag)); } return res; }
@Transactional(readOnly = true) public Map<String, String> findByL3Uuids(Collection<String> l3Uuids) { String sql = "select t.tag, l3.uuid" + " from SystemTagVO t, L3NetworkVO l3" + " where t.resourceType = :ttype" + " and t.tag like :tag" + " and t.resourceUuid = l3.l2NetworkUuid" + " and l3.uuid in (:l3Uuids)" + " group by l3.uuid"; TypedQuery<Tuple> tq = dbf.getEntityManager().createQuery(sql, Tuple.class); tq.setParameter("tag", TagUtils.tagPatternToSqlPattern(KVMSystemTags.L2_BRIDGE_NAME.getTagFormat())); tq.setParameter("l3Uuids", l3Uuids); tq.setParameter("ttype", L2NetworkVO.class.getSimpleName()); List<Tuple> ts = tq.getResultList(); Map<String, String> bridgeNames = new HashMap<>(); for (Tuple t : ts) { String brToken = t.get(0, String.class); String l3Uuid = t.get(1, String.class); bridgeNames.put(l3Uuid, KVMSystemTags.L2_BRIDGE_NAME.getTokenByTag(brToken, KVMSystemTags.L2_BRIDGE_NAME_TOKEN)); } return bridgeNames; } }
Map<String, String> token = TagUtils.parse(FlatNetworkSystemTags.L3_NETWORK_DHCP_IP.getTagFormat(), systemTag); String dhcpServerIp = token.get(FlatNetworkSystemTags.L3_NETWORK_DHCP_IP_TOKEN); dhcpServerIp = IPv6NetworkUtils.ipv6TagValueToAddress(dhcpServerIp);
public Map<String, String> getTokensByResourceUuid(String resourceUuid, Class resourceClass) { String tag = getTag(resourceUuid, resourceClass); if (tag == null) { return null; } return TagUtils.parseIfMatch(tagFormat, tag); }
public void deleteStaticIpByVmUuidAndL3Uuid(String vmUuid, String l3Uuid) { VmSystemTags.STATIC_IP.delete(vmUuid, TagUtils.tagPatternToSqlPattern(VmSystemTags.STATIC_IP.instantiateTag( map(e(VmSystemTags.STATIC_IP_L3_UUID_TOKEN, l3Uuid)) ))); }
public void deleteSecondaryNetworksByVmNic(VmNicInventory nic) { String vmUuid = nic.getVmInstanceUuid(); if (vmUuid == null) { return; } String l3Uuid = nic.getL3NetworkUuid(); Map<String, List<String>> secondaryNetworksMap = getSecondaryNetworksByVmUuid(vmUuid); for (Map.Entry<String, List<String>> e : secondaryNetworksMap.entrySet()) { String primaryL3 = e.getKey(); List<String> secondaryNetworksList = e.getValue(); if (primaryL3.equals(l3Uuid) || secondaryNetworksList.contains(l3Uuid)) { /* delete old systemTags */ for (String uuid : secondaryNetworksList) { VmSystemTags.DUAL_STACK_NIC.delete(vmUuid, TagUtils.tagPatternToSqlPattern(VmSystemTags.DUAL_STACK_NIC.instantiateTag( map(e(VmSystemTags.DUAL_STACK_NIC_PRIMARY_L3_TOKEN, primaryL3), e(VmSystemTags.DUAL_STACK_NIC_SECONDARY_L3_TOKEN, uuid))))); } return; } } } }
" and t.resourceUuid = l3.l2NetworkUuid and l3.uuid in (:l3Uuids)"; TypedQuery<Tuple> tq = dbf.getEntityManager().createQuery(sql, Tuple.class); tq.setParameter("tag", TagUtils.tagPatternToSqlPattern(KVMSystemTags.L2_BRIDGE_NAME.getTagFormat())); tq.setParameter("l3Uuids", l3Uuids); tq.setParameter("ttype", L2NetworkVO.class.getSimpleName()); " and t.tag like :tag and t.resourceUuid = vm.uuid and vm.uuid = :vmUuid"; tq = dbf.getEntityManager().createQuery(sql, Tuple.class); tq.setParameter("tag", TagUtils.tagPatternToSqlPattern(VmSystemTags.HOSTNAME.getTagFormat())); tq.setParameter("ttype", VmInstanceVO.class.getSimpleName()); tq.setParameter("vmUuid", vm.getUuid());
" and t.resourceUuid = l3.l2NetworkUuid and l3.uuid in (:l3Uuids)"; TypedQuery<Tuple> tq = dbf.getEntityManager().createQuery(sql, Tuple.class); tq.setParameter("tag", TagUtils.tagPatternToSqlPattern(KVMSystemTags.L2_BRIDGE_NAME.getTagFormat())); tq.setParameter("l3Uuids", l3Uuids); tq.setParameter("ttype", L2NetworkVO.class.getSimpleName()); " and t.tag like :tag and t.resourceUuid = vm.uuid and vm.uuid in (:vmUuids)"; tq = dbf.getEntityManager().createQuery(sql, Tuple.class); tq.setParameter("tag", TagUtils.tagPatternToSqlPattern(VmSystemTags.HOSTNAME.getTagFormat())); tq.setParameter("ttype", VmInstanceVO.class.getSimpleName()); tq.setParameter("vmUuids", vmDefaultL3.keySet());
VmSystemTags.DUAL_STACK_NIC.delete(vmUuid, TagUtils.tagPatternToSqlPattern(VmSystemTags.DUAL_STACK_NIC.instantiateTag( map(e(VmSystemTags.DUAL_STACK_NIC_PRIMARY_L3_TOKEN, primaryL3), e(VmSystemTags.DUAL_STACK_NIC_SECONDARY_L3_TOKEN, uuid))))); VmSystemTags.DUAL_STACK_NIC.delete(vmUuid, TagUtils.tagPatternToSqlPattern(VmSystemTags.DUAL_STACK_NIC.instantiateTag( map(e(VmSystemTags.DUAL_STACK_NIC_PRIMARY_L3_TOKEN, primaryL3), e(VmSystemTags.DUAL_STACK_NIC_SECONDARY_L3_TOKEN, l3Uuid)))));
VmSystemTags.DUAL_STACK_NIC.delete(vmUuid, TagUtils.tagPatternToSqlPattern(VmSystemTags.DUAL_STACK_NIC.instantiateTag( map(e(VmSystemTags.DUAL_STACK_NIC_PRIMARY_L3_TOKEN, primaryL3), e(VmSystemTags.DUAL_STACK_NIC_SECONDARY_L3_TOKEN, uuid)))));
public void setStaticIp(String vmUuid, String l3Uuid, String ip) { SimpleQuery<SystemTagVO> q = dbf.createQuery(SystemTagVO.class); q.select(SystemTagVO_.uuid); q.add(SystemTagVO_.resourceType, Op.EQ, VmInstanceVO.class.getSimpleName()); q.add(SystemTagVO_.resourceUuid, Op.EQ, vmUuid); q.add(SystemTagVO_.tag, Op.LIKE, TagUtils.tagPatternToSqlPattern(VmSystemTags.STATIC_IP.instantiateTag( map(e(VmSystemTags.STATIC_IP_L3_UUID_TOKEN, l3Uuid)) ))); final String tagUuid = q.findValue(); /* '::' is token used by systemtag, replace with "--" */ ip = IPv6NetworkUtils.ipv6AddessToTagValue(ip); if (tagUuid == null) { SystemTagCreator creator = VmSystemTags.STATIC_IP.newSystemTagCreator(vmUuid); creator.setTagByTokens(map( e(VmSystemTags.STATIC_IP_L3_UUID_TOKEN, l3Uuid), e(VmSystemTags.STATIC_IP_TOKEN, ip) )); creator.create(); } else { VmSystemTags.STATIC_IP.updateByTagUuid(tagUuid, VmSystemTags.STATIC_IP.instantiateTag(map( e(VmSystemTags.STATIC_IP_L3_UUID_TOKEN, l3Uuid), e(VmSystemTags.STATIC_IP_TOKEN, ip) ))); } }
String bridgeName = SQL.New("select t.tag from SystemTagVO t, L3NetworkVO l3 where t.resourceType = :ttype and t.tag like :tag" + " and t.resourceUuid = l3.l2NetworkUuid and l3.uuid = :l3Uuid", String.class) .param("tag", TagUtils.tagPatternToSqlPattern(KVMSystemTags.L2_BRIDGE_NAME.getTagFormat())) .param("l3Uuid", forwardDnsStruct.getL3Network().getUuid()) .param("ttype", L2NetworkVO.class.getSimpleName())