Skip to content

Commit

Permalink
Merge pull request #20 from fabric-testbed/rel1.3
Browse files Browse the repository at this point in the history
Rel1.3
  • Loading branch information
kthare10 authored Oct 13, 2022
2 parents 0a23374 + d308e22 commit c7d7c4c
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 16 deletions.
2 changes: 1 addition & 1 deletion fabric_mgmt_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__VERSION__ = "1.2.1"
__VERSION__ = "1.3.0"
81 changes: 81 additions & 0 deletions fabric_mgmt_cli/managecli/manage_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,87 @@ def delete_dead_slices(self, *, actor_name: str, callback_topic: str, id_token:
callback_topic=callback_topic, id_token=id_token)
else:
print("No Dead/closing slices to remove")
except Exception as e:
self.logger.error(f"Exception occurred e: {e}")
self.logger.error(traceback.format_exc())

def do_close_delegation(self, *, did: str, actor_name: str, callback_topic: str,
id_token: str) -> Tuple[bool, Error]:
"""
Close delegation by invoking Management Actor Close delegation API
@param did delegation id
@param actor_name actor name
@param callback_topic callback topic
@param id_token identity token
@return Tuple[bool, Error] indicating success or failure status and error containing failure details
"""
actor = self.get_actor(actor_name=actor_name)
if actor is None:
raise Exception(f"Invalid arguments actor_name {actor_name} not found")

try:
actor.prepare(callback_topic=callback_topic)
return actor.close_delegation(did=did), actor.get_last_error()
except Exception as e:
self.logger.error(f"Exception occurred e: {e}")
self.logger.error(traceback.format_exc())

return False, actor.get_last_error()

def close_delegation(self, *, did: str, actor_name: str, callback_topic: str, id_token: str):
"""
Close delegation
@param did delegation id
@param actor_name actor name
@param callback_topic callback topic
@param id_token identity token
"""
try:
result, error = self.do_close_delegation(did=did, actor_name=actor_name,
callback_topic=callback_topic, id_token=id_token)
print(result)
if result is False:
self.print_result(status=error.get_status())
except Exception as e:
self.logger.error(f"Exception occurred e: {e}")
self.logger.error(traceback.format_exc())

def do_remove_delegation(self, *, did: str, actor_name: str, callback_topic: str,
id_token: str) -> Tuple[bool, Error]:
"""
Remove delegation by invoking Management Actor Remove delegation API
@param did delegation id
@param actor_name actor name
@param callback_topic callback topic
@param id_token identity token
@return Tuple[bool, Error] indicating success or failure status and error containing failure details
"""
actor = self.get_actor(actor_name=actor_name)
if actor is None:
raise Exception("Invalid arguments actor_name {} not found".format(actor_name))

try:
actor.prepare(callback_topic=callback_topic)
return actor.remove_delegation(did=did), actor.get_last_error()
except Exception as e:
self.logger.error(f"Exception occurred e: {e}")
self.logger.error(traceback.format_exc())
return False, actor.get_last_error()

def remove_delegation(self, *, did: str, actor_name: str, callback_topic: str, id_token: str):
"""
Remove delegation
@param did delegation id
@param actor_name actor name
@param callback_topic callback topic
@param id_token identity token
"""
try:
result, error = self.do_remove_delegation(did=did, actor_name=actor_name, callback_topic=callback_topic,
id_token=id_token)
print(result)
if result is False:
self.print_result(status=error.get_status())
except Exception as e:
self.logger.error(f"Exception occurred e: {e}")
self.logger.error(traceback.format_exc())
50 changes: 48 additions & 2 deletions fabric_mgmt_cli/managecli/managecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,19 @@ def removealldead(ctx, email, actor, idtoken, refreshtoken):
@click.option('--idtoken', default=None, help='Fabric Identity Token', required=False)
@click.option('--refreshtoken', default=None, help='Fabric Refresh Token', required=False)
@click.option('--email', default=None, help='User email', required=False)
@click.option('--state',
type=click.Choice(['nascent', 'configuring', 'stableok', 'stableerror', 'modifyok', 'modifyerror',
'closing', 'dead'],
case_sensitive=False), required=False)
@click.pass_context
def query(ctx, actor, sliceid, slicename, idtoken, refreshtoken, email):
def query(ctx, actor, sliceid, slicename, idtoken, refreshtoken, email, state):
""" Get slice(s) from an actor
"""
try:
idtoken = KafkaProcessorSingleton.get().start(id_token=idtoken, refresh_token=refreshtoken, ignore_tokens=True)
mgmt_command = ShowCommand(logger=KafkaProcessorSingleton.get().logger)
mgmt_command.get_slices(actor_name=actor, callback_topic=KafkaProcessorSingleton.get().get_callback_topic(),
slice_id=sliceid, slice_name=slicename, id_token=idtoken, email=email)
slice_id=sliceid, slice_name=slicename, id_token=idtoken, email=email, state=state)
KafkaProcessorSingleton.get().stop()
except Exception as e:
# traceback.print_exc()
Expand Down Expand Up @@ -315,6 +319,48 @@ def query(ctx, actor, sliceid, did, state, idtoken, refreshtoken):
click.echo('Error occurred: {}'.format(e))


@delegations.command()
@click.option('--did', help='Delegation Id', required=True)
@click.option('--actor', help='Actor Name', required=True)
@click.option('--idtoken', default=None, help='Fabric Identity Token', required=False)
@click.option('--refreshtoken', default=None, help='Fabric Refresh Token', required=False)
@click.pass_context
def close(ctx, did, actor, idtoken, refreshtoken):
""" Closes delegation for an actor
"""
try:
idtoken = KafkaProcessorSingleton.get().start(id_token=idtoken, refresh_token=refreshtoken, ignore_tokens=True)
mgmt_command = ManageCommand(logger=KafkaProcessorSingleton.get().logger)
mgmt_command.close_delegation(did=did, actor_name=actor,
callback_topic=KafkaProcessorSingleton.get().get_callback_topic(),
id_token=idtoken)
KafkaProcessorSingleton.get().stop()
except Exception as e:
# traceback.print_exc()
click.echo('Error occurred: {}'.format(e))


@delegations.command()
@click.option('--did', help='Delegation Id', required=True)
@click.option('--actor', help='Actor Name', required=True)
@click.option('--idtoken', default=None, help='Fabric Identity Token', required=False)
@click.option('--refreshtoken', default=None, help='Fabric Refresh Token', required=False)
@click.pass_context
def remove(ctx, did, actor, idtoken, refreshtoken):
""" Removes sliver for an actor
"""
try:
idtoken = KafkaProcessorSingleton.get().start(id_token=idtoken, refresh_token=refreshtoken, ignore_tokens=True)
mgmt_command = ManageCommand(logger=KafkaProcessorSingleton.get().logger)
mgmt_command.remove_delegation(did=did, actor_name=actor,
callback_topic=KafkaProcessorSingleton.get().get_callback_topic(),
id_token=idtoken)
KafkaProcessorSingleton.get().stop()
except Exception as e:
# traceback.print_exc()
click.echo('Error occurred: {}'.format(e))


@click.group()
@click.pass_context
def maintenance(ctx):
Expand Down
43 changes: 33 additions & 10 deletions fabric_mgmt_cli/managecli/show_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@

class ShowCommand(Command):
def get_slices(self, *, actor_name: str, callback_topic: str, slice_id: str, slice_name: str, id_token: str,
email: str):
email: str, state: str):
try:
slices, error = self.do_get_slices(actor_name=actor_name, callback_topic=callback_topic, slice_id=slice_id,
slice_name=slice_name, id_token=id_token, email=email)
slice_name=slice_name, id_token=id_token, email=email, state=state)
if slices is not None and len(slices) > 0:
for s in slices:
self.__print_slice(slice_object=s)
Expand Down Expand Up @@ -81,7 +81,7 @@ def get_delegations(self, *, actor_name: str, callback_topic: str, slice_id: str
slice_id=slice_id, did=did, state=state, id_token=id_token)
if delegations is not None and len(delegations) > 0:
for d in delegations:
d.print()
ShowCommand.__print_delegation(dlg_object=d)
else:
print("Status: {}".format(error.get_status()))
except Exception as e:
Expand All @@ -90,23 +90,28 @@ def get_delegations(self, *, actor_name: str, callback_topic: str, slice_id: str
print("Exception occurred while processing get_delegations {}".format(e))

def do_get_slices(self, *, actor_name: str, callback_topic: str, slice_id: str = None, slice_name: str = None,
id_token: str = None, email: str = None) -> Tuple[List[SliceAvro], Error]:
id_token: str = None, email: str = None, state: str = None) -> Tuple[List[SliceAvro] or None, Error]:
actor = self.get_actor(actor_name=actor_name)

if actor is None:
raise Exception("Invalid arguments actor {} not found".format(actor_name))
try:
actor.prepare(callback_topic=callback_topic)
sid = ID(uid=slice_id) if slice_id is not None else None
return actor.get_slices(slice_id=sid, slice_name=slice_name, email=email), actor.get_last_error()
slice_state = None
if state is not None:
slice_state = [SliceState.translate(state_name=state).value]

result = actor.get_slices(slice_id=sid, slice_name=slice_name, email=email, state=slice_state)
return result, actor.get_last_error()
except Exception:
ex_str = traceback.format_exc()
self.logger.error(ex_str)
return None, actor.get_last_error()

def do_get_reservations(self, *, actor_name: str, callback_topic: str, slice_id: str = None, rid: str = None,
state: str = None, id_token: str = None,
email: str = None) -> Tuple[List[ReservationMng], Error]:
email: str = None) -> Tuple[List[ReservationMng] or None, Error]:
actor = self.get_actor(actor_name=actor_name)

if actor is None:
Expand All @@ -126,7 +131,7 @@ def do_get_reservations(self, *, actor_name: str, callback_topic: str, slice_id:
return None, actor.get_last_error()

def do_get_delegations(self, *, actor_name: str, callback_topic: str, slice_id: str = None, did: str = None,
state: str = None, id_token: str = None) -> Tuple[List[DelegationAvro], Error]:
state: str = None, id_token: str = None) -> Tuple[List[DelegationAvro] or None, Error]:
actor = self.get_actor(actor_name=actor_name)

if actor is None:
Expand All @@ -142,9 +147,9 @@ def do_get_delegations(self, *, actor_name: str, callback_topic: str, slice_id:
return actor.get_delegations(delegation_id=did, slice_id=sid,
state=delegation_state), actor.get_last_error()
except Exception as e:
self.logger.error(f"Exception occurred while fetching delegations: e {e}")
self.logger.error(traceback.format_exc())
traceback.print_exc()
ex_str = traceback.format_exc()
self.logger.error(ex_str)
return None, actor.get_last_error()

@staticmethod
Expand Down Expand Up @@ -208,8 +213,26 @@ def __print_slice(*, slice_object: SliceAvro):
print(f"Slice owner: {slice_object.get_owner()}")

if slice_object.get_state() is not None:
print(f"Slice state: {SliceState(slice_object.get_state())}")
print(f"Slice state: {str(SliceState(slice_object.get_state()))}")

if slice_object.get_lease_end() is not None:
print(f"Lease time: {slice_object.get_lease_end()}")
print("")

@staticmethod
def __print_delegation(*, dlg_object: DelegationAvro):
"""
Prints the Delegation Object
"""
print("")
print("Delegation ID: {} Slice ID: {}".format(dlg_object.delegation_id, dlg_object.slice.get_slice_id()))
if dlg_object.delegation_name is not None:
print("Delegation Name: {}".format(dlg_object.delegation_name))
if dlg_object.sequence is not None:
print("Sequence: {}".format(dlg_object.sequence))
if dlg_object.state is not None:
print(f"State: {DelegationState(dlg_object.state)}")
if dlg_object.graph is not None:
print("Graph: {}".format(dlg_object.graph))
print("")

5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ certifi==2020.12.5
attrs==20.3.0
Jinja2==2.11.3
MarkupSafe==1.1.1
python-dateutil==2.8.1
fabric-cf==1.2.2
fabric-credmgr-client==1.2
fabric-cf==1.3.1
fabric-credmgr-client==1.3.2

0 comments on commit c7d7c4c

Please sign in to comment.