Beispiel #1
0
 def remove_shared_instance(self, instance=None, revision=None):
     params = self.json()['parameters']
     if params.has_key('configuration.shared-instances'):
         if instance.instanceId in params['configuration.shared-instances'].values():
             val = [x for x,y in params['configuration.shared-instances'].items() if y == instance.instanceId]
             del params['configuration.shared-instances'][val[0]]
         else:
             raise exceptions.ApiError('Unable find shared instance %s in service %s' % (instance.instanceId, self.name))
         self.modify(params)
     else:
         raise exceptions.ApiError('Unable to add shared instance %s to service %s' % (instance.name, self.name))
Beispiel #2
0
 def add_shared_instance(self, revision, instance):
     params = self.json()['parameters']
     if params.has_key('configuration.shared-instances'):
         params['configuration.shared-instances'][revision.revisionId.split('-')[0]] = instance.instanceId
         self.modify(params)
     else:
         raise exceptions.ApiError('Unable to add shared instance %s to service %s' % (instance.name, self.name))
 def list_applications(self):
     url = self.context.api+'/api/1/organizations/'+self.organizationId+'/applications'
     resp = requests.get(url, auth=(self.context.user, self.context.password), verify=False)
     log.debug(resp.text)
     if resp.status_code == 200:
         return resp.json()
     raise exceptions.ApiError('Unable to get applications list, got error: %s' % resp.text)
    def create_service(self, name, type, parameters={}, zone=None):
        log.info("Creating service: %s" % name)
        if not zone:
            zone = self.zoneId
        data = {
            'name': name,
            'typeId': type,
            'zoneId': zone,
            'parameters': parameters
        }

        url = self.context.api + '/organizations/' + self.organizationId + '/services.json'
        headers = {'Content-Type': 'application/json'}
        resp = requests.post(url,
                             cookies=self.context.cookies,
                             data=json.dumps(data),
                             verify=False,
                             headers=headers)
        log.debug(resp.request.body)
        log.debug(resp.text)

        if resp.status_code == 200:
            return self.get_service(resp.json()['id'])
        raise exceptions.ApiError(
            'Unable to create service %s, got error: %s' % (name, resp.text))
 def json(self, key=None):
     url = self.context.api+'/organizations/'+self.context.organizationId+'/applications/'+self.applicationId+'.json'
     resp = requests.get(url, cookies=self.context.cookies, data="{}", verify=False)
     log.debug(resp.text)
     if resp.status_code == 200:
         return resp.json()
     raise exceptions.ApiError('Unable to get application by url %s\n, got error: %s' % (url, resp.text))
 def list_organizations(self):
     url = self.context.api+'/api/1/organizations'
     resp = requests.get(url, auth=(self.context.user, self.context.password), verify=False)
     log.debug(resp.text)
     if 200 == resp.status_code:
         return resp.json()
     raise exceptions.ApiError('Unable to list organization, got error: %s' % resp.text)
    def create_environment(self, name, default=False, zone=None):
        log.info("Creating environment: %s" % name)
        if not zone:
            zone = self.context.zoneId
        data = {
            'isDefault': default,
            'name': name,
            'backend': zone,
            'organizationId': self.organizationId
        }

        url = self.context.api + '/organizations/' + self.organizationId + '/environments.json'
        headers = {'Content-Type': 'application/json'}
        resp = requests.post(url,
                             cookies=self.context.cookies,
                             data=json.dumps(data),
                             verify=False,
                             headers=headers)
        log.debug(resp.request.body)
        log.debug(resp.text)

        if resp.status_code == 200:
            return self.get_environment(resp.json()['id'])
        raise exceptions.ApiError(
            'Unable to create environment %s, got error: %s' %
            (name, resp.text))
 def list_service(self, id):
     url = self.context.api+'/api/1/services/'+id
     resp = requests.get(url, auth=(self.context.user, self.context.password), verify=False)
     log.debug(resp.text)
     if resp.status_code == 200:
         return resp.json()
     raise exceptions.ApiError('Unable to list service, got error: %s' % resp.text)
 def list_zones(self):
     url = self.context.api + '/organizations/' + self.organizationId + '/zones.json'
     resp = requests.get(url, cookies=self.context.cookies, verify=False)
     log.debug(resp.text)
     if resp.status_code == 200:
         return resp.json()
     raise exceptions.ApiError('Unable to get zones list, got error: %s' %
                               resp.text)
 def json(self):
     url = self.context.api + '/organizations/' + self.context.organizationId + '/applications/' + self.context.applicationId + '/revisions/' + self.revisionId + '.json'
     resp = requests.get(url, cookies=self.context.cookies, verify=False)
     log.debug(resp.text)
     if resp.status_code == 200:
         resp.json()
     raise exceptions.ApiError(
         'Unable to get service properties, got error: %s' % resp.text)
Beispiel #11
0
 def servicesAvailable(self):
     url = self.context.api + '/organizations/' + self.context.organizationId + '/environments/' + self.environmentId + '/availableServices.json'
     resp = requests.get(url, cookies=self.context.cookies, verify=False)
     log.debug(resp.text)
     self.rawRespose = resp
     if resp.status_code == 200:
         return resp.json()
     raise exceptions.ApiError(
         'Unable to update environment, got error: %s' % resp.text)
 def delete(self):
     url = self.context.api + '/organizations/' + self.context.organizationId + '/applications/' + self.context.applicationId + '/revisions/' + self.revisionId + '.json'
     resp = requests.delete(url, cookies=self.context.cookies, verify=False)
     log.debug(resp.text)
     self.rawRespose = resp
     if resp.status_code == 200:
         return True
     raise exceptions.ApiError('Unable to delete revision, got error: %s' %
                               resp.text)
Beispiel #13
0
 def remove_shared_instance(self, instance=None, revision=None):
     params = self.json()['parameters']
     if params.has_key('configuration.shared-instances'):
         old = yaml.safe_load(params['configuration.shared-instances'])
         if instance.instanceId in old.values():
             val = [x for x, y in old.items() if y == instance.instanceId]
             del old[val[0]]
         else:
             raise exceptions.ApiError(
                 'Unable find shared instance %s in service %s' %
                 (instance.instanceId, self.name))
         params['configuration.shared-instances'] = yaml.safe_dump(
             old, default_flow_style=False)
         self.modify(params)
     else:
         raise exceptions.ApiError(
             'Unable to add shared instance %s to service %s' %
             (instance.name, self.name))
 def json(self):
     url = self.context.api+'/api/1/organizations'
     resp = requests.get(url, auth=(self.context.user, self.context.password), verify=False)
     log.debug(resp.text)
     if resp.status_code == 200:
         org = [x for x in resp.json() if x['id'] == self.organizationId]
         if len(org)>0:
             return org[0]
         raise exceptions.NotFoundError('Unable to get organization by id: %s' % self.organizationId)
     raise exceptions.ApiError('Unable to get organization by id: %s, got error: %s' % (self.organizationId, resp.text))
Beispiel #15
0
 def json(self):
     url = self.context.api + '/organizations/' + self.context.organizationId + '/services.json'
     resp = requests.get(url, cookies=self.context.cookies, verify=False)
     log.debug(resp.text)
     if resp.status_code == 200:
         service = [x for x in resp.json() if x['id'] == self.serviceId]
         if len(service) > 0:
             return service[0]
     raise exceptions.ApiError(
         'Unable to get service properties, got error: %s' % resp.text)
Beispiel #16
0
 def json(self):
     url = self.context.api + '/organizations/' + self.context.organizationId + '/providers.json'
     resp = requests.get(url, cookies=self.context.cookies, verify=False)
     log.debug(resp.text)
     if resp.status_code == 200:
         provider = [x for x in resp.json() if x['id'] == self.providerId]
         if len(provider) > 0:
             return provider[0]
     raise exceptions.ApiError(
         'Unable to get provider %s properties, got error: %s' %
         (self.providerId, resp.text))
Beispiel #17
0
 def add_shared_instance(self, revision, instance):
     params = self.json()['parameters']
     if params.has_key('configuration.shared-instances'):
         old = yaml.safe_load(params['configuration.shared-instances'])
         old[revision.revisionId.split('-')[0]] = instance.instanceId
         params['configuration.shared-instances'] = yaml.safe_dump(
             old, default_flow_style=False)
         self.modify(params)
     else:
         raise exceptions.ApiError(
             'Unable to add shared instance %s to service %s' %
             (instance.name, self.name))
Beispiel #18
0
 def regenerate(self):
     url = self.context.api + '/organizations/' + self.context.organizationId + '/services/' + self.serviceId + '/keys/generate.json'
     headers = {'Content-Type': 'application/json'}
     resp = requests.post(url,
                          cookies=self.context.cookies,
                          data=json.dumps({}),
                          verify=False,
                          headers=headers)
     log.debug(resp.text)
     if resp.status_code == 200:
         return resp.json()
     raise exceptions.ApiError('Unable to regenerate key: %s' % resp.text)
 def json(self):
     url = self.context.api + '/organizations.json'
     resp = requests.get(url, cookies=self.context.cookies, verify=False)
     log.debug(resp.text)
     if resp.status_code == 200:
         org = [x for x in resp.json() if x['id'] == self.organizationId]
         if len(org) > 0:
             return org[0]
         return resp.json()
     raise exceptions.ApiError(
         'Unable to get organization by id %s, got error: %s' %
         (self.organizationId, resp.text))
Beispiel #20
0
 def remove_shared_instance(self, instance):
     params = self.parameters
     if SHARED_INSTANCES_PARAMETER_NAME in params:
         # noinspection PyBroadException
         try:
             # Param could contain invalid yaml
             old = yaml.safe_load(params[SHARED_INSTANCES_PARAMETER_NAME])
         except:
             old = params[SHARED_INSTANCES_PARAMETER_NAME]
         if instance.instanceId in old.values():
             val = [x for x, y in old.items() if y == instance.instanceId]
             del old[val[0]]
         else:
             raise exceptions.ApiError(
                 "Unable to find shared instance %s in catalog '%s'" % (instance.instanceId, self.name))
         params[SHARED_INSTANCES_PARAMETER_NAME] = yaml.safe_dump(old, default_flow_style=False)
         self.reconfigure(parameters=params)
     else:
         raise exceptions.ApiError(
             "Unable to remove shared instance %s from catalog '%s'. No shared instances configured." % (
                 instance.name, self.name))
Beispiel #21
0
 def modify(self, parameters):
     url = self.context.api+'/api/1/services/'+self.serviceId
     headers = {'Content-Type': 'application/json'}
     payload = {#'id': self.serviceId,
                'name': self.name,
                'parameters': parameters}
     resp = requests.put(url, auth=(self.context.user, self.context.password), data=json.dumps(payload), verify=False, headers=headers)
     log.debug(resp.request.body)
     log.debug(resp.text)
     if resp.status_code == 200:
         return resp.json()
     raise exceptions.ApiError('Unable to modify service %s: %s' % (self.name, resp.text))
 def set_default_environment(self, id):
     url = self.context.api + '/organizations/' + self.organizationId + '/defaultEnvironment.json'
     headers = {'Content-Type': 'application/json'}
     data = json.dumps({'environmentId': id})
     resp = requests.put(url,
                         cookies=self.context.cookies,
                         data=data,
                         verify=False)
     log.debug(resp.text)
     if resp.status_code == 200:
         return resp.json()
     raise exceptions.ApiError(
         'Unable to set default environment, got error: %s' % resp.text)
Beispiel #23
0
 def delete(self):
     url = self.context.api + '/organizations/' + self.context.organizationId + '/services/' + self.serviceId + '.json'
     headers = {'Content-Type': 'application/json'}
     resp = requests.delete(url,
                            cookies=self.context.cookies,
                            data=json.dumps({}),
                            verify=False,
                            headers=headers)
     log.debug(resp.text)
     if resp.status_code == 200:
         return True
     raise exceptions.ApiError(
         'Unable to delete service %s, got error: %s' %
         (self.serviceId, resp.text))
Beispiel #24
0
 def set_backend(self, zone):
     data = self.json()
     data.update({'backend': zone})
     url = self.context.api + '/organizations/' + self.context.organizationId + '/environments/' + self.environmentId + '.json'
     payload = json.dumps(data)
     headers = {'Content-Type': 'application/json'}
     resp = requests.put(url,
                         cookies=self.context.cookies,
                         data=payload,
                         verify=False,
                         headers=headers)
     log.debug(resp.text)
     if resp.status_code == 200:
         return resp.json()
     raise exceptions.ApiError(
         'Unable to update environment, got error: %s' % resp.text)
Beispiel #25
0
 def upload(self, manifest):
     log.info("Uploading manifest")
     url = self.context.api + '/api/1/applications/' + self.applicationId + '/manifest'
     headers = {'Content-Type': 'application/x-yaml'}
     resp = requests.put(url,
                         auth=(self.context.user, self.context.password),
                         data=manifest.content,
                         verify=False,
                         headers=headers)
     log.debug(resp.text)
     if resp.status_code == 200:
         self.manifest = manifest
         return resp.json()
     raise exceptions.ApiError(
         'Unable to upload manifest to application id: %s, got error: %s' %
         (self.applicationId, resp.text))
Beispiel #26
0
 def create_organization(self, name):
     log.info("Creating organization: %s" % name)
     url = self.context.api + '/organizations.json'
     headers = {'Content-Type': 'application/json'}
     payload = json.dumps({'editable': 'true', 'name': name})
     resp = requests.post(url,
                          cookies=self.context.cookies,
                          data=payload,
                          verify=False,
                          headers=headers)
     log.debug(resp.text)
     if resp.status_code == 200:
         return self.get_organization(resp.json()['id'])
     raise exceptions.ApiError(
         'Unable to create organization %s, got error: %s' %
         (name, resp.text))
    def create_application(self, name, manifest):
        log.info("Creating application: %s" % name)
        url = self.context.api + '/organizations/' + self.organizationId + '/applications.json'

        resp = requests.post(url,
                             files={'path': manifest.content},
                             data={
                                 'manifestSource': 'upload',
                                 'name': name
                             },
                             verify=False,
                             cookies=self.context.cookies)
        log.debug(resp.text)
        if resp.status_code == 200:
            return self.get_application(resp.json()['id'])
        raise exceptions.ApiError(
            'Unable to create application %s, got error: %s' %
            (name, resp.text))
    def create_provider(self, name, parameters):
        log.info("Creating provider: %s" % name)
        parameters['name'] = name

        url = self.context.api + '/organizations/' + self.organizationId + '/providers.json'
        headers = {'Content-Type': 'application/json'}
        resp = requests.post(url,
                             cookies=self.context.cookies,
                             data=json.dumps(parameters),
                             verify=False,
                             headers=headers)
        log.debug(resp.text)

        if resp.status_code == 200:
            return self.get_provider(resp.json()['id'])
        raise exceptions.ApiError(
            'Unable to create environment %s, got error: %s' %
            (name, resp.text))
    def launch(self, **argv):
        url = self.context.api+'/organizations/'+self.context.organizationId+'/applications/'+self.applicationId+'/launch.json'
        headers = {'Content-Type': 'application/json'}
        if not 'environmentId' in argv.keys():
            argv['environmentId'] = self.context.environmentId
        data = json.dumps(argv)
        resp = requests.post(url, cookies=self.context.cookies, data=data, verify=False, headers=headers)

        log.debug('--- APPLICATION LAUNCH REQUEST ---')
        log.debug('REQUEST HEADERS: %s' % resp.request.headers)
        log.debug('REQUEST: %s' % resp.request.body)
        log.debug('RESPONSE: %s' % resp.text)

        self.rawResponse = resp
        if resp.status_code == 200:
            instance_id = resp.json()['id']
            return self.get_instance(id=instance_id)
        raise exceptions.ApiError('Unable to launch application id: %s, got error: %s' % (self.applicationId, resp.text))
 def create_revision(self, name, instance, parameters=[], version=None):
     if not version:
         version=self.get_manifest()['version']
     url = self.context.api+'/organizations/'+self.context.organizationId+'/applications/'+self.applicationId+'/revisions.json'
     headers = {'Content-Type': 'application/json'}
     payload = json.dumps({ 'name': name,
                 'parameters': parameters,
                 'submoduleRevisions': {},
                 'returnValues': [],
                 'applicationId': self.applicationId,
                 'applicationName': self.name,
                 'version': version,
                 'instanceId': instance.instanceId})
     resp = requests.post(url, cookies=self.context.cookies, data=payload, verify=False, headers=headers)
     log.debug(resp.text)
     if resp.status_code==200:
         return self.get_revision(id=resp.json()['id'])
     raise exceptions.ApiError('Unable to get revision, got error: %s' % resp.text)