Revision f789d500

View differences:

include/VirtualMachine.h
1209 1209
            vector<VectorAttribute *>& pci_dev);
1210 1210

  
1211 1211
    /**
1212
     * Returns the list of Cluster IDs where the VM can be deployed, based
1213
     * on the Datastores and VirtualNetworks requested
1214
     *
1215
     * @param cluster_ids set of Cluster IDs
1216
     * @param error_str Returns the error reason, if any
1217
     * @return 0 on success
1218
     */
1219
    int get_cluster_requirements(set<int>& cluster_ids, string& error_str);
1220

  
1221
    /**
1212 1222
     *  Checks if the resize parameters are valid
1213 1223
     *    @param cpu New CPU. 0 means unchanged.
1214 1224
     *    @param memory New MEMORY. 0 means unchanged.
src/rm/RequestManagerVirtualMachine.cc
990 990
    PoolObjectAuth * auth_ds_perms;
991 991

  
992 992
    int    c_hid;
993
    int    c_cluster_id;
994 993
    int    c_ds_id;
995 994
    string c_tm_mad, tm_mad;
996 995
    bool   c_is_public_cloud;
997 996

  
997
    set<int> cluster_ids;
998
    string   tmp_str;
999

  
998 1000
    bool auth = false;
1001
    bool ds_migr;
999 1002

  
1000 1003
    string error;
1001 1004

  
......
1153 1156
        return;
1154 1157
    }
1155 1158

  
1159
    vm->get_cluster_requirements(cluster_ids, tmp_str);
1160

  
1156 1161
    vm->unlock();
1157 1162

  
1158
    // Check we are in the same cluster
1163
    // Check we are migrating to a compatible cluster
1159 1164
    Host * host = nd.get_hpool()->get(c_hid, true);
1160 1165

  
1161 1166
    if (host == 0)
......
1165 1170
        failure_response(NO_EXISTS, att);
1166 1171
    }
1167 1172

  
1168
    c_cluster_id = host->get_cluster_id();
1169

  
1170 1173
    c_is_public_cloud = host->is_public_cloud();
1171 1174

  
1172 1175
    host->unlock();
1173 1176

  
1174
    if ( c_cluster_id != cluster_id )
1177
    if (cluster_ids.count(cluster_id) == 0)
1175 1178
    {
1176 1179
        ostringstream oss;
1177 1180

  
1178
        oss << "Cannot migrate to a different cluster. VM running in a host"
1179
            << " in " << object_name(PoolObjectSQL::CLUSTER) << " ["
1180
            << c_cluster_id << "] , and new host is in "
1181
            << object_name(PoolObjectSQL::CLUSTER) << " [" << cluster_id << "]";
1181
        oss << "Cannot migrate to host [" << hid << "]. Host is in cluster ["
1182
            << cluster_id << "], and VM requires to be placed on cluster ["
1183
            << one_util::join(cluster_ids, ',') << "]";
1182 1184

  
1183 1185
        att.resp_msg = oss.str();
1184 1186
        failure_response(ACTION, att);
......
1196 1198

  
1197 1199
    if (ds_id != -1)
1198 1200
    {
1199
        bool ds_migr;
1200

  
1201 1201
        if ( c_ds_id != ds_id && live )
1202 1202
        {
1203 1203
            att.resp_msg = "A migration to a different system datastore "
......
1218 1218
            return;
1219 1219
        }
1220 1220

  
1221
        if (ds_cluster_ids.count(c_cluster_id) == 0)
1222
        {
1223
            ostringstream oss;
1224

  
1225
            oss << "Cannot migrate to a different cluster. VM running in a host"
1226
                << " in " << object_name(PoolObjectSQL::CLUSTER)
1227
                << " [" << c_cluster_id << "] , and new system datastore is in "
1228
                << object_name(PoolObjectSQL::CLUSTER)
1229
                << " [" << one_util::join(ds_cluster_ids, ',') << "]";
1230

  
1231
            att.resp_msg = oss.str();
1232
            failure_response(ACTION, att);
1233

  
1234
            return;
1235
        }
1236

  
1237 1221
        if (c_tm_mad != tm_mad)
1238 1222
        {
1239 1223
            att.resp_msg = "Cannot migrate to a system datastore with a different TM driver";
......
1245 1229
    else
1246 1230
    {
1247 1231
        ds_id  = c_ds_id;
1248
        tm_mad = c_tm_mad;
1232

  
1233
        if (get_ds_information(ds_id, ds_cluster_ids, tm_mad, att, ds_migr) != 0)
1234
        {
1235
            return;
1236
        }
1237
    }
1238

  
1239
    if (ds_cluster_ids.count(cluster_id) == 0)
1240
    {
1241
        ostringstream oss;
1242

  
1243
        oss << "Cannot migrate to host [" << hid << "] and system datastore [" << ds_id << "]. Host is in cluster ["
1244
            << cluster_id << "], and the datastore is in cluster ["
1245
            << one_util::join(ds_cluster_ids, ',') << "]";
1246

  
1247
        att.resp_msg = oss.str();
1248
        failure_response(ACTION, att);
1249

  
1250
        return;
1249 1251
    }
1250 1252

  
1251 1253
    // ------------------------------------------------------------------------
src/vm/VirtualMachine.cc
1475 1475

  
1476 1476
/* ------------------------------------------------------------------------ */
1477 1477

  
1478
int VirtualMachine::automatic_requirements(string& error_str)
1478
int VirtualMachine::get_cluster_requirements(set<int>& cluster_ids, string& error_str)
1479 1479
{
1480
    int num_vatts;
1481
    vector<const VectorAttribute  *> vatts;
1482

  
1483 1480
    ostringstream   oss;
1484
    string          requirements;
1485
    set<int>        cluster_ids;
1486

  
1487
    set<string> clouds;
1488

  
1489
    int num_public = get_public_clouds(clouds);
1481
    int             num_vatts;
1482
    vector<const VectorAttribute  *> vatts;
1490 1483

  
1491 1484
    int incomp_id;
1492 1485
    int rc;
......
1562 1555
        }
1563 1556
    }
1564 1557

  
1565
    if ( !cluster_ids.empty() )
1566
    {
1567
        set<int>::iterator i = cluster_ids.begin();
1568

  
1569
        oss << "(CLUSTER_ID = " << *i;
1570

  
1571
        for (++i; i != cluster_ids.end(); i++)
1572
        {
1573
            oss << " | CLUSTER_ID = " << *i;
1574
        }
1575

  
1576
        oss << ") & !(PUBLIC_CLOUD = YES)";
1577
    }
1578
    else
1579
    {
1580
        oss << "!(PUBLIC_CLOUD = YES)";
1581
    }
1582

  
1583
    if (num_public != 0)
1584
    {
1585
        set<string>::iterator it = clouds.begin();
1586

  
1587
        oss << " | (PUBLIC_CLOUD = YES & (";
1588

  
1589
        oss << "HYPERVISOR = " << *it ;
1590

  
1591
        for (++it; it != clouds.end() ; ++it)
1592
        {
1593
            oss << " | HYPERVISOR = " << *it;
1594
        }
1595

  
1596
        oss << "))";
1597
    }
1598

  
1599
    obj_template->add("AUTOMATIC_REQUIREMENTS", oss.str());
1600

  
1601
    // Set automatic System DS requirements
1602

  
1603
    if ( !cluster_ids.empty() )
1604
    {
1605
        oss.str("");
1606

  
1607
        set<int>::iterator i = cluster_ids.begin();
1608

  
1609
        oss << "\"CLUSTERS/ID\" @> " << *i;
1610

  
1611
        for (++i; i != cluster_ids.end(); i++)
1612
        {
1613
            oss << " | \"CLUSTERS/ID\" @> " << *i;
1614
        }
1615

  
1616
        obj_template->add("AUTOMATIC_DS_REQUIREMENTS", oss.str());
1617
    }
1618

  
1619

  
1620 1558
    return 0;
1621 1559

  
1622 1560
error_disk:
......
1699 1637
/* ------------------------------------------------------------------------ */
1700 1638
/* ------------------------------------------------------------------------ */
1701 1639

  
1640
int VirtualMachine::automatic_requirements(string& error_str)
1641
{
1642
    ostringstream   oss;
1643
    set<int>        cluster_ids;
1644
    set<string>     clouds;
1645

  
1646
    int rc = get_cluster_requirements(cluster_ids, error_str);
1647

  
1648
    if (rc != 0)
1649
    {
1650
        return -1;
1651
    }
1652

  
1653
    if ( !cluster_ids.empty() )
1654
    {
1655
        set<int>::iterator i = cluster_ids.begin();
1656

  
1657
        oss << "(CLUSTER_ID = " << *i;
1658

  
1659
        for (++i; i != cluster_ids.end(); i++)
1660
        {
1661
            oss << " | CLUSTER_ID = " << *i;
1662
        }
1663

  
1664
        oss << ") & !(PUBLIC_CLOUD = YES)";
1665
    }
1666
    else
1667
    {
1668
        oss << "!(PUBLIC_CLOUD = YES)";
1669
    }
1670

  
1671
    int num_public = get_public_clouds(clouds);
1672

  
1673
    if (num_public != 0)
1674
    {
1675
        set<string>::iterator it = clouds.begin();
1676

  
1677
        oss << " | (PUBLIC_CLOUD = YES & (";
1678

  
1679
        oss << "HYPERVISOR = " << *it ;
1680

  
1681
        for (++it; it != clouds.end() ; ++it)
1682
        {
1683
            oss << " | HYPERVISOR = " << *it;
1684
        }
1685

  
1686
        oss << "))";
1687
    }
1688

  
1689
    obj_template->add("AUTOMATIC_REQUIREMENTS", oss.str());
1690

  
1691
    // Set automatic System DS requirements
1692

  
1693
    if ( !cluster_ids.empty() )
1694
    {
1695
        oss.str("");
1696

  
1697
        set<int>::iterator i = cluster_ids.begin();
1698

  
1699
        oss << "\"CLUSTERS/ID\" @> " << *i;
1700

  
1701
        for (++i; i != cluster_ids.end(); i++)
1702
        {
1703
            oss << " | \"CLUSTERS/ID\" @> " << *i;
1704
        }
1705

  
1706
        obj_template->add("AUTOMATIC_DS_REQUIREMENTS", oss.str());
1707
    }
1708

  
1709
    return 0;
1710
}
1711

  
1712
/* ------------------------------------------------------------------------ */
1713
/* ------------------------------------------------------------------------ */
1714

  
1702 1715
int VirtualMachine::insert_replace(SqlDB *db, bool replace, string& error_str)
1703 1716
{
1704 1717
    ostringstream   oss;

Also available in: Unified diff