2018-08-16 12:36:27 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import base
|
|
|
|
import swagger_client
|
|
|
|
|
|
|
|
class Registry(base.Base):
|
2018-11-30 06:32:20 +01:00
|
|
|
def create_registry(self, endpoint, name=None, username="",
|
2018-08-16 12:36:27 +02:00
|
|
|
password="", insecure=True, **kwargs):
|
2018-11-30 06:32:20 +01:00
|
|
|
if name is None:
|
|
|
|
name = base._random_name("registry")
|
2018-08-16 12:36:27 +02:00
|
|
|
client = self._get_client(**kwargs)
|
|
|
|
registry = swagger_client.RepTargetPost(name=name, endpoint=endpoint,
|
|
|
|
username=username, password=password, insecure=insecure)
|
|
|
|
_, _, header = client.targets_post_with_http_info(registry)
|
|
|
|
return base._get_id_from_header(header), name
|
2019-08-01 09:29:42 +02:00
|
|
|
|
2018-08-16 12:36:27 +02:00
|
|
|
def get_registry_id_by_endpoint(self, endpoint, **kwargs):
|
|
|
|
client = self._get_client(**kwargs)
|
|
|
|
registries = client.targets_get()
|
|
|
|
for registry in registries or []:
|
|
|
|
if registry.endpoint == endpoint:
|
|
|
|
return registry.id
|
|
|
|
raise Exception("registry %s not found" % endpoint)
|