2
A Cobbler repesentation of a yum repo.
4
Copyright 2006-2009, Red Hat, Inc
5
Michael DeHaan <mdehaan@redhat.com>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
from cexceptions import *
30
# this datastructure is described in great detail in item_distro.py -- read the comments there.
33
["arch","",0,"Arch",True,"ex: i386, x86_64",['i386','x86_64','ia64','ppc','s390', 'noarch', 'src'],"str"],
34
["breed","",0,"Breed",True,"",codes.VALID_REPO_BREEDS,"str"],
35
["comment","",0,"Comment",True,"Free form text description",0,"str"],
36
["ctime",0,0,"",False,"",0,"float"],
37
["depth",2,0,"",False,"",0,"float"],
38
["keep_updated",True,0,"Keep Updated",True,"Update this repo on next 'cobbler reposync'?",0,"bool"],
39
["mirror",None,0,"Mirror",True,"Address of yum or rsync repo to mirror",0,"str"],
40
["mtime",0,0,"",False,"",0,"float"],
41
["name","",0,"Name",True,"Ex: f10-i386-updates",0,"str"],
42
["owners","SETTINGS:default_ownership",0,"Owners",True,"Owners list for authz_ownership (space delimited)",[],"list"],
43
["parent",None,0,"",False,"",0,"str"],
44
["rpm_list",[],0,"RPM List",True,"Mirror just these RPMs (yum only)",0,"list"],
45
# ["os_version","",0,"OS Version",True,"ex: rhel4"],
46
["uid",None,0,"",False,"",0,"str"],
47
["createrepo_flags",'<<inherit>>',0,"Createrepo Flags",True,"Flags to use with createrepo",0,"dict"],
48
["environment",{},0,"Environment Variables",True,"Use these environment variables during commands (key=value, space delimited)",0,"dict"],
49
["mirror_locally",True,0,"Mirror locally",True,"Copy files or just reference the repo externally?",0,"bool"],
50
["priority",99,0,"Priority",True,"Value for yum priorities plugin, if installed",0,"int"],
51
["yumopts",{},0,"Yum Options",True,"Options to write to yum config file",0,"dict"]
54
class Repo(item.Item):
57
COLLECTION_TYPE = "repo"
60
ds = self.to_datastruct()
61
cloned = Repo(self.config)
62
cloned.from_datastruct(ds)
68
def _guess_breed(self):
69
# backwards compatibility
70
if (self.breed == "" or self.breed is None):
71
if self.mirror.startswith("http://") or self.mirror.startswith("ftp://"):
73
elif self.mirror.startswith("rhn://"):
76
self.set_breed("rsync")
78
def set_mirror(self,mirror):
80
A repo is (initially, as in right now) is something that can be rsynced.
81
reposync/repotrack integration over HTTP might come later.
84
if self.arch is None or self.arch == "":
85
if mirror.find("x86_64") != -1:
86
self.set_arch("x86_64")
87
elif mirror.find("x86") != -1 or mirror.find("i386") != -1:
89
elif mirror.find("ia64") != -1:
91
elif mirror.find("s390") != -1:
92
self.set_arch("s390x")
96
def set_keep_updated(self,keep_updated):
98
This allows the user to disable updates to a particular repo for whatever reason.
100
self.keep_updated = utils.input_boolean(keep_updated)
103
def set_yumopts(self,options,inplace=False):
105
Kernel options are a space delimited list,
106
like 'a=b c=d e=f g h i=j' or a hash.
108
(success, value) = utils.input_string_or_hash(options,allow_multiples=False)
110
raise CX(_("invalid yum options"))
113
for key in value.keys():
114
self.yumopts[key] = value[key]
119
def set_environment(self,options,inplace=False):
121
Yum can take options from the environment. This puts them there before
124
(success, value) = utils.input_string_or_hash(options,allow_multiples=False)
126
raise CX(_("invalid environment options"))
129
for key in value.keys():
130
self.environment[key] = value[key]
132
self.environment = value
136
def set_priority(self,priority):
138
Set the priority of the repository. 1= highest, 99=default
139
Only works if host is using priorities plugin for yum.
142
priority = int(str(priority))
144
raise CX(_("invalid priority level: %s") % priority)
145
self.priority = priority
148
def set_rpm_list(self,rpms):
150
Rather than mirroring the entire contents of a repository (Fedora Extras, for instance,
151
contains games, and we probably don't want those), make it possible to list the packages
152
one wants out of those repos, so only those packages + deps can be mirrored.
154
self.rpm_list = utils.input_string_or_list(rpms)
157
def set_createrepo_flags(self,createrepo_flags):
159
Flags passed to createrepo when it is called. Common flags to use would be
160
-c cache or -g comps.xml to generate group information.
162
if createrepo_flags is None:
163
createrepo_flags = ""
164
self.createrepo_flags = createrepo_flags
167
def set_breed(self,breed):
169
return utils.set_repo_breed(self,breed)
171
def set_os_version(self,os_version):
173
return utils.set_repo_os_version(self,os_version)
175
def set_arch(self,arch):
177
Override the arch used for reposync
179
return utils.set_arch(self,arch,repo=True)
181
def set_mirror_locally(self,value):
182
self.mirror_locally = utils.input_boolean(value)
185
def get_parent(self):
187
currently the Cobbler object space does not support subobjects of this object
188
as it is conceptually not useful.
192
def check_if_valid(self):
193
if self.name is None:
194
raise CX("name is required")
195
if self.mirror is None:
196
raise CX("Error with repo %s - mirror is required" % (self.name))