def create(self, entity, nsr_id, vnfr_id, vdu_id="", standby=False): entity = entity.strip() if entity.endswith("}") or entity.endswith("]"): try: entity_dict = json.loads(entity) except: raise SdkException('The passed JSON seems to be invalid.') else: if not os.path.isfile(entity): raise WrongParameters( "{} is neither a file nor does it seem to be valid JSON". format(entity)) with open(entity) as f: file_content = f.read().replace('\n', '') try: entity_dict = json.loads(file_content) except: raise SdkException('The passed JSON seems to be invalid.') if standby: if (vdu_id is None or vdu_id == ''): raise WrongParameters( 'When creating standby VNFCInstances you have to specify the VDU.' ) return self._client.post( "{}/{}/vnfrecords/{}/vdunits/{}/vnfcinstances/standby".format( self.url, nsr_id, vnfr_id, vdu_id), json.dumps(entity_dict)) else: return self._client.post( "{}/{}/vnfrecords/{}/vdunits/{}/vnfcinstances".format( self.url, nsr_id, vnfr_id, vdu_id), json.dumps(entity_dict))
def create(self, entity='', _id=""): if _id is None or _id == "": raise WrongParameters( "Please provide the id of the object where to create this entity" ) return super(SubAgent, self).create(entity, _id + "/" + self.sub_url + "/")
def create(self, entity='{}', _id=""): headers = { "content-type": "application/json", "accept": "application/octet-stream" } entity = entity.strip() if entity.endswith("}") or entity.endswith("]"): try: entity_json = json.loads(entity) except: raise SdkException('The passed JSON seems to be invalid.') return self._client.post(self.url + "/create/%s" % _id, json.dumps(entity_json), headers=headers) else: if not os.path.isfile(entity): raise WrongParameters("%s is not a file") with open(entity) as f: file_content = f.read().replace('\n', '') try: entity_json = json.loads(file_content) except: raise SdkException('The passed JSON seems to be invalid.') return self._client.post(self.url + "/create/%s" % _id, body=json.dumps(entity_json), headers=headers)
def find(self, _id=""): if not _id: raise WrongParameters("Please provide the id") nsr_id, vnfr_id, vdu_id, vnfci = _get_parents_obj_id_from_id( _id, NSRAgent(self._client, self._client.project_id), 'vnfr', 'vdu', 'vnfc_instance') return vnfci
def find(self, _id=""): if not _id: raise WrongParameters( "Please provide the ID. The 'show' action is allowed on this agent but not the 'list' action." ) parent_obj_id, obj = _get_parents_obj_id_from_id( _id, self._main_agent, self.sub_obj) return json.dumps(obj)
def find(self, nsr_id=None, vnfr_name=None, hostname=None, lines=None): if not vnfr_name or not hostname or not nsr_id: raise WrongParameters( 'The log agent is only allowed to execute "show" passing: nsr_id, vnfr_name and hostname' ) if lines: body = json.dumps({'lines': int(lines)}) else: body = None return self._client.post( self.url + "/%s/vnfrecord/%s/hostname/%s" % (nsr_id, vnfr_name, hostname), body)
def find(self, _id=""): if _id is None or _id == "": raise WrongParameters( "Please provide the id, only action show is allowed on this agent" ) if self._main_agent.url == "ns-records": nsr_id, vnfr_id, vdu = _get_parents_obj_id_from_id( _id, self._main_agent, self.sub_obj, 'vdu') else: # self._main_agent == "ns-descriptors" nsd_id, vnfd_id, vdu = _get_parents_obj_id_from_id( _id, self._main_agent, self.sub_obj, 'vdu') return json.dumps(vdu)
def update(self, _id, entity): file_path = entity[0] vnfpackage_id, script = _get_parents_obj_id_from_id( _id, self._main_agent, self.sub_obj) if os.path.exists(file_path) and os.path.isfile(file_path): with open(file_path) as f: file_content = json.dumps(f.read().replace('\n', '')) try: entity_json = json.loads(file_content) except: raise SdkException('The passed JSON seems to be invalid.') response = self._client.put_file( "{}/{}/{}/{}".format(self.url, vnfpackage_id, self.sub_url, _id), entity_json) script['payload'] = json.dumps(response) return script else: raise WrongParameters("{} is not a file".format(file_path))
def get_agent(self, agent, project_id): if agent == "nsr": return self.get_ns_records_agent(project_id) if agent == "nsd": return self.get_ns_descriptor_agent(project_id) if agent == "vnfd": return self.get_vnf_descriptor_agent(project_id) if agent == "vnfr": return self.get_vnf_record_agent(project_id) if agent == "vim": return self.get_vim_instance_agent(project_id) if agent == "vnfpackage": return self.get_vnf_package_agent(project_id) if agent == "project": return self.get_project_agent() if agent == "event": return self.get_event_agent(project_id) if agent == "market": return self.get_market_agent(project_id) if agent == "user": return self.get_user_agent(project_id) if agent == "csarnsd": return self.get_csarnsd_agent(project_id) if agent == "csarvnfd": return self.get_csarvnfd_agent(project_id) if agent == "key": return self.get_key_agent(project_id) if agent == "log": return self.get_log_agent(project_id) if agent == 'vnfci': return self.get_vnfci_agnet(project_id) if "-" in agent and agent.split("-")[0] == 'vdu': # vdu-nsd return self.get_vdu_agnet(project_id, agent.split("-")[1]) if agent == "vdu": # vdu-nsr return self.get_vdu_agnet(project_id, "nsr") if agent == "service": return self.get_service_agent(project_id) if agent == "script": return self.get_script_agent(project_id) raise WrongParameters('Agent %s not found' % agent)
def create(self, entity='{}', _id=""): entity = entity.strip() if entity.endswith("}") or entity.endswith("]"): try: entity_json = json.loads(entity) except: raise SdkException('The passed JSON seems to be invalid.') result = json.loads( self._client.post(self.url + "/%s" % _id, json.dumps(entity_json))) return result else: if not os.path.isfile(entity): raise WrongParameters("{} is not a file".format(entity)) with open(entity) as f: file_content = f.read().replace('\n', '') try: entity_json = json.loads(file_content) except: raise SdkException('The passed JSON seems to be invalid.') return json.loads( self._client.post(self.url + "/%s" % _id, json.dumps(entity_json)))
def create(self, entity, _id="{}"): raise WrongParameters( 'The log agent is only allowed to execute "show" passing: nsr_id, vnfr_name, hostname' )
def update(self, _id, entity): raise WrongParameters( 'Market agent is allowed only to execute "create" passing a link')
def update(self, _id, entity): raise WrongParameters( 'VNFC Instance agent is allowed only to execute "create" and "delete"' )
def find(self, _id=""): raise WrongParameters( 'Market agent is allowed only to execute "create" passing a link')
def delete(self, _id): raise WrongParameters( 'The log agent is only allowed to execute "show" passing: nsr_id, vnfr_name, hostname' )
def find(self, _id=""): raise WrongParameters( 'Market agent is only allowed to execute "create"')
def delete(self, _id): raise WrongParameters( 'Market agent is only allowed to execute "create"')
def update(self, _id, entity): raise WrongParameters( 'csarvnfd agent is only allowed to execute "create"')