Skip to content

Commit

Permalink
Merge pull request #25 from fabric-testbed/rel1.4
Browse files Browse the repository at this point in the history
Rel1.4 changes
  • Loading branch information
kthare10 authored Jan 20, 2023
2 parents c7d7c4c + bed1c5f commit c39aeab
Show file tree
Hide file tree
Showing 7 changed files with 445 additions and 88 deletions.
100 changes: 93 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ peers:
## Usage
Management CLI supports show and manage commands:
```
(mgmtcli) $ fabric-mgmt-cli
$ fabric-mgmt-cli
Usage: fabric-mgmt-cli [OPTIONS] COMMAND [ARGS]...
Options:
Expand All @@ -134,13 +134,15 @@ Options:
Commands:
delegations Delegation management
maintenance Maintenance Operations
net Dataplane network management
slices Slice management
slivers Sliver management
```
### Delegation Commands
List of the delegation commands supported can be found below:
```
(mgmtcli) $ fabric-mgmt-cli delegations
$ fabric-mgmt-cli delegations
Usage: fabric-mgmt-cli delegations [OPTIONS] COMMAND [ARGS]...
Delegation management
Expand All @@ -150,13 +152,15 @@ Options:
Commands:
claim Claim delegation(s) from AM to Broker
close Closes delegation for an actor
query Get delegation(s) from an actor
reclaim Reclaim delegation(s) from Broker to AM
remove Removes sliver for an actor
```
### Slice Commands
List of the Slice commands supported can be found below:
```
(mgmtcli) $ fabric-mgmt-cli slices
$ fabric-mgmt-cli slices
Usage: fabric-mgmt-cli slices [OPTIONS] COMMAND [ARGS]...
Slice management
Expand All @@ -165,14 +169,15 @@ Options:
--help Show this message and exit.
Commands:
close Closes slice for an actor
query Get slice(s) from an actor
remove Removes slice for an actor
close Closes slice for an actor
query Get slice(s) from an actor
remove Removes slice for an actor
removealldead Removes slice for an actor
```
### Sliver Commands
List of the Sliver commands supported can be found below:
```
(mgmtcli) $ fabric-mgmt-cli slivers
$ fabric-mgmt-cli slivers
Usage: fabric-mgmt-cli slivers [OPTIONS] COMMAND [ARGS]...
Sliver management
Expand All @@ -184,4 +189,85 @@ Commands:
close Closes sliver for an actor
query Get sliver(s) from an actor
remove Removes sliver for an actor
```

### Maintenance Commands
List of the Maintenance commands supported can be found below:
```
$ fabric-mgmt-cli maintenance
Usage: fabric-mgmt-cli maintenance [OPTIONS] COMMAND [ARGS]...
Maintenance Operations
Options:
--help Show this message and exit.
Commands:
site Change Maintenance modes (PreMaint, Maint, Active) for a
specific...
testbed Change Maintenance modes (PreMaint, Maint, Active) for the...
```

#### Examples
NOTE: Specific projects/users can still be allowed to provision by passing:
- Comma separated list of email addresses of the allowed users in the argument `--users`
- Command separated list of the allowed project ids in the argument `--projects`
##### Change Testbed Maintenance Mode
Move Testbed in Pre-Maintenance Mode.
```
$ fabric-mgmt-cli maintenance testbed --actor orchestrator --mode PreMaint --deadline '2022-12-26T22:29:51.214418+00:00' --end '2022-12-30T22:29:51.214418+00:00'
```
Move Testbed in Maintenance Mode.
```
$ fabric-mgmt-cli maintenance testbed --actor orchestrator --mode Maint
```
Move Testbed in Active Mode
```
$ fabric-mgmt-cli maintenance testbed --actor orchestrator --mode Active
```
##### Change Site Maintenance Mode
Move Site in Pre-Maintenance Mode.
```
$ fabric-mgmt-cli maintenance site --name RENC --actor orchestrator --mode PreMaint --deadline '2022-12-26T22:29:51.214418+00:00' --end '2022-12-30T22:29:51.214418+00:00'
```
Move Site in Maintenance Mode.
```
$ fabric-mgmt-cli maintenance site --name RENC --actor orchestrator --mode Maint
```
Move Site in Active Mode
```
$ fabric-mgmt-cli maintenance site --name RENC --actor orchestrator --mode Active
```

##### Change Worker Maintenance Mode
Move Worker in Pre-Maintenance Mode.
```
$ fabric-mgmt-cli maintenance site --name RENC --actor orchestrator --mode PreMaint --deadline '2022-12-26T22:29:51.214418+00:00' --end '2022-12-30T22:29:51.214418+00:00' --workers renc-w1.fabric-testbed.net
```
Move Worker in Maintenance Mode.
```
$ fabric-mgmt-cli maintenance site --name RENC --actor orchestrator --mode Maint --workers renc-w1.fabric-testbed.net
```
Move Worker in Active Mode
```
$ fabric-mgmt-cli maintenance site --name RENC --actor orchestrator --mode Active --workers renc-w1.fabric-testbed.net
```

### Network Management Commands
List of the Network Management commands supported can be found below:
```
$ fabric-mgmt-cli net
Usage: fabric-mgmt-cli net [OPTIONS] COMMAND [ARGS]...
Dataplane network management
Options:
--help Show this message and exit.
Commands:
create Create a new network service
delete Delete an existing network service by name
show Subgroup for network information commands
sync Control NSO device synchronization
```
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.3.0"
__VERSION__ = "1.4.0"
4 changes: 2 additions & 2 deletions fabric_mgmt_cli/managecli/kafka_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def get_tokens(self, id_token: str, refresh_token: str) -> str:
if refresh_token is not None:
try:
proxy = CredmgrProxy(credmgr_host=self.config_processor.get_credmgr_host())
tokens = proxy.refresh(project_name="all", scope="all", refresh_token=refresh_token)
tokens = proxy.refresh(project_id=None, scope="all", refresh_token=refresh_token)
id_token = tokens.get('id_token', None)
except Exception as e:
raise TokenException('Not a valid refresh_token! Error: {}'.format(e))
Expand All @@ -205,7 +205,7 @@ def get_tokens(self, id_token: str, refresh_token: str) -> str:

return id_token

def start(self, id_token: str, refresh_token: str, ignore_tokens: bool = False) -> str:
def start(self, id_token: str = None, refresh_token: str = None, ignore_tokens: bool = False) -> str:
"""
Start Synchronous Kafka Processor
@param id_token identity token
Expand Down
65 changes: 57 additions & 8 deletions fabric_mgmt_cli/managecli/manage_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@
#
# Author: Komal Thareja (kthare10@renci.org)
import traceback
from datetime import datetime, timezone
from typing import Tuple

from fabric_cf.actor.core.apis.abc_delegation import DelegationState
from fabric_cf.actor.core.common.constants import Constants
from fabric_cf.actor.core.kernel.slice_state_machine import SliceState
from fabric_cf.actor.core.manage.error import Error
from fabric_cf.actor.core.util.id import ID
from fabric_mb.message_bus.messages.delegation_avro import DelegationAvro
from fabric_mb.message_bus.messages.site_avro import SiteAvro
from fabric_mb.message_bus.messages.slice_avro import SliceAvro
from fim.slivers.maintenance_mode import MaintenanceInfo, MaintenanceEntry, MaintenanceState

from fabric_mgmt_cli.managecli.show_command import ShowCommand

Expand Down Expand Up @@ -361,13 +365,20 @@ def reclaim_delegations(self, *, broker: str, am: str, callback_topic: str, did:
self.logger.error(f"Exception occurred e: {e}")
self.logger.error(traceback.format_exc())

def toggle_maintenance_mode(self, *, actor_name: str, callback_topic: str, mode: bool = False,
id_token: str = None):
def toggle_maintenance_mode(self, *, actor_name: str, callback_topic: str, state: str, projects: str = None,
users: str = None, site_name: str = None, workers: str = None, deadline: str = None,
expected_end: str = None, id_token: str = None):
"""
Claim delegations
Toggle Maintenance Mode
@param actor_name actor name
@param callback_topic callback topic
@param mode mode
@param state Maintenance State
@param projects comma separated list of project_ids allowed in maintenance
@param users comma separated list of email address of the users allowed in maintenance
@param site_name site name
@param workers comma separated list of specific workers on a site which are in maintenance
@param deadline start time for the Maintenance
@param expected_end Expected End time for the Maintenance
@param id_token id token
"""
status = False
Expand All @@ -378,11 +389,49 @@ def toggle_maintenance_mode(self, *, actor_name: str, callback_topic: str, mode:
if actor is None:
raise Exception(f"Invalid arguments! {actor_name} not found")

mode = MaintenanceState.from_string(state)

if mode == MaintenanceState.PreMaint and deadline is None:
raise Exception("Required parameter: deadline is missing!")

if deadline is not None:
try:
maint_start_time = datetime.fromisoformat(deadline)
except Exception as e:
raise Exception(f"Deadline is not in ISO 8601 format")
now = datetime.now(timezone.utc)
if maint_start_time < now:
raise Exception(f"Deadline cannot be before current time {now}")

if expected_end is not None:
try:
expected_end_time = datetime.fromisoformat(deadline)
except Exception as e:
raise Exception(f"Expected end is not in ISO 8601 format")
now = datetime.now(timezone.utc)
if expected_end_time < now:
raise Exception(f"Expected end cannot be before current time {now}")

try:
actor.prepare(callback_topic=callback_topic)
sites = None
if site_name is None:
site_name = Constants.ALL

worker_list = [site_name]
if workers is not None:
worker_list = workers.split(",")

maint_info = MaintenanceInfo()
for w in worker_list:
entry = MaintenanceEntry(state=state, deadline=deadline, expected_end=expected_end)
maint_info.add(w, entry)
site_avro = SiteAvro(name=site_name, maint_info=maint_info)
sites = [site_avro]

status = actor.toggle_maintenance_mode(actor_guid=str(actor.get_guid()), sites=sites, projects=projects,
users=users, callback_topic=callback_topic)

status = actor.toggle_maintenance_mode(actor_guid=str(actor.get_guid()),
mode=mode, callback_topic=callback_topic)
except Exception as e:
self.logger.error(f"Exception occurred e: {e}")
self.logger.error(traceback.format_exc())
Expand All @@ -394,9 +443,9 @@ def toggle_maintenance_mode(self, *, actor_name: str, callback_topic: str, mode:
error = str(e)

if status:
print(f"Maintenance mode successfully set to {mode}")
print(f"Maintenance mode successfully set to {state}")
else:
print(f"Failure to set maintenance mode error {error}")
print(f"Failure to set maintenance mode: [{state}]; Error: [{error}]")

def delete_dead_slices(self, *, actor_name: str, callback_topic: str, id_token: str, email: str):

Expand Down
Loading

0 comments on commit c39aeab

Please sign in to comment.