Revision 74aa41ba src/vm/VirtualMachine.cc

View differences:

src/vm/VirtualMachine.cc
594 594
    int                        num_nics, rc;
595 595
    vector<Attribute  * >      nics;
596 596
    VirtualNetworkPool       * vnpool;
597
    VirtualNetwork           * vn;
598 597
    VectorAttribute          * nic;
599
    map<string,string>         new_nic;
600

  
601
    string                     ip;
602
    string                     mac;
603
    string                     bridge;
604
    string                     network;
605
    string                     model;
606

  
607
    ostringstream              vnid;
608 598

  
609 599
    // Set the networking attributes.
610 600

  
......
613 603

  
614 604
    num_nics   = vm_template.get("NIC",nics);
615 605

  
616
    for(int i=0; i<num_nics; i++,vnid.str(""))
606
    for(int i=0; i<num_nics; i++)
617 607
    {
618
   	 	nic = dynamic_cast<VectorAttribute * >(nics[i]);
608
        nic = dynamic_cast<VectorAttribute * >(nics[i]);
619 609

  
620 610
        if ( nic == 0 )
621 611
        {
622 612
            continue;
623 613
        }
624 614

  
625
        network = nic->vector_value("NETWORK");
626

  
627
        if ( network.empty() )
628
        {
629
            continue;
630
        }
631

  
632
        vn = vnpool->get(network,true);
633

  
634
        if ( vn == 0 )
635
        {
636
            return -1;
637
        }
638

  
639
        if ( vn->get_uid() != uid && vn->get_uid() != 0 && uid != 0)
640
        {
641
            ostringstream ose;
642
            ose << "Owner " << uid << " of the VM doesn't have ownership of Virtual Network "
643
                << vn->get_uid();
644
            NebulaLog::log("VMM", Log::ERROR, ose);
645
            return -1;
646
        }
647

  
648

  
649
        ip = nic->vector_value("IP");
650

  
651
        if (ip.empty())
652
        {
653
        	rc = vn->get_lease(oid, ip, mac, bridge);
654
        }
655
        else
656
        {
657
        	rc = vn->set_lease(oid, ip, mac, bridge);
658
        }
659

  
660
        vn->unlock();
615
        rc = vnpool->nic_attribute(nic, oid);
661 616

  
662
        if ( rc != 0 )
617
        if (rc == -1)
663 618
        {
664 619
            return -1;
665 620
        }
666

  
667
        vnid << vn->get_oid();
668

  
669
        new_nic.insert(make_pair("NETWORK",network));
670
        new_nic.insert(make_pair("MAC"    ,mac));
671
        new_nic.insert(make_pair("BRIDGE" ,bridge));
672
        new_nic.insert(make_pair("VNID"   ,vnid.str()));
673
        new_nic.insert(make_pair("IP"     ,ip));
674

  
675
        model = nic->vector_value("MODEL");
676

  
677
        if ( !model.empty() )
678
        {
679
            new_nic.insert(make_pair("MODEL",model));
680
        }
681

  
682
        nic->replace(new_nic);
683

  
684
        new_nic.erase(new_nic.begin(),new_nic.end());
685 621
    }
686 622

  
687 623
    return 0;

Also available in: Unified diff