Example #1
0
def destroy(namespace):

    resource_client = client()
    if resource_client.resource_groups.check_existence(
            namespace.resource_group):
        poller = resource_client.resource_groups.delete(  # AzureOperationPoller
            namespace.resource_group)
        session.login()
        try:
            Layer3Firewall(namespace.resource_group).delete()
        except (ElementNotFound, DeleteElementFailed) as e:
            logger.error('Problem deleting engine: {}'.format(e))
        session.logout()
        return poller.result(timeout=10)
        for stats in node.hardware_status.filesystem:
            print("hardware status.filesystem={}".format(stats))
        for stats in node.hardware_status.logging_subsystem:
            print("hardware status.logging_subsystem={}".format(stats))
        for stats in node.hardware_status.sandbox_subsystem:
            print("hardware status.sandbox_subsystem={}".format(stats))
        for stats in node.interface_status:
            print("interface status={}".format(stats))
        print("health=>Master Node={}".format(node.health.master_node))
        print("health=>Node status={}".format(node.health.engine_node_status))
        print("health=>dyn up={}".format(node.health.dyn_up))
        # print all attributes
        print("health=>{}".format(node.health))

    single_fw = Layer3Firewall("Plano")
    print("Check nodes status for {}...".format(single_fw))

    for node in single_fw.nodes:

        # Wait for node to be Online
        waiter = NodeStatusWaiter(node, 'Online', max_wait=3)
        while not waiter.done():
            status = waiter.result(5)
            print("Status after 5 sec wait: {}".format(status))
        print("Node:{} is {}".format(node, status))

        assert status is not None, "Node {} can't be contacted".format(node)

        # should be None
        print("health=>Master Node={}".format(node.health.master_node))
Example #3
0
def create(namespace):

    if namespace.template_path:
        with open(namespace.template_path, 'r') as template_file_fd:
            template = json.load(template_file_fd)

    pub_ssh_key_path = os.path.expanduser(
        '~/.ssh/id_rsa.pub')  # the path to rsa public key file

    with open(pub_ssh_key_path, 'r') as pub_ssh_file_fd:
        pub_ssh_key = pub_ssh_file_fd.read()

    session.login()
    if namespace.force_remove:
        try:
            Layer3Firewall(namespace.resource_group).delete()
        except ElementNotFound:
            pass

    engineCfg = provision_stonesoft(name=namespace.resource_group,
                                    vnet=None,
                                    location=namespace.engine_location)

    parameters = {
        'engineCfg': engineCfg,
        'engineUsername': namespace.engine_username,
        'sshKey': pub_ssh_key
    }
    parameters = {k: {'value': v} for k, v in parameters.items()}

    resource_client = client()

    resource_group_params = {
        'location': namespace.location_id,
        'tags': {
            'stonesoft': namespace.tag_value
        }
    }

    try:
        resource_client.resource_groups.create_or_update(
            namespace.resource_group, resource_group_params)

        deployment_properties = {
            'mode': DeploymentMode.incremental,
            'parameters': parameters,
            'template': None,
            'template_link': None
        }

        if namespace.template_path:
            deployment_properties.update(template=template)
        else:
            deployment_properties.update(
                template_link=TemplateLink(namespace.template_link))

        deployment_async_operation = resource_client.deployments.create_or_update(
            resource_group_name=namespace.resource_group,
            deployment_name=namespace.deployment_name,
            properties=deployment_properties)  # AzureOperationPoller

        initial_result = deployment_async_operation.result(timeout=30)

        logger.info('Starting Azure deployment; correlation id: %s',
                    initial_result.properties.correlation_id)

        logger.info('Azure provisioning state: %s',
                    initial_result.properties.provisioning_state)

        while not deployment_async_operation.done():
            deployment_async_operation.wait(timeout=30)

            status = resource_client.deployments.get(
                namespace.resource_group,
                deployment_name=namespace.deployment_name)

            logger.info('Azure provisioning state: %s',
                        status.properties.provisioning_state)

        result = deployment_async_operation.result()

        elapsed_time = result.properties.timestamp - initial_result.properties.timestamp
        logger.info('Elapsed Time: %s (seconds)', elapsed_time.total_seconds())

        if namespace.engine_policy:
            provision_stonesoft_policy(namespace.engine_policy)

        for k, v in result.properties.outputs.items():
            logger.info('{} -> {}'.format(k, v.get('value')))

    except CloudError:
        Layer3Firewall(namespace.resource_group).delete()
        raise
    finally:
        session.logout()
Example #4
0
from smc.elements.service import TCPService
from smc.policy.layer3 import FirewallPolicy
from smc_info import *

logging.getLogger()

if __name__ == "__main__":
    session.login(url=SMC_URL,
                  api_key=API_KEY,
                  verify=False,
                  timeout=120,
                  api_version=API_VERSION)
    print("session OK")

try:
    plano = Layer3Firewall("Plano")

    # check for pending changes
    print("check for pending changes..")
    nb_changes_before = 0
    for changes in plano.pending_changes.all():
        print(changes, changes.resolve_element)
        nb_changes_before += 1
    print("changes found:{}".format(nb_changes_before))

    # update policy used by plano
    print("Update policy..")
    policy = FirewallPolicy(plano.installed_policy)
    new_rule = policy.fw_ipv4_access_rules.create(
        name="newrule",
        sources="any",