from . import riftcm_config_plugin
-# Charm service name accepts only a to z and -.
def get_vnf_unique_name(nsr_name, vnfr_name, member_vnf_index):
+ """Get the unique VNF name.
+ Charm names accepts only a to z and non-consecutive - characters."""
name = "{}-{}-{}".format(nsr_name, vnfr_name, member_vnf_index)
new_name = ''
for c in name:
elif not c.isalpha():
c = "-"
new_name += c
- return new_name.lower()
+ return re.sub('\-+', '-', new_name.lower())
class JujuConfigPlugin(riftcm_config_plugin.RiftCMConfigPluginBase):
'launchpad/packages/vnfd',
self._project.name,
agent_vnfr.vnfr_msg.vnfd.id,
- 'charms/trusty',
+ 'charms',
charm)
self._log.debug("jujuCA: Charm dir is {}".format(path))
if not os.path.isdir(path):
- self._log.error("jujuCA: Did not find the charm directory at {}".
- format(path))
+ self._log.error("jujuCA: Did not find the charm directory at {}".format(path))
path = None
except Exception as e:
self.log.exception(e)
if service in self._tasks:
tasks = []
for action in self._tasks[service].keys():
- #if self.check_task_status(service, action):
tasks.append(action)
del tasks
except KeyError as e:
"""
return True
- def check_task_status(self, service, action):
- #self.log.debug("jujuCA: check task status for %s, %s" % (service, action))
- try:
- task = self._tasks[service][action]
- if task.done():
- self.log.debug("jujuCA: Task for %s, %s done" % (service, action))
- e = task.exception()
- if e:
- self.log.error("jujuCA: Error in task for {} and {} : {}".
- format(service, action, e))
- raise Exception(e)
- r= task.result()
- if r:
- self.log.debug("jujuCA: Task for {} and {}, returned {}".
- format(service, action,r))
- return True
- else:
- self.log.debug("jujuCA: task {}, {} not done".
- format(service, action))
- return False
- except KeyError as e:
- self.log.error("jujuCA: KeyError for task for {} and {}: {}".
- format(service, action, e))
- except Exception as e:
- self.log.error("jujuCA: Error for task for {} and {}: {}".
- format(service, action, e))
- raise
- return True
-
@asyncio.coroutine
def _vnf_config_primitive(self, nsr_id, vnfr_id, primitive,
vnf_config=None, wait=False):
try:
vnfr = self._juju_vnfs[agent_vnfr.id].vnfr
+ service = vnfr['vnf_juju_name']
except KeyError:
self._log.debug("Did not find VNFR %s in Juju plugin",
agent_vnfr.name)
if not rc:
return False
- # action_ids = []
try:
if vnfr_msg.mgmt_interface.ip_address:
vnfr['tags'].update({'rw_mgmt_ip': vnfr_msg.mgmt_interface.ip_address})
self._log.error(msg)
return False
- elif rc == "pending":
- action_ids.append(eid)
-
elif primitive.name:
config = {}
if primitive.name == 'config':
val = self.xlate(param.value,
vnfr['tags'])
config.update({param.name: val})
- except KeyError as e:
- self._log.exception("jujuCA:(%s) Initial config error(%s): config=%s",
- vnfr['vnf_juju_name'], str(e), config)
- config = None
- return False
-
- if config:
- self.juju_log('info', vnfr['vnf_juju_name'],
- "Applying Initial config:%s",
- config)
-
- rc = yield from self.api.apply_config(
- config,
- application=service,
- )
- if rc is False:
- self.log.error("Service {} is in error state".format(service))
- return False
if config:
self.juju_log('info', vnfr['vnf_juju_name'],
"Applying Initial config:%s",
config)
- # Apply any actions specified as part of initial config
- for primitive in vnfr['config'].initial_config_primitive:
- if primitive.name != 'config':
- self._log.debug("jujuCA:(%s) Initial config action primitive %s",
- vnfr['vnf_juju_name'], primitive)
- action = primitive.name
- params = {}
- for param in primitive.parameter:
- val = self.xlate(param.value, vnfr['tags'])
- params.update({param.name: val})
-
- self._log.info("jujuCA:(%s) Action %s with params %s",
- vnfr['vnf_juju_name'], action, params)
- self._log.debug("executing action")
- resp = yield from self.api.execute_action(
- service,
- action,
- **params,
- )
- self._log.debug("executed action")
- if 'error' in resp:
- self._log.error("Applying initial config on {} failed for {} with {}: {}".
- format(vnfr['vnf_juju_name'], action, params, resp))
- return False
-
- # action_ids.append(resp['action']['tag'])
- # action_ids.append(resp)
+ rc = yield from self.api.apply_config(
+ config,
+ application=service,
+ )
+ if rc is False:
+ self.log.error("Service {} is in error state".format(service))
+ return False
+ else:
+ # Apply any actions specified as part of initial config
+ for primitive in vnfr['config'].initial_config_primitive:
+ if primitive.name != 'config':
+ self._log.debug("jujuCA:(%s) Initial config action primitive %s",
+ vnfr['vnf_juju_name'], primitive)
+ action = primitive.name
+ params = {}
+ for param in primitive.parameter:
+ val = self.xlate(param.value, vnfr['tags'])
+ params.update({param.name: val})
+
+ self._log.info("jujuCA:(%s) Action %s with params %s",
+ vnfr['vnf_juju_name'], action, params)
+ self._log.debug("executing action")
+ resp = yield from self.api.execute_action(
+ service,
+ action,
+ **params,
+ )
+ self._log.debug("executed action")
+ if 'error' in resp:
+ self._log.error("Applying initial config on {} failed for {} with {}: {}".
+ format(vnfr['vnf_juju_name'], action, params, resp))
+ return False
except KeyError as e:
self._log.info("Juju config agent(%s): VNFR %s not managed by Juju",
vnfr['vnf_juju_name'], agent_vnfr.id)
rc = 'configuring'
- if not self.check_task_status(service, 'deploy'):
- return rc
-
try:
- resp = yield from self.api.get_service_status(application=service)
- self._log.debug("jujuCA: Get service %s status? %s", service, resp)
+ # Get the status of the application
+ resp = yield from self.api.get_application_status(service)
+
+ # No status means the application is still pending deployment
+ if resp is None:
+ return rc
if resp == 'error':
return 'error'