metadata: Refactor metadata service into ec2 metadata

Added more testing.