Пример #1
0
    def create(cls,
               name,
               neighbor_as,
               neighbor_ip,
               neighbor_port=179,
               comment=None):
        """
        Create an external BGP Peer. 

        :param str name: name of peer
        :param str,AutonomousSystem neighbor_as_ref: AutonomousSystem
            element or href. 
        :param str neighbor_ip: ip address of BGP peer
        :param int neighbor_port: port for BGP, default 179.
        :raises CreateElementFailed: failed creating
        :return: instance with meta
        :rtype: ExternalBGPPeer
        """
        json = {
            'name': name,
            'neighbor_ip': neighbor_ip,
            'neighbor_port': neighbor_port,
            'comment': comment
        }

        neighbor_as_ref = element_resolver(neighbor_as)
        json.update(neighbor_as=neighbor_as_ref)

        return ElementCreator(cls, json)
Пример #2
0
    def create(cls, name, mode="active", connectivity_group=1, comment=None):
        """
        Create a connection type for an VPN endpoint.
        ::

            ConnectionType.create(name='mygroup', mode='standby')

        :param str name: name of connection type
        :param str mode: mode of connection type, valid options active, standby,
            aggregate
        :param int connectivity_group: integer useed to group multiple connection types
            into a single monitoring group (default: 1)
        :param str comment: optional comment
        :raises CreateElementFailed: reason for failure
        :rtype: ConnectionType
        """
        return ElementCreator(
            cls,
            json={
                "name": name,
                "mode": mode,
                "comment": comment,
                "connectivity_group": connectivity_group,
            },
        )
Пример #3
0
    def create(cls,
               name,
               address,
               proxy_port=8080,
               username=None,
               password=None,
               secondary=None,
               comment=None):
        """
        Create a new HTTP Proxy service. Proxy must define at least
        one primary address but can optionally also define a list
        of secondary addresses.
        
        :param str name: Name of the proxy element
        :param str address: Primary address for proxy
        :param int proxy_port: proxy port (default: 8080)
        :param str username: optional username for authentication (default: None)
        :param str password: password for username if defined (default: None)
        :param str comment: optional comment
        :param list secondary: secondary list of proxy server addresses
        :raises CreateElementFailed: Failed to create the proxy element
        :rtype: HttpProxy
        """
        json = {
            'name': name,
            'address': address,
            'comment': comment,
            'http_proxy_port': proxy_port,
            'http_proxy_username': username if username else '',
            'http_proxy_password': password if password else '',
            'secondary': secondary if secondary else []
        }

        return ElementCreator(cls, json)
Пример #4
0
    def create(cls, name, comment=None, **ciphers):
        """
        Create a new TLSCryptographySuite. The ciphers kwargs should
        be a dict with the cipher suite string as key and boolean value
        to indicate if this cipher should be enabled.
        To obtain the valid cipher suite string name, use the following
        method::

            cipher_strings = TLSCryptographySuite.ciphers()

        Then to create a custom cipher suite, provide the ciphers as a
        dict of kwargs. In this example, create a TLS Crypto Suite that
        only enables AES 256 bit ciphers::

            only256 = dict(((cipher, True) for cipher in TLSCryptographySuite.ciphers()
                if 'aes_256' in cipher))

            mytls = TLSCryptographySuite.create(name='mytls', **only256)

        :param str name: name of this TLS Crypto suite
        :param dict ciphers: dict of ciphers with cipher string as key and
            bool as value, True enables the cipher
        :raises CreateElementFailed: failed to create element with reason
        :rtype: TLSCryptographySuite
        """
        json = {
            "name": name,
            "comment": comment,
            "tls_cryptography_suites": ciphers
        }

        return ElementCreator(cls, json)
Пример #5
0
    def create(self,
               name,
               address=None,
               enabled=True,
               ipsec_vpn=True,
               nat_t=False,
               force_nat_t=False,
               dynamic=False,
               ike_phase1_id_type=None,
               ike_phase1_id_value=None,
               connection_type_ref=None,
               **kw):
        """
        Create an test_external endpoint. Define common settings for that
        specify the address, enabled, nat_t, name, etc. You can also omit
        the IP address if the endpoint is dynamic. In that case, you must
        also specify the ike_phase1 settings.

        :param str name: name of test_external endpoint
        :param str address: address of remote host
        :param bool enabled: True|False (default: True)
        :param bool ipsec_vpn: True|False (default: True)
        :param bool nat_t: True|False (default: False)
        :param bool force_nat_t: True|False (default: False)
        :param bool dynamic: is a dynamic VPN (default: False)
        :param int ike_phase1_id_type: If using a dynamic endpoint, you must
            set this value. Valid options: 0=DNS name, 1=Email, 2=DN, 3=IP Address
        :param str ike_phase1_id_value: value of ike_phase1_id. Required if
            ike_phase1_id_type and dynamic set.
        :param ConnectionType connection_type_ref: SMC>=6.5 setting. Specifies the
            mode for this endpoint; i.e. Active, Aggregate, Standby. (Default: Active)
        :raises CreateElementFailed: create element with reason
        :return: newly created element
        :rtype: ExternalEndpoint
        """
        json = {
            "name": name,
            "address": address,
            "dynamic": dynamic,
            "enabled": enabled,
            "nat_t": nat_t,
            "force_nat_t": force_nat_t,
            "ipsec_vpn": ipsec_vpn,
        }

        json.update(kw)
        if dynamic:
            json.pop("address", None)

        if ike_phase1_id_value:
            json.update(ike_phase1_id_value=ike_phase1_id_value)

        if ike_phase1_id_type is not None:
            json.update(ike_phase1_id_type=ike_phase1_id_type)

        json.update(connection_type_ref=element_resolver(
            connection_type_ref)) if connection_type_ref else json.update(
                connection_type_ref=element_default(ConnectionType, "Active"))

        return ElementCreator(self.__class__, href=self.href, json=json)
Пример #6
0
    def create(cls,
               name,
               engines,
               include_core_files=False,
               include_slapcat_output=False,
               comment=None):
        """
        Create an sginfo task. 
        
        :param str name: name of task
        :param engines: list of engines to apply the sginfo task
        :type engines: list(Engine)
        :param bool include_core_files: include core files in the
            sginfo backup (default: False)
        :param bool include_slapcat_output: include output from a
            slapcat command in output (default: False)
        :raises ElementNotFound: engine not found
        :raises CreateElementFailed: create the task failed
        :return: the task
        :rtype: SGInfoTask
        """
        json = {
            'name': name,
            'comment': comment,
            'resources': [engine.href for engine in engines],
            'include_core_files': include_core_files,
            'include_slapcat_output': include_slapcat_output
        }

        return ElementCreator(cls, json)
Пример #7
0
    def create(cls, name, vss_def=None):
        """
        Create a VSS Container. This maps to the Service Manager
        within NSX.

        vss_def is optional and has the following definition:

            {"isc_ovf_appliance_model": 'virtual',
             "isc_ovf_appliance_version": '',
             "isc_ip_address": '192.168.4.84', # IP of manager, i.e. OSC
             "isc_vss_id": '',
             "isc_virtual_connector_name": 'smc-python'}

        :param str name: name of container
        :param dict vss_def: dict of optional settings
        :raises CreateElementFailed: failed creating with reason
        :rtype: VSSContainer
        """
        vss_def = {} if vss_def is None else vss_def
        json = {
            'master_type': 'dcl2fw',
            'name': name,
            'vss_isc': vss_def
        }
        return ElementCreator(cls, json)
Пример #8
0
    def create(cls,
               name,
               ne_ref=None,
               operator='exclusion',
               sub_expression=None,
               comment=None):
        """
        Create the expression

        :param str name: name of expression
        :param list ne_ref: network element references for expression
        :param str operator: 'exclusion' (negation), 'union', 'intersection'
               (default: exclusion)
        :param dict sub_expression: sub expression used
        :param str comment: optional comment
        :raises CreateElementFailed: element creation failed with reason
        :return: instance with meta
        :rtype: Expression
        """
        sub_expression = [] if sub_expression is None else [sub_expression]
        json = {
            'name': name,
            'operator': operator,
            'ne_ref': ne_ref,
            'sub_expression': sub_expression,
            'comment': comment
        }

        return ElementCreator(cls, json)
Пример #9
0
    def create(cls,
               name,
               domain_settings_ref,
               external_distance=110,
               inter_distance=110,
               intra_distance=110,
               redistribution_entry=None):
        """
        Create an OSPFProfile
        
        :param str name: name of profile
        :param str domain_settings_ref: linked OSPFDomainSetting href
        :param int external_distance: route metric (E1-E2)
        :param int inter_distance: routes learned from different areas (O IA)
        :param int intra_distance: routes learned from same area (O)
        :param list redistribution_entry:
        :return: str href: href location of new element
        :raises: :py:class:`smc.api.exceptions.CreateElementFailed`
        """
        cls.json = {
            'name': name,
            'domain_settings_ref': domain_settings_ref,
            'external_distance': external_distance,
            'inter_distance': inter_distance,
            'intra_distance': intra_distance,
            'redistribution_entry': redistribution_entry
        }

        return ElementCreator(cls)
Пример #10
0
    def create(cls,
               name,
               user=None,
               network_element=None,
               domain_name=None,
               zone=None,
               executable=None):
        """
        Create a match expression

        :param str name: name of match expression
        :param str user: name of user or user group
        :param Element network_element: valid network element type, i.e. host, network, etc
        :param DomainName domain_name: domain name network element
        :param Zone zone: zone to use
        :param str executable: name of executable or group
        :raises ElementNotFound: specified object does not exist
        :return: instance with meta
        :rtype: MatchExpression
        """
        ref_list = []
        if user:
            pass
        if network_element:
            ref_list.append(network_element.href)
        if domain_name:
            ref_list.append(domain_name.href)
        if zone:
            ref_list.append(zone.href)
        if executable:
            pass

        json = {'name': name, 'ref': ref_list}

        return ElementCreator(cls, json)
Пример #11
0
    def create(cls,
               name,
               address=None,
               ipv6_address=None,
               secondary=None,
               comment=None):
        """
        Create the router element

        :param str name: Name of element
        :param str address: ip address of host object (optional if ipv6)
        :param str ipv6_address: ipv6 address (optional if ipv4)
        :param list secondary: secondary ip address (optional)
        :param str comment: comment (optional)
        :raises CreateElementFailed: element creation failed with reason
        :return: instance with meta
        :rtype: Router
        
        .. note:: either ipv4 or ipv6 address is required
        """
        address = address if address else None
        ipv6_address = ipv6_address if ipv6_address else None
        secondary = [] if secondary is None else secondary
        json = {
            'name': name,
            'address': address,
            'ipv6_address': ipv6_address,
            'secondary': secondary,
            'comment': comment
        }

        return ElementCreator(cls, json)
Пример #12
0
    def create(cls,
               name,
               snmp_monitoring_contact=None,
               snmp_monitoring_listening_port=161,
               snmp_version='v3',
               comment=None):

        json = {
            'boot': False,
            'go_offline': False,
            'go_online': False,
            'hardware_alerts': False,
            'name': name,
            'policy_applied': False,
            'shutdown': False,
            'snmp_monitoring_contact': snmp_monitoring_contact,
            'snmp_monitoring_listening_port': snmp_monitoring_listening_port,
            'snmp_monitoring_user_name': [],
            'snmp_trap_destination': [],
            'snmp_user_name': [],
            'snmp_version': snmp_version,
            'user_login': False
        }

        return ElementCreator(cls, json)
Пример #13
0
    def create(cls, name, abr_type='cisco', auto_cost_bandwidth=100,
               deprecated_algorithm=False, initial_delay=200,
               initial_hold_time=1000, max_hold_time=10000,
               shutdown_max_metric_lsa=0, startup_max_metric_lsa=0):
        """
        Create custom Domain Settings

        Domain settings are referenced by an OSPFProfile

        :param str name: name of custom domain settings
        :param str abr_type: cisco|shortcut|standard
        :param int auto_cost_bandwidth: Mbits/s
        :param bool deprecated_algorithm: RFC 1518 compatibility
        :param int initial_delay: in milliseconds
        :param int initial_hold_type: in milliseconds
        :param int max_hold_time: in milliseconds
        :param int shutdown_max_metric_lsa: in seconds
        :param int startup_max_metric_lsa: in seconds
        :raises CreateElementFailed: create failed with reason
        :return: instance with meta
        :rtype: OSPFDomainSetting
        """
        json = {'name': name,
                'abr_type': abr_type,
                'auto_cost_bandwidth': auto_cost_bandwidth,
                'deprecated_algorithm': deprecated_algorithm,
                'initial_delay': initial_delay,
                'initial_hold_time': initial_hold_time,
                'max_hold_time': max_hold_time,
                'shutdown_max_metric_lsa': shutdown_max_metric_lsa,
                'startup_max_metric_lsa': startup_max_metric_lsa}

        return ElementCreator(cls, json)
Пример #14
0
    def create(cls,
               name,
               md5_password=None,
               connect_retry=120,
               session_hold_timer=180,
               session_keep_alive=60):
        """
        Create a new BGP Connection Profile.

        :param str name: name of profile
        :param str md5_password: optional md5 password
        :param int connect_retry: The connect retry timer, in seconds
        :param int session_hold_timer: The session hold timer, in seconds
        :param int session_keep_alive: The session keep alive timer, in seconds
        :raises CreateElementFailed: failed creating profile
        :return: instance with meta
        :rtype: BGPConnectionProfile
        """
        json = {
            'name': name,
            'connect': connect_retry,
            'session_hold_timer': session_hold_timer,
            'session_keep_alive': session_keep_alive
        }

        if md5_password:
            json.update(md5_password=md5_password)

        return ElementCreator(cls, json)
Пример #15
0
    def create(cls,
               name,
               nat=False,
               mobile_vpn_toplogy_mode=None,
               vpn_profile=None):
        """
        Create a new policy based VPN

        :param name: name of vpn policy
        :param bool nat: whether to apply NAT to the VPN (default False)
        :param mobile_vpn_toplogy_mode: whether to allow remote vpn
        :param VPNProfile vpn_profile: reference to VPN profile, or uses default
        :rtype: PolicyVPN
        """
        vpn_profile = vpn_profile if vpn_profile else VPNProfile('VPN-A Suite')

        json = {
            'mobile_vpn_topology_mode': mobile_vpn_toplogy_mode,
            'name': name,
            'nat': nat,
            'vpn_profile': vpn_profile.href
        }

        try:
            return ElementCreator(cls, json)
        except CreateElementFailed as err:
            raise CreatePolicyFailed(err)
    def create(cls, name, master_engines, comment=None, **kwargs):
        """
        Create a refresh task for master engines.

        :param str name: name of task
        :param master_engines: list of master engines for this task
        :type master_engines: list(MasterEngine)
        :param str comment: optional comment
        :param kwargs: to support new attributes like preserve_connections, snapshot_creation.
        :raises CreateElementFailed: failed to create the task, i.e. no
            valid engines provided
        :return: the task
        :rtype: RefreshMasterEnginePolicyTask
        """
        json = {
            "name":
            name,
            "comment":
            comment,
            "resources": [
                eng.href for eng in master_engines
                if isinstance(eng, MasterEngine)
            ],
        }
        for k, v in kwargs.items():
            json.update({k: v})

        return ElementCreator(cls, json)
Пример #17
0
    def create(cls, name, engines, policy=None, comment=None, **kwargs):
        """
        Create a new validate policy task.
        If a policy is not specified, the engines existing policy will
        be validated. Override default validation settings as kwargs.
        
        :param str name: name of task
        :param engines: list of engines to validate
        :type engines: list(Engine)
        :param Policy policy: policy to validate. Uses the engines assigned
            policy if none specified.
        :param kwargs: see :func:`~policy_validation_settings` for keyword
            arguments and default values.
        :raises ElementNotFound: engine or policy specified does not exist
        :raises CreateElementFailed: failure to create the task
        :return: the task
        :rtype: ValidatePolicyTask
        """
        json = {
            'name': name,
            'resources': [eng.href for eng in engines],
            'policy': policy.href if policy is not None else policy,
            'comment': comment
        }

        if kwargs:
            json.update(policy_validation_settings(**kwargs))

        return ElementCreator(cls, json)
Пример #18
0
    def create(cls, name, address=None, ipv6_address=None, secondary=None, comment=None):
        """
        Create the host element

        :param str name: Name of element
        :param str address: ipv4 address of host object (optional if ipv6)
        :param str ipv6_address: ipv6 address (optional if ipv4)
        :param list secondary: secondary ip addresses (optional)
        :param str comment: comment (optional)
        :raises CreateElementFailed: element creation failed with reason
        :return: instance with meta
        :rtype: Host

        .. note:: Either ipv4 or ipv6 address is required
        """
        address = address if address else None
        ipv6_address = ipv6_address if ipv6_address else None
        secondaries = [] if secondary is None else secondary
        json = {
            "name": name,
            "address": address,
            "ipv6_address": ipv6_address,
            "secondary": secondaries,
            "comment": comment,
        }

        return ElementCreator(cls, json)
Пример #19
0
    def add_context(self, isc_name, isc_policy_id, isc_traffic_tag):
        """
        Create the VSS Context within the VSSContainer

        :param str isc_name: ISC name, possibly append policy name??
        :param str isc_policy_id: Policy ID in SMC (the 'key' attribute)
        :param str isc_traffic_tag: NSX groupId (serviceprofile-145)
        :raises CreateElementFailed: failed to create
        :return: VSSContext
        """
        if 'add_context' in self.data.links: # SMC >=6.5
            element = ElementCreator(
                VSSContext,
                href=self.get_relation('add_context'),
                json = {
                    'name': isc_name,
                    'vc_isc': {
                        'isc_name': isc_name,
                        'isc_policy_id': isc_policy_id,
                        'isc_traffic_tag': isc_traffic_tag
                    }
                })
        else: # SMC < 6.5
            element = VSSContext.create(
                isc_name=isc_name,
                isc_policy_id=isc_policy_id,
                isc_traffic_tag=isc_traffic_tag,
                vss_container=self)
        
        # Delete cache since the virtualResources node is attached to
        # the engine json
        self._del_cache()
        return element
Пример #20
0
    def create(cls, name, iplist=None, comment=None):
        """
        Create an IP List. It is also possible to add entries by supplying
        a list of IPs/networks, although this is optional. You can also
        use upload/download to add to the iplist.

        :param str name: name of ip list
        :param list iplist: list of ipaddress
        :param str comment: optional comment
        :raises CreateElementFailed: element creation failed with reason
        :return: instance with meta
        :rtype: IPList
        """
        json = {"name": name, "comment": comment}
        result = ElementCreator(cls, json)
        if result and iplist is not None:
            element = IPList(name)

            element.make_request(
                CreateElementFailed,
                method="create",
                resource="ip_address_list",
                json={"ip": iplist},
            )

        return result
Пример #21
0
    def create(cls, name, isc_id, vss_container, comment=None):
        """
        Create a new security group.
        
        Find a security group::
        
            SecurityGroup.objects.filter(name)
        
        .. note:: The isc_id (securitygroup-10, etc) represents the
            internal NSX reference for the Security Composer group.
            This is placed in the comment field which makes it
            a searchable field using search collections

        :param str name: name of group
        :param str isc_id: NSX Security Group objectId
        :param str isc_name: NSX Security Group name
        :param VSSContainer vss_container: VSS Container to add the
            security group to.
        :param str comment: comment, making this searchable
        :raises: CreateElementFailed
        :return SecurityGroup
        """
        return ElementCreator(cls,
            href=vss_container.get_relation('security_groups'),
            json = {
                'name': name,
                'isc_name': name,
                'isc_id': isc_id,
                'comment': comment or isc_id
            })
Пример #22
0
 def create(cls, name, multilink_members, multilink_method='rtt', retries=2,
            timeout=3600, comment=None):
     """
     Create a new multilink configuration. Multilink requires at least
     one netlink for operation, although 2 or more are recommeneded.
     
     :param str name: name of multilink
     :param list multilink_members: the output of calling
         :func:`.multilink_member` to retrieve the proper formatting for
         this sub element.
     :param str multilink_method: 'rtt' or 'ratio'. If ratio is used, each
         netlink must have a probe IP address configured and also have
         input and output speed configured (default: 'rtt')
     :param int retries: number of keep alive retries before a destination
         link is considered unavailable (default: 2)
     :param int timeout: timeout between retries (default: 3600 seconds)
     :param str comment: comment for multilink (optional)
     :raises CreateElementFailed: failure to create multilink
     :rtype: Multilink
     """
     json = {'name': name,
             'comment': comment,
             'retries': retries,
             'timeout': timeout,
             'multilink_member': multilink_members,
             'multilink_method': multilink_method}
     
     return ElementCreator(cls, json)
Пример #23
0
    def create(cls, name, certificate):
        """
        Create a TLS CA. The certificate must be compatible with OpenSSL
        and be in PEM format. The certificate can be either a file with
        the Root CA, or a raw string starting with BEGIN CERTIFICATE, etc.
        When creating a TLS CA, you must also import the CA certificate. Once
        the CA is created, it is possible to import a different certificate to
        map to the CA if necessary.

        :param str name: name of root CA
        :param str,file certificate: The root CA contents
        :raises CreateElementFailed: failed to create the root CA
        :raises ValueError: if loading from file and no certificates present
        :raises IOError: cannot find specified file for certificate
        :rtype: TLSCertificateAuthority
        """
        json = {
            "name":
            name,
            "certificate":
            certificate if pem_as_string(certificate) else
            load_cert_chain(certificate)[0][1].decode("utf-8"),
        }

        return ElementCreator(cls, json)
Пример #24
0
    def create(cls, name, port=179, external_distance=20, internal_distance=200,
               local_distance=200, subnet_distance=None):
        """
        Create a custom BGP Profile

        :param str name: name of profile
        :param int port: port for BGP process
        :param int external_distance: external administrative distance; (1-255)
        :param int internal_distance: internal administrative distance (1-255)
        :param int local_distance: local administrative distance (aggregation) (1-255)
        :param list subnet_distance: configure specific subnet's with respective distances
        :type tuple subnet_distance: (subnet element(Network), distance(int))
        :raises CreateElementFailed: reason for failure
        :return: instance with meta
        :rtype: BGPProfile
        """
        json = {'name': name,
                'external': external_distance,
                'internal': internal_distance,
                'local': local_distance,
                'port': port}

        if subnet_distance:
            d = [{'distance': distance, 'subnet': subnet.href}
                 for subnet, distance in subnet_distance]
            json.update(distance_entry=d)

        return ElementCreator(cls, json)
Пример #25
0
    def create(cls, name, comment=None, **kw):
        """
        Create a VPN Profile. There are a variety of kwargs that can
        can be and also retrieved about a VPN Profile. Keyword parameters
        are specified below. To access a valid keyword, use the standard
        dot notation.

        To validate supported keyword attributes for a VPN Profile, consult
        the native SMC API docs for your version of SMC. You can also optionally
        print the element contents after retrieving the element and use
        `update` to modify the element.

        For example::

            vpn = VPNProfile.create(name='mySecureVPN', comment='test comment')
            pprint(vars(vpn.data))

        Then once identifying the attribute, update the relevant top level
        attribute values::

            vpn.update(sa_life_time=128000, tunnel_life_time_seconds=57600)

        :param str name: Name of profile
        :param str comment: optional comment
        :raises CreateElementFailed: failed creating element with reason
        :rtype: VPNProfile
        """
        kw.update(name=name, comment=comment)
        return ElementCreator(cls, json=kw)
Пример #26
0
    def create(
        cls,
        name,
        snmp_users=[],
        trap_destinations=[],
        snmp_monitoring_contact=None,
        snmp_monitoring_listening_port=161,
        snmp_version="v3",
        monitoring_user_names=[],
        trap_user_names=[],
        comment=None,
    ):

        json = {
            "boot": False,
            "go_offline": False,
            "go_online": False,
            "hardware_alerts": False,
            "name": name,
            "policy_applied": False,
            "shutdown": False,
            "snmp_monitoring_contact": snmp_monitoring_contact,
            "snmp_monitoring_listening_port": snmp_monitoring_listening_port,
            "snmp_monitoring_user_name": monitoring_user_names,
            "snmp_trap_destination": trap_destinations,
            "snmp_user_name": snmp_users,
            "snmp_version": snmp_version,
            "user_login": False,
        }

        return ElementCreator(cls, json)
Пример #27
0
    def create(cls, name, template='Firewall Inspection Template'):
        """
        Create Firewall Policy. Template policy is required for the
        policy. The template parameter should be the name of the
        firewall template.

        This policy will then inherit the Inspection and File Filtering
        policy from the specified template.

        :param str name: name of policy
        :param str template: name of the NGFW engine template to base policy on
        :raises LoadPolicyFailed: Cannot load the policy after creation
        :raises CreatePolicyFailed: policy creation failed with message
        :return: FirewallPolicy

        To use after successful creation, reference the policy to obtain
        context::

            FirewallPolicy('newpolicy')
        """
        try:
            if cls.typeof == 'fw_template_policy' and template is None:
                fw_template = None
            else:
                fw_template = FirewallTemplatePolicy(template).href
        except ElementNotFound:
            raise LoadPolicyFailed(
                'Cannot find specified firewall template: {}'.format(template))
        json = {
            'name': name,
            'template': fw_template}
        try:
            return ElementCreator(cls, json)
        except CreateElementFailed as err:
            raise CreatePolicyFailed(err)
Пример #28
0
    def create(cls, name, vss_container, vss_node_def, comment=None):
        """
        Create VSS node. This is the engines dvFilter management
        interface within the NSX agent.

        .. seealso:: `~.isc_settings` for documentation on the
            vss_node_def dict

        :param str name: name of node
        :param VSSContainer vss_container: container to nest this node
        :param dict vss_node_def: node definition settings
        :raises CreateElementFailed: created failed with reason
        :rtype: VSSContainerNode
        """
        element = ElementCreator(
            cls,
            href=vss_container.get_relation("vss_container_node"),
            json={
                "name": name,
                "vss_node_isc": vss_node_def,
                "comment": comment
            },
        )
        vss_container._del_cache()  # Removes references to linked container
        return element
Пример #29
0
    def create(cls,
               name,
               address,
               time_to_live=20,
               update_interval=10,
               secondary=None,
               comment=None):
        """
        Create a DNS Server element.
        
        :param str name: Name of DNS Server
        :param str address: IP address for DNS Server element
        :param int time_to_live: Defines how long a DNS entry can be cached
            before querying the DNS server again (default: 20)
        :param int update_interval: Defines how often the DNS entries can be
            updated to the DNS server if the link status changes constantly
            (default: 10)
        :param list secondary: a secondary set of IP address for this element
        :raises CreateElementFailed: Failed to create with reason
        :rtype: DNSServer
        """
        json = {
            'name': name,
            'address': address,
            'comment': comment,
            'time_to_live': time_to_live,
            'update_interval': update_interval,
            'secondary': secondary if secondary else []
        }

        return ElementCreator(cls, json)
Пример #30
0
    def create(cls,
               name,
               min_dst_port,
               max_dst_port=None,
               min_src_port=None,
               max_src_port=None,
               comment=None):
        """
        Create the UDP Service

        :param str name: name of udp service
        :param int min_dst_port: minimum destination port value
        :param int max_dst_port: maximum destination port value
        :param int min_src_port: minimum source port value
        :param int max_src_port: maximum source port value
        :raises CreateElementFailed: failure creating element with reason
        :return: instance with meta
        :rtype: UDPService
        """
        max_dst_port = max_dst_port if max_dst_port is not None else ''
        json = {
            'name': name,
            'min_dst_port': min_dst_port,
            'max_dst_port': max_dst_port,
            'min_src_port': min_src_port,
            'max_src_port': max_src_port,
            'comment': comment
        }

        return ElementCreator(cls, json)