Angular multipart/formdata

You would like to upload or post something not as an application/json but as a multipart/formdata.

It’s pretty simple, simpler than you would’ve thought 🙂

1. create the FormData instance

then you can use .set or .append methods to add values to the post body of the FormData.

and finally we upload it or send it away, rather.

if we have a file upload and would like to be notified about upload progress

when we subscribe to this, we have several events happening.

Angular, EventSource, Go and wasted lifetime

If you have ever used EventSource and Angular and have read all the other blog posts and github issues and Stackoverflow posts and nothing worked, then you’ve probably come here and will happily leave knowing you solved your problem.

First of all I use cobra, I know, get to the point. As part of cobra I add the serve command, so I can go run main.go serve

This is the serve.go file

I set up the route, cors and run it

The server/handler/handler.go file

Here is the important part. I wasted the last 6 hours and previous to that 2 days on this issue.
If you’re serving this via nginx, you have to set this header X-Accel-Buffering = no.
If you don’t send this header responses will get buffered by nginx until the timeout it met then flushed to the client.
The above code has a ticker that ticks every second and sends a new “Server Sent Event”.

Why it didn’t work for me was, as you see above Event: "message". I had that set to “darko”.

The Angular service

eventSource.onmessage expects a message with the Event: "message" content. Since I had it set to “darko”,
the onmessage event never fired. If you for whatever reason need to send an event that is not a message type,
the eventSource.addEventListener is how you listen for that event.
As you might have seen in other blog posts or github issues, zonejs and EventSource aren’t the best of friends.
So you have to wrap it all in zone.run() so you can have real time updates, and not just when you unsubscribe from the Observable.

Finally, the component

and the component html

Finally, the nginx configuration for the development server. To serve it all.
Here I’m using es.dev.luketic on the local network.

libvirt manual migration

Following scenario:

You have 2 servers. No shared storage.
You would like to move VMs from Server A to Server B.

If you want a clean filesystem there will be downtime.
Downtime will take as long as it needs to copy the image from one server to the other.

Step 1:

Shutdown the instance running on the source server.
e.g.

Step 2:

Copy the image, usually located in /var/lib/libvirt/images/ , from source to destination.
e.g.

Step 3:

Dumo the configuration xml of your vm and copy it to the destination server
e.g.

This will copy domain.name.xml to the home directory of the destination server, in this case /root/ (implied by the : after the server name)

Step 4:

Import the copied xml domain configuration on the destination server.
The MAC address probably changed, depending on your data center’s setup you’d need to edit the xml file accordingly.
The domain import command is

Step 5:
Finish it up.
Change network configuration from inside the guest.
You will need to login via spice console.
It’s best to use the great tool “Virtual Machine Manager” for this job.
Remember to keep your VM’s root password ready.