Skip to content
This repository has been archived by the owner on Jun 3, 2023. It is now read-only.

Getting the ip of an instance #13

Open
ajagnanan opened this issue Nov 1, 2017 · 17 comments
Open

Getting the ip of an instance #13

ajagnanan opened this issue Nov 1, 2017 · 17 comments

Comments

@ajagnanan
Copy link

Is it possible to get the ip of a new vm?

@mborodin
Copy link
Contributor

Currently it is not possible. I'm analysing possible ways to achieve it, but cannot promise it will be implemented anytime soon.

@ajagnanan
Copy link
Author

fwiw, I did find that if you run xe vm-list params=name-label,networks on the xenserver console it returns the ips if xentools is installed. I'm not sure how or if it can work through the api though.

@mborodin
Copy link
Contributor

thanks for a tip! I will have a look at it

This was referenced Jan 15, 2018
@mborodin
Copy link
Contributor

Hi @ajagnanan, @briantopping
I've implemented VM Guest metrics data source, which allows among other obtain information on IPs of a running guest. I would be very grateful if you could test it (#24).

@briantopping
Copy link
Contributor

Will do! I'm suddenly delayed a bit, dislocated and fractured my shoulder about eight hours ago. Yuck.

@ringods
Copy link
Contributor

ringods commented Jan 16, 2018

@briantopping take care!

FYI: I will review/merge the pull requests probably on Thursday evening CET.

@mborodin
Copy link
Contributor

@briantopping thanks and take care!

@ringods perfect, I've just found small issue with this PR which occurs when you try to read metrics of newly created VM and now I will have time to fix it :)

@ajagnanan
Copy link
Author

ajagnanan commented Jan 16, 2018

Sure I can, I'm not too familiar with go, can you give me quick steps to compile/run against your branch?

@mborodin
Copy link
Contributor

Hi @ajagnanan,
I've prepared a branch for testing, which uses my code. Here is how you can build it:

  1. Grab my version of provider:
$ go get github.com/mborodin/terraform-provider-xenserver
  1. cd to obtained package in go src: /github.com/mborodin/terraform-provider-xenserver Usually GO-SRC would be folder go/src in your user home directory, but it depends on your GOPATH
  2. Change branch:
$ git checkout feature/test_guest_ip
  1. Download dep tool from https://github.com/golang/dep/releases and put it somewhere in your $PATH
  2. Install depencencies - residing in /github.com/mborodin/terraform-provider-xenserver execute following command:
$ dep ensure
  1. Build it:
$ make fmt build
  1. Use it :) Binary should be available in GO-BIN (bin in the same folder as src)

@mborodin
Copy link
Contributor

Small update: I have pushed few changes (most critical - new datasource) and example how to provision VM with ansible.
@ajagnanan if you have started testing I recommend you to pull changes from feature/test_guest_ip, because previous code state could not be used to do some interesting thing like provisioning due to HCL limitations

@ajagnanan
Copy link
Author

I just tried it and it works! I got the IP (v4 and v6) written out to output.json. I have 2 questions:

Thanks for putting this in btw

@mborodin
Copy link
Contributor

Have you tried the latest version? If no - can you please also test with newest release and xenserver_vm_network data source?
Regarding your questions:

  • well, techically it is possible, but there are few issues. First of all, network information comes from guest utilities, which means some delay must be introduced inside VM creation. Second problem (or better to say - lack of knowledge of terraform internals from my side) is that metrics information is being constantly updated which potentialy can lead to constant vm updates, since stored metrics state will be different from metrics state on the server. This is not a problem for a data source, but can cause issues for resources.
  • yes, it is possible to do such a thing for xenserver_vm_guest_metrics (since it is basically useless outside of output and json template rendering use cases). Such a feature for xenserver_vm_networks would render it useless due to HCL limitations.

@briantopping
Copy link
Contributor

Hi @mborodin, I'm finally able to sit at a desk comfortably for reasonable time and found your feature/guest_ip branch. This is really cool work, you rock!

I've tried to use it in my use case, which I just uploaded at https://github.com/briantopping/terraform_salted_aws/tree/xen-work. This is a project by @quixoten that can generate a Salt cluster in AWS, but was conveniently written to allow other providers.

Possibly because of my misuse of any number of components here, I am getting an error: Error: data.xenserver_vm_networks.saltmaster_interfaces: Provider doesn't support data source: xenserver_vm_networks.

To me, this sounds like I did not compile and install your changes correctly, but the install seems to work properly:

bt-imac:terraform-provider-xenserver brian$ pwd
/Users/brian/go/src/github.com/briantopping/terraform-provider-xenserver
bt-imac:terraform-provider-xenserver brian$ go clean -x
cd /Users/brian/go/src/github.com/briantopping/terraform-provider-xenserver
rm -f terraform-provider-xenserver terraform-provider-xenserver.exe terraform-provider-xenserver.test terraform-provider-xenserver.test.exe main main.exe
bt-imac:terraform-provider-xenserver brian$ go install -x
WORK=/var/folders/02/fxpfcvtn363g2dhz01sblgqh0000gp/T/go-build358332052
mkdir -p $WORK/github.com/briantopping/terraform-provider-xenserver/_obj/
mkdir -p $WORK/github.com/briantopping/terraform-provider-xenserver/_obj/exe/
cd /Users/brian/go/src/github.com/briantopping/terraform-provider-xenserver
/usr/local/go/pkg/tool/darwin_amd64/compile -o $WORK/github.com/briantopping/terraform-provider-xenserver.a -trimpath $WORK -goversion go1.9.2 -p main -complete -buildid 4732a7bdb4b885f8874b027553d2b699056ed208 -D _/Users/brian/go/src/github.com/briantopping/terraform-provider-xenserver -I $WORK -I /Users/brian/go/pkg/darwin_amd64 -pack ./main.go
cd .
/usr/local/go/pkg/tool/darwin_amd64/link -o $WORK/github.com/briantopping/terraform-provider-xenserver/_obj/exe/a.out -L $WORK -L /Users/brian/go/pkg/darwin_amd64 -extld=clang -buildmode=exe -buildid=4732a7bdb4b885f8874b027553d2b699056ed208 $WORK/github.com/briantopping/terraform-provider-xenserver.a
mkdir -p /Users/brian/go/bin/
mv $WORK/github.com/briantopping/terraform-provider-xenserver/_obj/exe/a.out /Users/brian/go/bin/terraform-provider-xenserver

Can you see anything out of place? Please don't worry about making it work, I'm only desiring to make the output.tf properly generate the IP address. But if you like it, of course I will enjoy sharing it! 😄

@briantopping
Copy link
Contributor

briantopping commented Jan 23, 2018

@mborodin: I'm also curious if you could share how you are using GoLand and whether you've been able to create a debug configuration with breakpoints in your IDE? The only thing I have managed so far is to run as in dlv debug --headless --listen=:2345 --api-version=2 github.com/hashicorp/terraform -- apply with the plugin in ~/terraform.d/plugins and once it finishes a long compilation, click connect. But it doesn't stop at any breakpoints.

@mborodin
Copy link
Contributor

Hi @briantopping,
are you sure you are using the most recent version of my patch? Other thing what I've mentioned was that you have referenced feature/gust_ip branch which is merge branch for pull request and should correctly work only in context of pull request. To test it you should use feature/test_guest_ip branch because it references my version of xenserver provider in main.go

As for Gogland - I'm using IntelliJ with plugin and suspect it to be a bit different to Gogland in terms of ease of use (Gogland should be better tuned for Go). But anyways it is quite comfortable with exception to debugging - I could not get it working either. I'm still investigating that matter, but since go for me at the moment is just a fun thing to learn I can not invest much of time in it.

@briantopping
Copy link
Contributor

Hi @mborodin, thanks for the response! I'm just getting back into the swing of things and I think you might be interested in https://blog.sgmansfield.com/2016/06/working-with-forks-in-go/. I can't say I have enough experience with this technique yet, but it should remove the need to rename any package imports for the code you are working on.

About the Go plugin use in IntelliJ: I guess you would lose the CMake integration, which provides the seamless import for larger projects. This project isn't using CMake, something I'll probably attack at some point since I have some experience with it. The problem with the various xMake and Autotools formats is they are very difficult for an IDE to parse and developers end up with multiple project metadata formats that have to be kept in sync if they are going to get any benefits from IDEs at all. CMake seems to be the emerging standard to avoid that.

Should be a fun weekend, I'll check in as I get some progress, thanks for the tip on the import! :)

@briantopping
Copy link
Contributor

(Preface: I am running on XenServer 7.3)

Update from here: I created https://github.com/briantopping/terraform-provider-xenserver/tree/mborodin/guest_ip as a fork of @mborodin's work. I couldn't quite make out whether I've improved it or not, there were a lot of methods that would just return when there was an error. I don't know if my changes are correct, this is me learning Go in the process! A review would be very kindly appreciated!! :D

The bigger things that I didn't understand is I see in the wireshark traces that ISO 8601 dates are being returned by XenServer, but it does not seem that https://github.com/ ringods/go-xen-api-client parses them. As I outlined in the commit, they all parse as 0001-01-01 00:00:00 +0000 UTC, which means the delay code never fired.

So I commented out that logic for now in my fork so it always delays, but no networks are ever parsed, even though the networks are visible in XenCenter.

I'm the wireshark trace for this TCP session here.

@ringods, Do you have enough experience yet with the go-xen-api-client for any of the parsing stuff to make sense?

Thanks guys, more as I get it!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants