2018-08-16 12:36:27 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import base
|
2021-03-31 09:49:23 +02:00
|
|
|
import v2_swagger_client
|
|
|
|
|
|
|
|
class Registry(base.Base, object):
|
|
|
|
def __init__(self):
|
|
|
|
super(Registry,self).__init__(api_type = "registry")
|
2018-08-16 12:36:27 +02:00
|
|
|
|
2019-08-08 10:16:02 +02:00
|
|
|
def create_registry(self, url, registry_type= "harbor", description="", credentialType = "basic",
|
|
|
|
access_key = "admin", access_secret = "Harbor12345", name=base._random_name("registry"),
|
|
|
|
insecure=True, expect_status_code = 201, **kwargs):
|
|
|
|
|
2018-08-16 12:36:27 +02:00
|
|
|
client = self._get_client(**kwargs)
|
2021-03-31 09:49:23 +02:00
|
|
|
registryCredential = v2_swagger_client.RegistryCredential(type=credentialType, access_key=access_key, access_secret=access_secret)
|
|
|
|
registry = v2_swagger_client.Registry(name=name, url=url,
|
2019-08-08 10:16:02 +02:00
|
|
|
description= description, type=registry_type,
|
|
|
|
insecure=insecure, credential=registryCredential)
|
2021-03-31 09:49:23 +02:00
|
|
|
_, status_code, header = client.create_registry_with_http_info(registry)
|
2019-08-08 10:16:02 +02:00
|
|
|
base._assert_status_code(expect_status_code, status_code)
|
|
|
|
return base._get_id_from_header(header), _
|
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)
|
2021-03-31 09:49:23 +02:00
|
|
|
registries = client.list_registries()
|
2018-08-16 12:36:27 +02:00
|
|
|
for registry in registries or []:
|
|
|
|
if registry.endpoint == endpoint:
|
|
|
|
return registry.id
|
2019-08-08 10:16:02 +02:00
|
|
|
raise Exception("registry %s not found" % endpoint)
|
|
|
|
|
|
|
|
def delete_registry(self, registry_id, expect_status_code = 200, **kwargs):
|
|
|
|
client = self._get_client(**kwargs)
|
2021-03-31 09:49:23 +02:00
|
|
|
_, status_code, _ = client.delete_registry_with_http_info(registry_id)
|
2019-08-08 10:16:02 +02:00
|
|
|
base._assert_status_code(expect_status_code, status_code)
|