Skip to content

Commit

Permalink
Adding ServiceFabric commands for version 5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
samedder committed May 5, 2017
1 parent 49c281b commit 02e97a9
Show file tree
Hide file tree
Showing 20 changed files with 2,763 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ src/build
/.vs/config/applicationhost.config
.vscode/settings.json
.vscode/.ropeproject/
.vscode/cSpell.json
.project
.pydevproject

Expand Down
10 changes: 10 additions & 0 deletions src/command_modules/azure-cli-sf/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. :changelog:
Release History
===============

1.0.0 (2017-05-04)
++++++++++++++++++

* Initial release of Service Fabric module. This corresponds to 5.6 Service
Sabric product release.
1 change: 1 addition & 0 deletions src/command_modules/azure-cli-sf/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include *.rst
6 changes: 6 additions & 0 deletions src/command_modules/azure-cli-sf/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Microsoft Azure CLI Service Fabric Module
=========================================

This package is for the `sf` module. It contains commands that can be used
to manage and administer Service Fabric clusters.

8 changes: 8 additions & 0 deletions src/command_modules/azure-cli-sf/azure/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# ------------------------------------------------------------------------------

import pkg_resources
pkg_resources.declare_namespace(__name__)
8 changes: 8 additions & 0 deletions src/command_modules/azure-cli-sf/azure/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# ------------------------------------------------------------------------------

import pkg_resources
pkg_resources.declare_namespace(__name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# ------------------------------------------------------------------------------

import pkg_resources
pkg_resources.declare_namespace(__name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -----------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------

import azure.cli.command_modules.sf._help # pylint: disable=unused-import


def load_params(_):
# pylint: disable=redefined-outer-name
import azure.cli.command_modules.sf._params


def load_commands():
# pylint: disable=redefined-outer-name
import azure.cli.command_modules.sf.commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -----------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------


def cf_sf_client(_):
from azure.cli.core.util import CLIError
from azure.servicefabric import ServiceFabricClientAPIs
from azure.cli.command_modules.sf.custom import (
sf_get_cert_info, sf_get_connection_endpoint,
sf_get_ca_cert_info, sf_get_verify_setting
)
from azure.cli.command_modules.sf.cluster_auth import (
ClientCertAuthentication
)
from azure.cli.core.commands.client_factory import (
configure_common_settings
)

endpoint = sf_get_connection_endpoint()
if endpoint is None:
raise CLIError(
"Connection endpoint not specified, run 'az sf cluster "
"select' first."
)

cert = sf_get_cert_info()
if cert is not None:
ca_cert = sf_get_ca_cert_info()
else:
ca_cert = None

no_verify = sf_get_verify_setting()

auth = ClientCertAuthentication(cert, ca_cert, no_verify)
client = ServiceFabricClientAPIs(auth, base_url=endpoint)
configure_common_settings(client)
return client
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -----------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------

from azure.cli.core.help_files import helps

# pylint: disable=line-too-long

helps["sf"] = """
type: group
short-summary: Manage and administer a Service Fabric cluster
"""
helps["sf application"] = """
type: group
short-summary: Manage the applications running on a Service Fabric cluster
"""
helps["sf chaos"] = """
type: group
short-summary: Manage the Service Fabric Chaos service, designed to
simulate real failures
"""
helps["sf cluster"] = """
type: group
short-summary: Select and manage a Service Fabric cluster
"""
helps["sf compose"] = """
type: group
short-summary: Manage and deploy applications created from Docker Compose
"""
helps["sf node"] = """
type: group
short-summary: Manage the nodes that create a Service Fabric cluster
"""
helps["sf partition"] = """
type: group
short-summary: Manage the partitions of a Service Fabric service
"""
helps["sf replica"] = """
type: group
short-summary: Manage the replicas of a Service Fabric service partition
"""
helps["sf service"] = """
type: group
short-summary: Manage the services of a Service Fabric application
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# -----------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------

from azure.cli.core.sdk.util import ParametersContext
from azure.cli.core.util import get_json_object

# For some commands we take JSON strings as possible
with ParametersContext(command="sf application create") as c:
c.register("parameters", ("--parameters",), type=get_json_object,
help="JSON encoded list of application parameters.")

with ParametersContext(command="sf application create") as c:
c.register("metrics", ("--metrics",), type=get_json_object,
help="JSON encoded list of application metrics and their \
descriptions.")

with ParametersContext(command="sf application upgrade") as c:
c.register("parameters", ("--parameters",), type=get_json_object,
help="JSON encoded list of application parameter overrides to \
be applied when upgrading an application. Note, when starting \
an upgrade, be sure to include the existing application \
parameters, if any.")

with ParametersContext(command="sf application upgrade") as c:
c.register("default_service_health_policy",
("--default_service_health_policy",),
type=get_json_object,
help="JSON encoded specification of the health policy used by \
default to evaluate the health of a service type.")

with ParametersContext(command="sf application upgrade") as c:
c.register("service_health_policy", ("--service_health_policy",),
type=get_json_object,
help="JSON encoded map with service type health policy per \
service type name. The map is empty be default.")

with ParametersContext(command="sf service create") as c:
c.register("load_metrics", ("--load_metrics",),
type=get_json_object,
help="JSON encoded list of metrics used when load balancing \
services across nodes.")

with ParametersContext(command="sf service create") as c:
c.register("placement_policy_list", ("--placement_policy_list",),
type=get_json_object,
help="JSON encoded list of placement policies for the service, \
and any associated domain names. Policies can be one or more \
of: `NonPartiallyPlaceService`, `PreferPrimaryDomain`, \
`RequireDomain`, `requireDomainDistribution`")

with ParametersContext(command="sf service update") as c:
c.register("load_metrics", ("--load_metrics",),
type=get_json_object,
help="JSON encoded list of metrics used when load balancing \
services across nodes.")

with ParametersContext(command="sf service update") as c:
c.register("placement_policy_list", ("--placement_policy_list",),
type=get_json_object,
help="JSON encoded list of placement policies for the service, \
and any associated domain names. Policies can be one or more \
of: `NonPartiallyPlaceService`, `PreferPrimaryDomain`, \
`RequireDomain`, `requireDomainDistribution`")

with ParametersContext(command="sf chaos start") as c:
c.register("application_type_health_policy_map",
("--application_type_health_policy_map",),
type=get_json_object,
help="JSON encoded list with max percentage unhealthy \
applications for specific application types. Each entry \
specifies as a key the application type name and as a value \
an integer that represents the MaxPercentUnhealthyApplications \
percentage used to evaluate the applications of the specified \
application type.")

with ParametersContext(command="sf node service-package-upload") as c:
c.register("share_policy",
("--share_policy",),
type=get_json_object,
help="JSON encoded list of sharing policies. Each sharing \
policy element is composed of a 'name' and 'scope'. The name \
corresponds to the name of the code, configuration, or data \
package that is to be shared. The scope can either 'None', \
'All', 'Code', 'Config' or 'Data'.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -----------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------

from msrest.authentication import Authentication


# pylint: disable=too-few-public-methods
class ClientCertAuthentication(Authentication):
"""Client certificate authentication for Service Fabric clusters"""
def __init__(self, cert=None, ca_cert=None, no_verify=False):
self.cert = cert
self.ca_cert = ca_cert
self.no_verify = no_verify

def signed_session(self):
"""Create requests session with any required auth headers
applied.
:rtype: requests.Session.
"""
session = super(ClientCertAuthentication, self).signed_session()
if self.cert is not None:
session.cert = self.cert
if self.ca_cert is not None:
session.verify = self.ca_cert
if self.no_verify:
session.verify = False

return session
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# -----------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------

from azure.cli.core.commands import cli_command
from azure.cli.command_modules.sf._factory import cf_sf_client
from azure.cli.core.sdk.util import (
create_service_adapter,
ServiceGroup
)

custom_path = "azure.cli.command_modules.sf.custom#{}"
cluster_operations = create_service_adapter("azure.servicefabric",
"ServiceFabricClientAPIs")

# No client for specific custom commands
cli_command(__name__, "sf cluster select",
"azure.cli.command_modules.sf.custom#sf_select")
cli_command(__name__, "sf application upload",
"azure.cli.command_modules.sf.custom#sf_upload_app")

with ServiceGroup(__name__, cf_sf_client, cluster_operations,
custom_path) as sg:
# Cluster level commands
with sg.group("sf cluster") as cl_group:
cl_group.command("manifest", "get_cluster_manifest")
cl_group.command("code-version",
"get_provisioned_fabric_code_version_info_list")
cl_group.command("config-version",
"get_provisioned_fabric_config_version_info_list")
cl_group.command("health", "get_cluster_health")

# Application level commands
with sg.group("sf application") as app_group:
app_group.custom_command("create", "sf_create_app")
app_group.custom_command("report-health", "sf_report_app_health")
app_group.custom_command("upgrade", "sf_upgrade_app")
app_group.command("health", "get_application_health")
app_group.command("manifest", "get_application_health")
app_group.command("provision", "provision_application_type")
app_group.command("delete", "delete_application")
app_group.command("unprovision", "unprovision_application_type")
app_group.command("package-delete", "delete_image_store_content")
app_group.command("type", "get_application_type_info_list")
app_group.command("list", "get_application_info_list")

# Service level commands
with sg.group("sf service") as svc_group:
svc_group.custom_command("create", "sf_create_service")
svc_group.custom_command("update", "sf_update_service")
svc_group.custom_command("report-health", "sf_report_svc_health")
svc_group.command("list", "get_service_info_list")
svc_group.command("manifest", "get_service_manifest")
svc_group.command("application-name", "get_application_name_info")
svc_group.command("description", "get_service_description")
svc_group.command("health", "get_service_health")
svc_group.command("resolve", "resolve_service")

# Partition level commands
with sg.group("sf partition") as partition_group:
partition_group.custom_command("report-health",
"sf_report_partition_health")
partition_group.command("info", "get_partition_info")
partition_group.command("service-name", "get_service_name_info")
partition_group.command("health", "get_partition_health")

# Replica level commands
with sg.group("sf replica") as replica_group:
replica_group.custom_command("report-health",
"sf_report_replica_health")
replica_group.command("health", "get_replica_health")

# Node level commands
with sg.group("sf node") as node_group:
node_group.custom_command("report-health", "sf_report_node_health")
node_group.custom_command("service-package-upload",
"sf_service_package_upload")
node_group.command("list", "get_node_info_list")
node_group.command("remove-state", "remove_node_state")
node_group.command("stop", "stop_node")
node_group.command("restart", "restart_node")
node_group.command("start", "start_node")
node_group.command("replica-list",
"get_deployed_service_replica_info_list")
node_group.command("load", "get_node_load_info")
node_group.command("service-package-list",
"get_deployed_service_package_info_list")
node_group.command("service-package",
"get_deployed_service_package_info_list_by_name")
node_group.command("service-type-list",
"get_deployed_service_type_info_list")
node_group.command("service-type",
"get_deployed_service_type_info_by_name")
node_group.command("code-package",
"get_deployed_code_package_info_list")

# Docker Compose commands
with sg.group("sf compose") as compose_group:
compose_group.custom_command("create", "sf_create_compose_application")
compose_group.command("status", "get_compose_application_status")
compose_group.command("list", "get_compose_application_status_list")
compose_group.command("remove", "remove_compose_application")

# Chaos test commands
with sg.group("sf chaos") as chaos_group:
chaos_group.custom_command("start", "sf_start_chaos")
Loading

0 comments on commit 02e97a9

Please sign in to comment.