{"action":"created","issue":{"url":"https://api.github.com/repos/msantos/verx/issues/9","labels_url":"https://api.github.com/repos/msantos/verx/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/msantos/verx/issues/9/comments","events_url":"https://api.github.com/repos/msantos/verx/issues/9/events","html_url":"https://github.com/msantos/verx/issues/9","id":111874657,"number":9,"title":"Getting ip address of guest vm","user":{"login":"kansi","id":4709940,"avatar_url":"https://avatars.githubusercontent.com/u/4709940?v=3","gravatar_id":"","url":"https://api.github.com/users/kansi","html_url":"https://github.com/kansi","followers_url":"https://api.github.com/users/kansi/followers","following_url":"https://api.github.com/users/kansi/following{/other_user}","gists_url":"https://api.github.com/users/kansi/gists{/gist_id}","starred_url":"https://api.github.com/users/kansi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kansi/subscriptions","organizations_url":"https://api.github.com/users/kansi/orgs","repos_url":"https://api.github.com/users/kansi/repos","events_url":"https://api.github.com/users/kansi/events{/privacy}","received_events_url":"https://api.github.com/users/kansi/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-10-16T17:23:25Z","updated_at":"2015-10-17T13:18:03Z","closed_at":null,"body":"Is there a way to get ip address of booted vm ?"},"comment":{"url":"https://api.github.com/repos/msantos/verx/issues/comments/148915696","html_url":"https://github.com/msantos/verx/issues/9#issuecomment-148915696","issue_url":"https://api.github.com/repos/msantos/verx/issues/9","id":148915696,"user":{"login":"msantos","id":158059,"avatar_url":"https://avatars.githubusercontent.com/u/158059?v=3","gravatar_id":"","url":"https://api.github.com/users/msantos","html_url":"https://github.com/msantos","followers_url":"https://api.github.com/users/msantos/followers","following_url":"https://api.github.com/users/msantos/following{/other_user}","gists_url":"https://api.github.com/users/msantos/gists{/gist_id}","starred_url":"https://api.github.com/users/msantos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msantos/subscriptions","organizations_url":"https://api.github.com/users/msantos/orgs","repos_url":"https://api.github.com/users/msantos/repos","events_url":"https://api.github.com/users/msantos/events{/privacy}","received_events_url":"https://api.github.com/users/msantos/received_events","type":"User","site_admin":false},"created_at":"2015-10-17T13:18:03Z","updated_at":"2015-10-17T13:18:03Z","body":"> I updated libvirt to the latest release.\r\n\r\nWere you able to try `verx:domain_interface_addresses/2`? I got the parameters wrong. It should be:\r\n~~~ erlang\r\n% ?VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE = 0\r\nverx:domain_interface_addresses(Ref, [Network, ?VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE, 0])\r\n~~~\r\n\r\n> I see there's a function called network_get_dhcp_leases/2 but I am not sure how to use it. It would be great if you suggest how to use it.\r\n\r\nIt requires a little reverse engineering.\r\n* check the source for virsh\r\n\r\n  `net-dhcp-leases` seems to call virNetworkGetDHCPLeases()\r\n\r\n  https://github.com/libvirt/libvirt/blob/0bc5fcffb13e3ea9ab35aeb760d31660f4aea2c8/tools/virsh-network.c#L1381\r\n\r\n* check the libvirt docs for virNetworkGetDHCPLeases()\r\n\r\n https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetDHCPLeases\r\n\r\n``` c\r\nint\tvirNetworkGetDHCPLeases (\r\n                                         virNetworkPtr network,\r\n\t\t\t\t\t const char * mac,\r\n\t\t\t\t\t virNetworkDHCPLeasePtr ** leases,\r\n\t\t\t\t\t unsigned int flags)\r\n```\r\n\r\n* check the XDR signature for the RPC call\r\n\r\n https://github.com/libvirt/libvirt/blob/0bc5fcffb13e3ea9ab35aeb760d31660f4aea2c8/src/remote/remote_protocol.x#L3152\r\n\r\n  The function signature is:\r\n``` c\r\nstruct remote_network_get_dhcp_leases_args {\r\n    remote_nonnull_network net;\r\n    remote_string mac;\r\n    int need_results;\r\n    unsigned int flags;\r\n};\r\n```\r\n  The return value is:\r\n``` c\r\nstruct remote_network_get_dhcp_leases_ret {                                     \r\n    remote_network_dhcp_lease leases<REMOTE_NETWORK_DHCP_LEASES_MAX>;           \r\n    unsigned int ret;                                                           \r\n};\r\n```\r\n   Where a `remote_network_get_dhcp_lease` is defined as:\r\n``` c\r\nstruct remote_network_dhcp_lease {                                              \r\n    remote_nonnull_string iface;                                                \r\n    hyper expirytime;                                                           \r\n    int type;                                                                   \r\n    remote_string mac;                                                          \r\n    remote_string iaid;                                                         \r\n    remote_nonnull_string ipaddr;                                               \r\n    unsigned int prefix;                                                        \r\n    remote_string hostname;                                                     \r\n    remote_string clientid;                                                     \r\n};               \r\n```\r\n* the generated interface in verx takes 2 arguments: the verx client transport PID and a list of parameters which is a representation of the `remote_network_get_dhcp_leases_args` struct.\r\n\r\n  The parameters are: a network reference, the MAC address, an integer indicating the number of results to return and a flag (which should be set to 0)\r\n\r\n  The return value should be a tuple:\r\n~~~ erlang\r\n{ok, [Leases, non_neg_integer()]} | {error, posix() | libvirt()}\r\n~~~\r\n\r\n  Where `Leases` is a list: \r\n~~~ erlang\r\n[Iface :: binary(), Expiry :: integer(), Type :: integer(), MAC :: binary(), Iaid :: binary(), IPaddr :: binary(), Prefix :: non_neg_integer(), Hostname :: binary(), ClientId :: binary()]\r\n~~~\r\nAnd calling it should be something like:\r\n~~~ erlang\r\n{ok, Network} = verx:network_lookup_by_name(Ref, [Name]),\r\n {ok, [[], Num]} = verx:network_get_dhcp_leases(Ref, [Network, <<\"aa:bb:cc:00:11:22\">>, 0, 0)\r\n {ok, [Leases, Num]} = verx:network_get_dhcp_leases(Ref, [Network, <<\"aa:bb:cc:00:11:22\">>, Num, 0).\r\n~~~\r\nI am guessing here, I haven't actually tried running this. If you run into problems, let me know and I'll set up a few tests!\r\n\r\n\r\n\r\n"}}