Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Az definitions #3923

Open
wants to merge 2 commits into
base: az-rpc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions include/multipass/availability_zone.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*
*/

#ifndef MULTIPASS_AVAILABILITY_ZONE_H
#define MULTIPASS_AVAILABILITY_ZONE_H

#include "disabled_copy_move.h"
#include "virtual_machine.h"

#include <memory>

namespace multipass
{
class AvailabilityZone : DisabledCopyMove
{
public:
using UPtr = std::unique_ptr<AvailabilityZone>;
using ShPtr = std::shared_ptr<AvailabilityZone>;

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
44 changes: 44 additions & 0 deletions include/multipass/availability_zone_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/

#ifndef MULTIPASS_AVAILABILITY_ZONE_MANAGER_H
#define MULTIPASS_AVAILABILITY_ZONE_MANAGER_H

#include "availability_zone.h"

namespace multipass
{
class AvailabilityZoneManager : DisabledCopyMove
{
public:
using UPtr = std::unique_ptr<AvailabilityZoneManager>;
using ShPtr = std::shared_ptr<AvailabilityZoneManager>;

virtual ~AvailabilityZoneManager() = default;

virtual AvailabilityZone& get_zone(const std::string& name) = 0;
virtual std::vector<std::reference_wrapper<const AvailabilityZone>> 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
82 changes: 82 additions & 0 deletions include/multipass/exceptions/availability_zone_exceptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/

#ifndef MULTIPASS_AVAILABILITY_ZONE_EXCEPTIONS_H
#define MULTIPASS_AVAILABILITY_ZONE_EXCEPTIONS_H

#include <stdexcept>
#include <string>

#include <multipass/format.h>

namespace multipass
{
struct AvailabilityZoneError : std::runtime_error
{
template <typename... Args>
explicit AvailabilityZoneError(fmt::format_string<Args...> fmt, Args&&... args)
: runtime_error(fmt::format(fmt, std::forward<Args>(args)...))
{
}
};

struct AvailabilityZoneSerializationError final : AvailabilityZoneError
{
using AvailabilityZoneError::AvailabilityZoneError;
};

struct AvailabilityZoneDeserializationError final : AvailabilityZoneError
{
using AvailabilityZoneError::AvailabilityZoneError;
};

struct AvailabilityZoneManagerError : std::runtime_error
{
template <typename... Args>
explicit AvailabilityZoneManagerError(fmt::format_string<Args...> fmt, Args&&... args)
: runtime_error(fmt::format(fmt, std::forward<Args>(args)...))
{
}
};

struct AvailabilityZoneManagerSerializationError final : AvailabilityZoneManagerError
{
using AvailabilityZoneManagerError::AvailabilityZoneManagerError;
};

struct AvailabilityZoneManagerDeserializationError final : AvailabilityZoneManagerError
{
using AvailabilityZoneManagerError::AvailabilityZoneManagerError;
};

struct AvailabilityZoneNotFound final : AvailabilityZoneManagerError
{
explicit AvailabilityZoneNotFound(const std::string& name)
: AvailabilityZoneManagerError{"no AZ with name {:?} found", name}
{
}
};

struct NoAvailabilityZoneAvailable final : AvailabilityZoneManagerError
{
NoAvailabilityZoneAvailable() : AvailabilityZoneManagerError{"no AZ is available"}
{
}
};
} // namespace multipass

#endif // MULTIPASS_AVAILABILITY_ZONE_EXCEPTIONS_H
Loading