[Ovirt-devel] [PATCH] Rewriting the identify-node piece into two managed node units

Daniel P. Berrange berrange at redhat.com
Mon Jun 16 20:47:23 UTC 2008


On Mon, Jun 16, 2008 at 04:37:22PM -0400, Darryl L. Pierce wrote:
> diff --git a/ovirt-daemons/ovirt-identify.c b/ovirt-daemons/ovirt-identify.c
> new file mode 100644
> index 0000000..7a7ec05
> --- /dev/null
> +++ b/ovirt-daemons/ovirt-identify.c
> +int main(int argc,char** argv)
> +{
> +    int result = 1;
> +
> +    if(!config(argc,argv))
> +    {
> +        int success = 1;
> +
> +        if(!testing)
> +        {
> +            success = 0;
> +
> +            fprintf(stdout,"Connecting to libvirt.\n");
> +            virConnectPtr connection = virConnectOpenReadOnly(NULL);
> +
> +            if(debug) printf("connection=%ld\n",(long int)connection);
> +
> +            if(connection)
> +            {
> +                virNodeInfo info;
> +
> +                if(debug) printf("Retrieving node information.\n");
> +                if(!virNodeGetInfo(connection,&info))
> +                {
> +                    success = 1;
> +
> +                    gethostname(uuid,128);
> +                    sprintf(arch,    "%s",  info.model);
> +                    sprintf(memsize, "%ld", info.memory);
> +                    sprintf(numcpus, "%d",  info.cpus);
> +                    sprintf(cpuspeed,"%d",  info.mhz);
> +
> +                    if(debug)
> +                    {
> +                        printf("Node Info:\n");
> +                        printf("     UUID: %s\n", uuid);
> +                        printf("     Arch: %s\n", arch);
> +                        printf("   Memory: %s\n", memsize);
> +                        printf("   # CPUs: %s\n", numcpus);
> +                        printf("CPU Speed: %s\n", cpuspeed);
> +                    }
> +                }
> +                else
> +                {
> +                    if(debug) printf("Failed to get node info.\n");
> +                }
> +            }
> +            else
> +            {
> +                if(debug) printf("Could not connect to libvirt.\n");
> +            }
> +        }
> +        else
> +        {
> +            strcpy(uuid,"UUID-FOR-TESTING-PURPOSES");
> +            strcpy(arch,"x86_64");
> +            strcpy(memsize,"2048");
> +            strcpy(numcpus,"2");
> +            strcpy(cpuspeed,"2048");
> +        }

FYI, there is no need to have different code paths for testing. libvirt
has a special driver for exactly this use case. It has a set of hardcoded
defaults, if you use  test:///default as the URI

  $ virsh --connect test:///default nodeinfo
  CPU model:           i686
  CPU(s):              16
  CPU frequency:       1400 MHz
  CPU socket(s):       2
  Core(s) per socket:  2
  Thread(s) per core:  2
  NUMA cell(s):        2
  Memory size:         3145728 kB


Or you can customize the data output by the test driver using an XML file
to define params. eg to define a host with 2 active VMs, and 2 virtual
networks you can create a file

  <node>
  <!-- This file gives an example config for the mock 'test' backend
       driver to libvirt. This is intended to allow relible unit testing
       of applications using libvirt. To use this with virsh, run something
       like:

        virsh -connect test:////path/to/this/dir/testnode.xml nodeinfo
      -->
    <domain file="testdomfv0.xml"/>
    <domain file="testdomfc4.xml"/>
    <network file="testnetpriv.xml"/>
    <network file="testnetdef.xml"/>

    <cpu>
      <mhz>6000</mhz>
      <model>i986</model>
      <active>50</active>
      <nodes>4</nodes>
      <sockets>4</sockets>
      <cores>4</cores>
      <threads>2</threads>
    </cpu>
    <memory>8192000</memory>
  </node>

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the ovirt-devel mailing list