The legislative body of any city may, by ordinance, provide the city and its inhabitants with water, light, power, and heat, by contract or by works of its own, located either within or beyond the boundaries of the city, make regulations for the management thereof, and fix and regulate the prices to private consumers and customers.