]>
git.proxmox.com Git - proxmox-apt.git/blob - src/repositories/standard.rs
1 use std
::convert
::TryFrom
;
4 use anyhow
::{bail, Error}
;
5 use serde
::{Deserialize, Serialize}
;
7 use crate::repositories
::repository
::{
8 APTRepository
, APTRepositoryFileType
, APTRepositoryPackageType
,
11 use proxmox_schema
::api
;
16 description
: "Handle referencing a standard repository.",
21 #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
22 #[serde(rename_all = "kebab-case")]
23 /// Reference to a standard repository and configuration status.
24 pub struct APTStandardRepository
{
25 /// Handle referencing a standard repository.
26 pub handle
: APTRepositoryHandle
,
28 /// Configuration status of the associated repository.
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub status
: Option
<bool
>,
32 /// Display name of the repository.
35 /// Description of the repository.
36 pub description
: String
,
40 #[derive(Debug, Copy, Clone, Serialize, Deserialize, PartialEq)]
41 #[serde(rename_all = "kebab-case")]
42 /// Handles for Proxmox repositories.
43 pub enum APTRepositoryHandle
{
44 /// The enterprise repository for production use.
46 /// The repository that can be used without subscription.
48 /// The test repository.
50 /// Ceph Pacific repository.
52 /// Ceph Pacific test repository.
54 /// Ceph Octoput repository.
56 /// Ceph Octoput test repository.
60 impl From
<APTRepositoryHandle
> for APTStandardRepository
{
61 fn from(handle
: APTRepositoryHandle
) -> Self {
62 APTStandardRepository
{
66 description
: handle
.description(),
71 impl TryFrom
<&str> for APTRepositoryHandle
{
74 fn try_from(string
: &str) -> Result
<Self, Error
> {
76 "enterprise" => Ok(APTRepositoryHandle
::Enterprise
),
77 "no-subscription" => Ok(APTRepositoryHandle
::NoSubscription
),
78 "test" => Ok(APTRepositoryHandle
::Test
),
79 "ceph-pacific" => Ok(APTRepositoryHandle
::CephPacific
),
80 "ceph-pacific-test" => Ok(APTRepositoryHandle
::CephPacificTest
),
81 "ceph-octopus" => Ok(APTRepositoryHandle
::CephOctopus
),
82 "ceph-octopus-test" => Ok(APTRepositoryHandle
::CephOctopusTest
),
83 _
=> bail
!("unknown repository handle '{}'", string
),
88 impl Display
for APTRepositoryHandle
{
89 fn fmt(&self, f
: &mut std
::fmt
::Formatter
<'_
>) -> std
::fmt
::Result
{
91 APTRepositoryHandle
::Enterprise
=> write
!(f
, "enterprise"),
92 APTRepositoryHandle
::NoSubscription
=> write
!(f
, "no-subscription"),
93 APTRepositoryHandle
::Test
=> write
!(f
, "test"),
94 APTRepositoryHandle
::CephPacific
=> write
!(f
, "ceph-pacific"),
95 APTRepositoryHandle
::CephPacificTest
=> write
!(f
, "ceph-pacific-test"),
96 APTRepositoryHandle
::CephOctopus
=> write
!(f
, "ceph-octopus"),
97 APTRepositoryHandle
::CephOctopusTest
=> write
!(f
, "ceph-octopus-test"),
102 impl APTRepositoryHandle
{
103 /// Get the description for the repository.
104 pub fn description(self) -> String
{
106 APTRepositoryHandle
::Enterprise
=> {
107 "This is the default, stable, and recommended repository, available for all \
108 Proxmox subscription users."
110 APTRepositoryHandle
::NoSubscription
=> {
111 "This is the recommended repository for testing and non-production use. \
112 Its packages are not as heavily tested and validated as the production ready \
113 enterprise repository. You don't need a subscription key to access this repository."
115 APTRepositoryHandle
::Test
=> {
116 "This repository contains the latest packages and is primarily used for test labs \
117 and by developers to test new features."
119 APTRepositoryHandle
::CephPacific
=> {
120 "This repository holds the main Proxmox Ceph Pacific packages."
122 APTRepositoryHandle
::CephPacificTest
=> {
123 "This repository contains the Ceph Pacific packages before they are moved to the \
126 APTRepositoryHandle
::CephOctopus
=> {
127 "This repository holds the main Proxmox Ceph Octopus packages."
129 APTRepositoryHandle
::CephOctopusTest
=> {
130 "This repository contains the Ceph Octopus packages before they are moved to the \
137 /// Get the display name of the repository.
138 pub fn name(self) -> String
{
140 APTRepositoryHandle
::Enterprise
=> "Enterprise",
141 APTRepositoryHandle
::NoSubscription
=> "No-Subscription",
142 APTRepositoryHandle
::Test
=> "Test",
143 APTRepositoryHandle
::CephPacific
=> "Ceph Pacific",
144 APTRepositoryHandle
::CephPacificTest
=> "Ceph Pacific Test",
145 APTRepositoryHandle
::CephOctopus
=> "Ceph Octopus",
146 APTRepositoryHandle
::CephOctopusTest
=> "Ceph Octopus Test",
151 /// Get the standard file path for the repository referenced by the handle.
152 pub fn path(self, product
: &str) -> String
{
154 APTRepositoryHandle
::Enterprise
=> {
155 format
!("/etc/apt/sources.list.d/{}-enterprise.list", product
)
157 APTRepositoryHandle
::NoSubscription
=> "/etc/apt/sources.list".to_string(),
158 APTRepositoryHandle
::Test
=> "/etc/apt/sources.list".to_string(),
159 APTRepositoryHandle
::CephPacific
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
160 APTRepositoryHandle
::CephPacificTest
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
161 APTRepositoryHandle
::CephOctopus
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
162 APTRepositoryHandle
::CephOctopusTest
=> "/etc/apt/sources.list.d/ceph.list".to_string(),
166 /// Get package type, possible URIs and the component associated with the handle.
168 /// The first URI is the preferred one.
169 pub fn info(self, product
: &str) -> (APTRepositoryPackageType
, Vec
<String
>, String
) {
171 APTRepositoryHandle
::Enterprise
=> (
172 APTRepositoryPackageType
::Deb
,
175 "https://enterprise.proxmox.com/debian/pve".to_string(),
176 "https://enterprise.proxmox.com/debian".to_string(),
178 _
=> vec
![format
!("https://enterprise.proxmox.com/debian/{}", product
)],
180 format
!("{}-enterprise", product
),
182 APTRepositoryHandle
::NoSubscription
=> (
183 APTRepositoryPackageType
::Deb
,
186 "http://download.proxmox.com/debian/pve".to_string(),
187 "http://download.proxmox.com/debian".to_string(),
189 _
=> vec
![format
!("http://download.proxmox.com/debian/{}", product
)],
191 format
!("{}-no-subscription", product
),
193 APTRepositoryHandle
::Test
=> (
194 APTRepositoryPackageType
::Deb
,
197 "http://download.proxmox.com/debian/pve".to_string(),
198 "http://download.proxmox.com/debian".to_string(),
200 _
=> vec
![format
!("http://download.proxmox.com/debian/{}", product
)],
202 format
!("{}test", product
),
204 APTRepositoryHandle
::CephPacific
=> (
205 APTRepositoryPackageType
::Deb
,
206 vec
!["http://download.proxmox.com/debian/ceph-pacific".to_string()],
209 APTRepositoryHandle
::CephPacificTest
=> (
210 APTRepositoryPackageType
::Deb
,
211 vec
!["http://download.proxmox.com/debian/ceph-pacific".to_string()],
214 APTRepositoryHandle
::CephOctopus
=> (
215 APTRepositoryPackageType
::Deb
,
216 vec
!["http://download.proxmox.com/debian/ceph-octopus".to_string()],
219 APTRepositoryHandle
::CephOctopusTest
=> (
220 APTRepositoryPackageType
::Deb
,
221 vec
!["http://download.proxmox.com/debian/ceph-octopus".to_string()],
227 /// Get the standard repository referenced by the handle.
229 /// An URI in the result is not '/'-terminated (under the assumption that no valid
230 /// product name is).
231 pub fn to_repository(self, product
: &str, suite
: &str) -> APTRepository
{
232 let (package_type
, uris
, component
) = self.info(product
);
235 types
: vec
![package_type
],
236 uris
: vec
![uris
.into_iter().next().unwrap()],
237 suites
: vec
![suite
.to_string()],
238 components
: vec
![component
],
240 comment
: String
::new(),
241 file_type
: APTRepositoryFileType
::List
,