Revision f789d500 src/vm/VirtualMachine.cc

View differences:

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