Exemplo n.º 1
0
    def __init__(self, name, image_name, image_tag, target_num_instances=1, instance_size='XS', run_command='',
                 instance_ports=[], instance_envvars={}, volumes=[], links=[], details='', namespace=None,
                 scaling_mode='MANUAL', autoscaling_config={}, custom_domain_name='', region_name=None):
        self.name = name
        self.image_name = image_name
        self.image_tag = image_tag
        self.target_num_instances = target_num_instances

        self.instance_size = instance_size
        if instance_size not in INSTANCE_SIZES:
            raise AlaudaServerError(400, 'instance_size must be one of {}'.format(INSTANCE_SIZES))
        self.run_command = run_command
        self.instance_envvars = instance_envvars
        self.instance_ports = instance_ports
        self.volumes = volumes
        self.links = links
        self.details = details
        self.custom_domain_name = custom_domain_name

        self.api_endpoint, self.token, self.username = auth.load_token()
        self.headers = auth.build_headers(self.token)
        self.namespace = namespace or self.username
        self.scaling_mode = scaling_mode
        self.autoscaling_config = autoscaling_config
        self.region_name = region_name
Exemplo n.º 2
0
def get_exec_endpoint(namespace, container):

    try:
        _, _, username = auth.load_token()
        if namespace != username:
            verbose("use default exec endpoint: {0}".format(DEFAULT_EXEC_ENDPOINT))
            return DEFAULT_EXEC_ENDPOINT
    except:
        verbose("use default exec endpoint: {0}".format(DEFAULT_EXEC_ENDPOINT))
        return DEFAULT_EXEC_ENDPOINT

    service_name, _ = parse_container_arg(container)
    verbose("service name: {0}".format(service_name))

    try:
        exec_endpoint = load_exec_endpoint(service_name)
    except:
        api_endpoint, token, username = auth.load_token()
        url = api_endpoint + "/services/{0}/{1}".format(namespace, service_name)
        headers = auth.build_headers(token)

        r = requests.get(url, headers=headers)
        util.check_response(r)
        data = json.loads(r.text)
        exec_endpoint = data["exec_endpoint"]

        save_exec_endpoint(service_name, exec_endpoint)

    return exec_endpoint
Exemplo n.º 3
0
 def __init__(self, name, region=None, file=None, namespace=None):
     self.api_endpoint, self.token, self.username = auth.load_token()
     self.name = name
     self.file = file
     self.namespace = namespace or self.username
     self.region = region
     self.headers = auth.build_headers(self.token)
     #         self.headers['Content-type'] = 'multipart/form-data; boundary=simple boundary'
     del self.headers["Content-type"]
Exemplo n.º 4
0
 def update(self, company):
     api_endpoint, token, _ = auth.load_token()
     headers = auth.build_headers(token)
     url = api_endpoint + 'orgs/{}/'.format(self.name)
     payload = {
         'company': company
     }
     r = requests.put(url, headers=headers, data=json.dumps(payload))
     util.check_response(r)
Exemplo n.º 5
0
    def __init__(self, name, region=None, file=None, namespace=None):
        self.api_endpoint, self.token, self.username = auth.load_token()
        self.name = name
        self.file = file
        self.namespace = namespace or self.username
        self.region = region
        self.headers = auth.build_headers(self.token)
#         self.headers['Content-type'] = 'multipart/form-data; boundary=simple boundary'
        del self.headers['Content-type']
Exemplo n.º 6
0
 def fetch(cls, name):
     api_endpoint, token, _ = auth.load_token()
     headers = auth.build_headers(token)
     url = api_endpoint + 'orgs/{}/'.format(name)
     r = requests.get(url, headers=headers)
     util.check_response(r)
     result = json.loads(r.text)
     organization = cls(result['name'], result['company'], r.text)
     return organization
Exemplo n.º 7
0
 def fetch(cls, id, namespace=None):
     api_endpoint, token, username = auth.load_token()
     url = api_endpoint + 'backups/{0}/{1}/'.format(namespace or username, id)
     headers = auth.build_headers(token)
     r = requests.get(url, headers=headers)
     util.check_response(r)
     data = json.loads(r.text)
     backup = cls(name=data['name'], details=r.text)
     return backup
Exemplo n.º 8
0
 def create(self):
     api_endpoint, token, _ = auth.load_token()
     headers = auth.build_headers(token)
     url = api_endpoint + 'orgs/'
     payload = {
         'name': self.name,
         'company': self.company
     }
     r = requests.post(url, headers=headers, data=json.dumps(payload))
     util.check_response(r)
Exemplo n.º 9
0
 def logs(self, start_time, end_time):
     start, end = util.parse_time(start_time, end_time)
     api_endpoint, token, _ = auth.load_token()
     url = api_endpoint + 'services/{0}/{1}/instances/{2}/logs?start_time={3}&end_time={4}'.format(self.service.namespace,
                                                                                                   self.service.name,
                                                                                                   self.uuid, start, end)
     headers = auth.build_headers(token)
     r = requests.get(url, headers=headers)
     util.check_response(r)
     return r.text
Exemplo n.º 10
0
 def fetch(cls, id, namespace=None):
     api_endpoint, token, username = auth.load_token()
     url = api_endpoint + 'backups/{0}/{1}/'.format(namespace or username,
                                                    id)
     headers = auth.build_headers(token)
     r = requests.get(url, headers=headers)
     util.check_response(r)
     data = json.loads(r.text)
     backup = cls(name=data['name'], details=r.text)
     return backup
Exemplo n.º 11
0
 def list(cls, namespace=None):
     api_endpoint, token, username = auth.load_token()
     url = api_endpoint + 'backups/{}/'.format(namespace or username)
     headers = auth.build_headers(token)
     r = requests.get(url, headers=headers)
     util.check_response(r)
     backups = json.loads(r.text)
     backup_list = []
     for data in backups:
         backup = Backup.fetch(data['backup_id'], namespace)
         backup_list.append(backup)
     return backup_list
Exemplo n.º 12
0
 def remove(cls, id, namespace=None):
     api_endpoint, token, username = auth.load_token()
     url = api_endpoint + 'backups/{0}/{1}/'.format(namespace or username, id)
     headers = auth.build_headers(token)
     r = requests.delete(url, headers=headers)
     try:
         util.check_response(r)
     except AlaudaServerError as ex:
         if ex.status_code == 400:
             print '[alauda] backup "{}" does not exist'.format(id)
         else:
             raise ex
Exemplo n.º 13
0
 def list(cls, namespace=None):
     api_endpoint, token, username = auth.load_token()
     url = api_endpoint + 'backups/{}/'.format(namespace or username)
     headers = auth.build_headers(token)
     r = requests.get(url, headers=headers)
     util.check_response(r)
     backups = json.loads(r.text)
     backup_list = []
     for data in backups:
         backup = Backup.fetch(data['backup_id'], namespace)
         backup_list.append(backup)
     return backup_list
Exemplo n.º 14
0
 def remove(cls, name, namespace=None):
     print '[alauda] Removing service "{}"'.format(name)
     api_endpoint, token, username = auth.load_token()
     url = api_endpoint + 'services/{}/'.format(namespace or username) + name
     headers = auth.build_headers(token)
     try:
         r = requests.delete(url, headers=headers)
         util.check_response(r)
     except AlaudaServerError as ex:
         if ex.status_code == 404:
             print '[alauda] Service "{}" does not exist'.format(name)
         else:
             raise ex
Exemplo n.º 15
0
 def remove(cls, id, namespace=None):
     api_endpoint, token, username = auth.load_token()
     url = api_endpoint + 'backups/{0}/{1}/'.format(namespace or username,
                                                    id)
     headers = auth.build_headers(token)
     r = requests.delete(url, headers=headers)
     try:
         util.check_response(r)
     except AlaudaServerError as ex:
         if ex.status_code == 400:
             print '[alauda] backup "{}" does not exist'.format(id)
         else:
             raise ex
Exemplo n.º 16
0
 def list(cls):
     api_endpoint, token, _ = auth.load_token()
     headers = auth.build_headers(token)
     url = api_endpoint + 'orgs/'
     r = requests.get(url, headers=headers)
     util.check_response(r)
     organization_list = []
     if r.text:
         organizations = json.loads(r.text)
         for data in organizations:
             organization = Organization.fetch(data['name'])
             organization_list.append(organization)
     return organization_list
Exemplo n.º 17
0
 def remove(cls, name, namespace=None):
     print '[alauda] Removing service "{}"'.format(name)
     api_endpoint, token, username = auth.load_token()
     url = api_endpoint + 'services/{}/'.format(namespace
                                                or username) + name
     headers = auth.build_headers(token)
     try:
         r = requests.delete(url, headers=headers)
         util.check_response(r)
     except AlaudaServerError as ex:
         if ex.status_code == 404:
             print '[alauda] Service "{}" does not exist'.format(name)
         else:
             raise ex
Exemplo n.º 18
0
    def fetch(cls, name, namespace=None):
        service_name = name.split(".")[0]

        api_endpoint, token, username = auth.load_token()
        url = api_endpoint + 'services/{}/'.format(namespace or username) + service_name
        headers = auth.build_headers(token)
        r = requests.get(url, headers=headers)
        util.check_response(r)
        data = json.loads(r.text)
        executer = cls(name=name,
                       username=username,
                       exec_endpoint=data['exec_endpoint'],
                       namespace=data['namespace'])
        return executer
Exemplo n.º 19
0
 def fetch(cls, name, namespace=None):
     api_endpoint, token, username = auth.load_token()
     url = api_endpoint + 'services/{}/'.format(namespace or username) + name
     headers = auth.build_headers(token)
     r = requests.get(url, headers=headers)
     util.check_response(r)
     data = json.loads(r.text)
     service = cls(name=data['service_name'],
                   image_name=data['image_name'],
                   image_tag=data['image_tag'],
                   target_num_instances=data['target_num_instances'],
                   instance_size=data['instance_size'],
                   details=r.text,
                   namespace=data['namespace'])
     return service
Exemplo n.º 20
0
 def list(cls, namespace, page):
     api_endpoint, token, username = auth.load_token()
     url = api_endpoint + 'services/{}/?page={}'.format(namespace or username, page)
     headers = auth.build_headers(token)
     r = requests.get(url, headers=headers)
     util.check_response(r)
     service_list = []
     services = json.loads(r.text)
     services = services.get('results', [])
     for data in services:
         try:
             service = Service.fetch(data['service_name'], namespace)
             service_list.append(service)
         except AlaudaServerError:
             continue
     return service_list
Exemplo n.º 21
0
 def fetch(cls, name, namespace=None):
     api_endpoint, token, username = auth.load_token()
     url = api_endpoint + 'services/{}/'.format(namespace
                                                or username) + name
     headers = auth.build_headers(token)
     r = requests.get(url, headers=headers)
     util.check_response(r)
     data = json.loads(r.text)
     service = cls(name=data['service_name'],
                   image_name=data['image_name'],
                   image_tag=data['image_tag'],
                   target_num_instances=data['target_num_instances'],
                   instance_size=data['instance_size'],
                   details=r.text,
                   namespace=data['namespace'])
     return service
Exemplo n.º 22
0
 def list(cls, namespace, page):
     api_endpoint, token, username = auth.load_token()
     url = api_endpoint + 'services/{}/?page={}'.format(
         namespace or username, page)
     headers = auth.build_headers(token)
     r = requests.get(url, headers=headers)
     util.check_response(r)
     service_list = []
     services = json.loads(r.text)
     services = services.get('results', [])
     for data in services:
         try:
             service = Service.fetch(data['service_name'], namespace)
             service_list.append(service)
         except AlaudaServerError:
             continue
     return service_list
Exemplo n.º 23
0
    def __init__(self,
                 name,
                 image_name,
                 image_tag,
                 target_num_instances=1,
                 instance_size='XS',
                 run_command='',
                 instance_ports=[],
                 instance_envvars={},
                 volumes=[],
                 links=[],
                 details='',
                 namespace=None,
                 scaling_mode='MANUAL',
                 autoscaling_config={},
                 custom_domain_name='',
                 region_name=None):
        self.name = name
        self.image_name = image_name
        self.image_tag = image_tag
        self.target_num_instances = target_num_instances

        self.instance_size = instance_size
        if instance_size not in INSTANCE_SIZES:
            raise AlaudaServerError(
                400, 'instance_size must be one of {}'.format(INSTANCE_SIZES))
        self.run_command = run_command
        self.instance_envvars = instance_envvars
        self.instance_ports = instance_ports
        self.volumes = volumes
        self.links = links
        self.details = details
        self.custom_domain_name = custom_domain_name

        self.api_endpoint, self.token, self.username = auth.load_token()
        self.headers = auth.build_headers(self.token)
        self.namespace = namespace or self.username
        self.scaling_mode = scaling_mode
        self.autoscaling_config = autoscaling_config
        self.region_name = region_name
Exemplo n.º 24
0
 def __init__(self):
     self.api_endpoint, self.token, self.username = auth.load_token()
     self.headers = auth.build_headers(self.token)
Exemplo n.º 25
0
 def __init__(self):
     self.api_endpoint, self.token, self.username = auth.load_token()
     self.headers = auth.build_headers(self.token)