From abdcb95930bae3405058cb546245abfb42ae7bfb Mon Sep 17 00:00:00 2001 From: Andrei Toterman Date: Thu, 23 Jan 2025 16:57:32 +0100 Subject: [PATCH 1/2] [az] add abstract classes for az and az manager --- include/multipass/availability_zone.h | 45 +++++++++++++++++ include/multipass/availability_zone_manager.h | 49 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 include/multipass/availability_zone.h create mode 100644 include/multipass/availability_zone_manager.h diff --git a/include/multipass/availability_zone.h b/include/multipass/availability_zone.h new file mode 100644 index 0000000000..bf146a1256 --- /dev/null +++ b/include/multipass/availability_zone.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) Canonical, Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef MULTIPASS_AVAILABILITY_ZONE_H +#define MULTIPASS_AVAILABILITY_ZONE_H + +#include "disabled_copy_move.h" +#include "virtual_machine.h" + +#include + +namespace multipass +{ +class AvailabilityZone : private DisabledCopyMove +{ +public: + using UPtr = std::unique_ptr; + using ShPtr = std::shared_ptr; + + virtual ~AvailabilityZone() = default; + + [[nodiscard]] virtual const std::string& get_name() const = 0; + [[nodiscard]] virtual const std::string& get_subnet() const = 0; + [[nodiscard]] virtual bool is_available() const = 0; + virtual void set_available(bool new_available) = 0; + virtual void add_vm(VirtualMachine& vm) = 0; + virtual void remove_vm(VirtualMachine& vm) = 0; +}; +} // namespace multipass + +#endif // MULTIPASS_AVAILABILITY_ZONE_H diff --git a/include/multipass/availability_zone_manager.h b/include/multipass/availability_zone_manager.h new file mode 100644 index 0000000000..ca0f6b8e5d --- /dev/null +++ b/include/multipass/availability_zone_manager.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) Canonical, Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef MULTIPASS_AVAILABILITY_ZONE_MANAGER_H +#define MULTIPASS_AVAILABILITY_ZONE_MANAGER_H + +#include "availability_zone.h" + +#include +#include +#include +#include + +namespace multipass +{ +class AvailabilityZoneManager : private DisabledCopyMove +{ +public: + using UPtr = std::unique_ptr; + using ShPtr = std::shared_ptr; + + virtual ~AvailabilityZoneManager() = default; + + virtual AvailabilityZone& get_zone(const std::string& name) = 0; + virtual std::vector> get_zones() = 0; + // this returns a computed zone name, using an algorithm e.g. round-robin + // not to be confused with [get_default_zone_name] + virtual std::string get_automatic_zone_name() = 0; + // this always returns the same zone name, to be given to VMs that were not assigned to a zone in the past + // not to be confused with [get_automatic_zone] + virtual std::string get_default_zone_name() const = 0; +}; +} // namespace multipass + +#endif // MULTIPASS_AVAILABILITY_ZONE_MANAGER_H From 0e5434c1171fd5d2f8860eec0302596036ca15e3 Mon Sep 17 00:00:00 2001 From: Andrei Toterman Date: Thu, 6 Feb 2025 21:35:11 +0100 Subject: [PATCH 2/2] [az] add az exceptions --- .../exceptions/availability_zone_exceptions.h | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 include/multipass/exceptions/availability_zone_exceptions.h diff --git a/include/multipass/exceptions/availability_zone_exceptions.h b/include/multipass/exceptions/availability_zone_exceptions.h new file mode 100644 index 0000000000..c142fec788 --- /dev/null +++ b/include/multipass/exceptions/availability_zone_exceptions.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) Canonical, Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef MULTIPASS_AVAILABILITY_ZONE_EXCEPTIONS_H +#define MULTIPASS_AVAILABILITY_ZONE_EXCEPTIONS_H + +#include "formatted_exception_base.h" + +namespace multipass +{ +struct AvailabilityZoneNotFound final : FormattedExceptionBase<> +{ + explicit AvailabilityZoneNotFound(const std::string& name) + : FormattedExceptionBase{"no AZ with name {:?} found", name} + { + } +}; + +struct NoAvailabilityZoneAvailable final : std::runtime_error +{ + NoAvailabilityZoneAvailable() : std::runtime_error{"no AZ is available"} + { + } +}; +} // namespace multipass + +#endif // MULTIPASS_AVAILABILITY_ZONE_EXCEPTIONS_H