]>
git.proxmox.com Git - proxmox-apt.git/blob - src/repositories/standard.rs
3 use anyhow
::{bail, Error}
;
4 use serde
::{Deserialize, Serialize}
;
6 use crate::repositories
::repository
::{
7 APTRepository
, APTRepositoryFileType
, APTRepositoryPackageType
,
10 use proxmox_schema
::api
;
15 description
: "Handle referencing a standard repository.",
20 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
21 #[serde(rename_all = "kebab-case")]
22 /// Reference to a standard repository and configuration status.
23 pub struct APTStandardRepository
{
24 /// Handle referencing a standard repository.
25 pub handle
: APTRepositoryHandle
,
27 /// Configuration status of the associated repository.
28 #[serde(skip_serializing_if = "Option::is_none")]
29 pub status
: Option
<bool
>,
31 /// Display name of the repository.
34 /// Description of the repository.
35 pub description
: String
,
39 #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq, Eq)]
40 #[serde(rename_all = "kebab-case")]
41 /// Handles for Proxmox repositories.
42 pub enum APTRepositoryHandle
{
43 /// The enterprise repository for production use.
45 /// The repository that can be used without subscription.
47 /// The test repository.
49 /// Ceph Quincy repository.
51 /// Ceph Quincy test repository.
53 /// Ceph Pacific repository.
55 /// Ceph Pacific test repository.
57 /// Ceph Octoput repository.
59 /// Ceph Octoput test repository.
63 impl From
<APTRepositoryHandle
> for APTStandardRepository
{
64 fn from(handle
: APTRepositoryHandle
) -> Self {
65 APTStandardRepository
{
69 description
: handle
.description(),
74 impl TryFrom
<&str> for APTRepositoryHandle
{
77 fn try_from(string
: &str) -> Result
<Self, Error
> {
79 "enterprise" => Ok(APTRepositoryHandle
::Enterprise
),
80 "no-subscription" => Ok(APTRepositoryHandle
::NoSubscription
),
81 "test" => Ok(APTRepositoryHandle
::Test
),
82 "ceph-quincy" => Ok(APTRepositoryHandle
::CephQuincy
),
83 "ceph-quincy-test" => Ok(APTRepositoryHandle
::CephQuincyTest
),
84 "ceph-pacific" => Ok(APTRepositoryHandle
::CephPacific
),
85 "ceph-pacific-test" => Ok(APTRepositoryHandle
::CephPacificTest
),
86 "ceph-octopus" => Ok(APTRepositoryHandle
::CephOctopus
),
87 "ceph-octopus-test" => Ok(APTRepositoryHandle
::CephOctopusTest
),
88 _
=> bail
!("unknown repository handle '{}'", string
),
93 impl Display
for APTRepositoryHandle
{
94 fn fmt(&self, f
: &mut std
::fmt
::Formatter
<'_
>) -> std
::fmt
::Result
{
96 APTRepositoryHandle
::Enterprise
=> write
!(f
, "enterprise"),
97 APTRepositoryHandle
::NoSubscription
=> write
!(f
, "no-subscription"),
98 APTRepositoryHandle
::Test
=> write
!(f
, "test"),
99 APTRepositoryHandle
::CephQuincy
=> write
!(f
, "ceph-quincy"),
100 APTRepositoryHandle
::CephQuincyTest
=> write
!(f
, "ceph-quincy-test"),
101 APTRepositoryHandle
::CephPacific
=> write
!(f
, "ceph-pacific"),
102 APTRepositoryHandle
::CephPacificTest
=> write
!(f
, "ceph-pacific-test"),
103 APTRepositoryHandle
::CephOctopus
=> write
!(f
, "ceph-octopus"),
104 APTRepositoryHandle
::CephOctopusTest
=> write
!(f
, "ceph-octopus-test"),
109 impl APTRepositoryHandle
{
110 /// Get the description for the repository.
111 pub fn description(self) -> String
{
113 APTRepositoryHandle
::Enterprise
=> {
114 "This is the default, stable, and recommended repository, available for all \
115 Proxmox subscription users."
117 APTRepositoryHandle
::NoSubscription
=> {
118 "This is the recommended repository for testing and non-production use. \
119 Its packages are not as heavily tested and validated as the production ready \
120 enterprise repository. You don't need a subscription key to access this repository."
122 APTRepositoryHandle
::Test
=> {
123 "This repository contains the latest packages and is primarily used for test labs \
124 and by developers to test new features."
126 APTRepositoryHandle
::CephQuincy
=> {
127 "This repository holds the main Proxmox Ceph Quincy packages."
129 APTRepositoryHandle
::CephQuincyTest
=> {
130 "This repository contains the Ceph Quincy packages before they are moved to the \
133 APTRepositoryHandle
::CephPacific
=> {
134 "This repository holds the main Proxmox Ceph Pacific packages."
136 APTRepositoryHandle
::CephPacificTest
=> {
137 "This repository contains the Ceph Pacific packages before they are moved to the \
140 APTRepositoryHandle
::CephOctopus
=> {
141 "This repository holds the main Proxmox Ceph Octopus packages."
143 APTRepositoryHandle
::CephOctopusTest
=> {
144 "This repository contains the Ceph Octopus packages before they are moved to the \
151 /// Get the display name of the repository.
152 pub fn name(self) -> String
{
154 APTRepositoryHandle
::Enterprise
=> "Enterprise",
155 APTRepositoryHandle
::NoSubscription
=> "No-Subscription",
156 APTRepositoryHandle
::Test
=> "Test",
157 APTRepositoryHandle
::CephQuincy
=> "Ceph Quincy",
158 APTRepositoryHandle
::CephQuincyTest
=> "Ceph Quincy Test",
159 APTRepositoryHandle
::CephPacific
=> "Ceph Pacific",
160 APTRepositoryHandle
::CephPacificTest
=> "Ceph Pacific Test",
161 APTRepositoryHandle
::CephOctopus
=> "Ceph Octopus",
162 APTRepositoryHandle
::CephOctopusTest
=> "Ceph Octopus Test",
167 /// Get the standard file path for the repository referenced by the handle.
168 pub fn path(self, product
: &str) -> String
{
170 APTRepositoryHandle
::Enterprise
=> {
171 format
!("/etc/apt/sources.list.d/{}-enterprise.list", product
)
173 APTRepositoryHandle
::NoSubscription
=> "/etc/apt/sources.list".to_string(),
174 APTRepositoryHandle
::Test
=> "/etc/apt/sources.list".to_string(),
175 APTRepositoryHandle
::CephQuincy
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
176 APTRepositoryHandle
::CephQuincyTest
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
177 APTRepositoryHandle
::CephPacific
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
178 APTRepositoryHandle
::CephPacificTest
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
179 APTRepositoryHandle
::CephOctopus
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
180 APTRepositoryHandle
::CephOctopusTest
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
184 /// Get package type, possible URIs and the component associated with the handle.
186 /// The first URI is the preferred one.
187 pub fn info(self, product
: &str) -> (APTRepositoryPackageType
, Vec
<String
>, String
) {
189 APTRepositoryHandle
::Enterprise
=> (
190 APTRepositoryPackageType
::Deb
,
193 "https://enterprise.proxmox.com/debian/pve".to_string(),
194 "https://enterprise.proxmox.com/debian".to_string(),
196 _
=> vec
![format
!("https://enterprise.proxmox.com/debian/{}", product
)],
198 format
!("{}-enterprise", product
),
200 APTRepositoryHandle
::NoSubscription
=> (
201 APTRepositoryPackageType
::Deb
,
204 "http://download.proxmox.com/debian/pve".to_string(),
205 "http://download.proxmox.com/debian".to_string(),
207 _
=> vec
![format
!("http://download.proxmox.com/debian/{}", product
)],
209 format
!("{}-no-subscription", product
),
211 APTRepositoryHandle
::Test
=> (
212 APTRepositoryPackageType
::Deb
,
215 "http://download.proxmox.com/debian/pve".to_string(),
216 "http://download.proxmox.com/debian".to_string(),
218 _
=> vec
![format
!("http://download.proxmox.com/debian/{}", product
)],
220 format
!("{}test", product
),
222 APTRepositoryHandle
::CephQuincy
=> (
223 APTRepositoryPackageType
::Deb
,
224 vec
!["http://download.proxmox.com/debian/ceph-quincy".to_string()],
227 APTRepositoryHandle
::CephQuincyTest
=> (
228 APTRepositoryPackageType
::Deb
,
229 vec
!["http://download.proxmox.com/debian/ceph-quincy".to_string()],
232 APTRepositoryHandle
::CephPacific
=> (
233 APTRepositoryPackageType
::Deb
,
234 vec
!["http://download.proxmox.com/debian/ceph-pacific".to_string()],
237 APTRepositoryHandle
::CephPacificTest
=> (
238 APTRepositoryPackageType
::Deb
,
239 vec
!["http://download.proxmox.com/debian/ceph-pacific".to_string()],
242 APTRepositoryHandle
::CephOctopus
=> (
243 APTRepositoryPackageType
::Deb
,
244 vec
!["http://download.proxmox.com/debian/ceph-octopus".to_string()],
247 APTRepositoryHandle
::CephOctopusTest
=> (
248 APTRepositoryPackageType
::Deb
,
249 vec
!["http://download.proxmox.com/debian/ceph-octopus".to_string()],
255 /// Get the standard repository referenced by the handle.
257 /// An URI in the result is not '/'-terminated (under the assumption that no valid
258 /// product name is).
259 pub fn to_repository(self, product
: &str, suite
: &str) -> APTRepository
{
260 let (package_type
, uris
, component
) = self.info(product
);
263 types
: vec
![package_type
],
264 uris
: vec
![uris
.into_iter().next().unwrap()],
265 suites
: vec
![suite
.to_string()],
266 components
: vec
![component
],
268 comment
: String
::new(),
269 file_type
: APTRepositoryFileType
::List
,