def creation_validation(vca_client, **kwargs):
    floatingip = get_mandatory(ctx.node.properties, 'floatingip')
    edge_gateway = get_mandatory(floatingip, 'edge_gateway')
    gateway = get_gateway(vca_client, edge_gateway)
    service_type = get_vcloud_config().get('service_type')
    public_ip = floatingip.get(PUBLIC_IP)
    if public_ip:
        check_ip(public_ip)
        CheckAssignedExternalIp(public_ip, gateway)
    else:
        if is_subscription(service_type):
            getFreeIP(gateway)
 def test_getFreeIP(self):
     """
         check list returned list of free ip
     """
     # exist free ip
     gateway = self.generate_gateway()
     gateway.get_public_ips = mock.MagicMock(
         return_value=['10.18.1.1', '10.18.1.2'])
     rule_inlist = self.generate_nat_rule('DNAT', '10.18.1.1', 'any',
                                          'internal', '11', 'TCP')
     gateway.get_nat_rules = mock.MagicMock(return_value=[rule_inlist])
     self.assertEqual(network_plugin.getFreeIP(gateway), '10.18.1.2')
     # no free ips
     gateway.get_public_ips = mock.MagicMock(return_value=['10.18.1.1'])
     with self.assertRaises(cfy_exc.NonRecoverableError):
         network_plugin.getFreeIP(gateway)
def creation_validation(vca_client, **kwargs):
    nat = get_mandatory(ctx.node.properties, 'nat')
    rules = get_mandatory(ctx.node.properties, 'rules')
    gateway = get_gateway(vca_client, get_mandatory(nat, 'edge_gateway'))
    service_type = get_vcloud_config().get('service_type')
    public_ip = nat.get(PUBLIC_IP)
    if public_ip:
        check_ip(public_ip)
        CheckAssignedExternalIp(public_ip, gateway)
    else:
        if isSubscription(service_type):
            getFreeIP(gateway)
    check_protocol(rules.get('protocol', "any"))
    original_port = rules.get('original_port')
    if original_port and not isinstance(original_port, int):
        raise cfy_exc.NonRecoverableError("Parameter 'original_port' must be integer")
    translated_port = rules.get('translated_port')
    if translated_port and not isinstance(translated_port, int):
        raise cfy_exc.NonRecoverableError("Parameter 'translated_port' must be integer")
 def test_getFreeIP(self):
     # exist free ip
     gateway = self.generate_gateway()
     gateway.get_public_ips = mock.MagicMock(return_value=[
         '10.18.1.1', '10.18.1.2'
     ])
     rule_inlist = self.generate_nat_rule(
         'DNAT', '10.18.1.1', 'any', 'internal', '11', 'TCP'
     )
     gateway.get_nat_rules = mock.MagicMock(return_value=[rule_inlist])
     self.assertEqual(
         network_plugin.getFreeIP(gateway),
         '10.18.1.2'
     )
     # no free ips
     gateway.get_public_ips = mock.MagicMock(return_value=[
         '10.18.1.1'
     ])
     with self.assertRaises(cfy_exc.NonRecoverableError):
         network_plugin.getFreeIP(gateway)
def creation_validation(vca_client, **kwargs):
    nat = get_mandatory(ctx.node.properties, 'nat')
    rules = get_mandatory(ctx.node.properties, 'rules')
    gateway = get_gateway(vca_client, get_mandatory(nat, 'edge_gateway'))
    service_type = get_vcloud_config().get('service_type')
    public_ip = nat.get(PUBLIC_IP)
    if public_ip:
        check_ip(public_ip)
        CheckAssignedExternalIp(public_ip, gateway)
    else:
        if isSubscription(service_type):
            getFreeIP(gateway)
    check_protocol(rules.get('protocol', "any"))
    original_port = rules.get('original_port')
    if original_port and not isinstance(original_port, int):
        raise cfy_exc.NonRecoverableError(
            "Parameter 'original_port' must be integer")
    translated_port = rules.get('translated_port')
    if translated_port and not isinstance(translated_port, int):
        raise cfy_exc.NonRecoverableError(
            "Parameter 'translated_port' must be integer")
def creation_validation(vca_client, **kwargs):
    """
        validate node context,
        fields from floatingip dict:
        * edge_gateway - mandatory,
        * public_ip - prefered ip for node, can be empty
        fields from vcloud_config:
        * service_type - ondemand, subscription
        also check availability of public ip if set or exist some free
        ip in subscription case
    """
    floatingip = get_mandatory(ctx.node.properties, 'floatingip')
    edge_gateway = get_mandatory(floatingip, 'edge_gateway')
    gateway = get_gateway(vca_client, edge_gateway)
    service_type = get_vcloud_config().get('service_type')
    public_ip = floatingip.get(PUBLIC_IP)
    if public_ip:
        check_ip(public_ip)
        CheckAssignedExternalIp(public_ip, gateway)
    else:
        if is_subscription(service_type):
            getFreeIP(gateway)
def creation_validation(vca_client, **kwargs):
    """
        validate node context,
        fields from floatingip dict:
        * edge_gateway - mandatory,
        * public_ip - prefered ip for node, can be empty
        fields from vcloud_config:
        * service_type - ondemand, subscription
        also check availability of public ip if set or exist some free
        ip in subscription case
    """
    floatingip = get_mandatory(ctx.node.properties, 'floatingip')
    edge_gateway = get_mandatory(floatingip, 'edge_gateway')
    gateway = get_gateway(vca_client, edge_gateway)
    service_type = get_vcloud_config().get('service_type')
    public_ip = floatingip.get(PUBLIC_IP)
    if public_ip:
        check_ip(public_ip)
        CheckAssignedExternalIp(public_ip, gateway)
    else:
        if is_subscription(service_type):
            getFreeIP(gateway)
def creation_validation(vca_client, **kwargs):
    """
        validate nat rules in node properties
    """
    nat = get_mandatory(ctx.node.properties, 'nat')
    gateway = get_gateway(vca_client, get_mandatory(nat, 'edge_gateway'))
    service_type = get_vcloud_config().get('service_type')
    public_ip = nat.get(PUBLIC_IP)
    if public_ip:
        check_ip(public_ip)
    else:
        if is_subscription(service_type):
            getFreeIP(gateway)
    for rule in get_mandatory(ctx.node.properties, 'rules'):
        if rule['type'] == "DNAT":
            utils.check_protocol(rule.get('protocol'))
            original_port = rule.get('original_port')
            if original_port and not isinstance(original_port, int):
                raise cfy_exc.NonRecoverableError(
                    "Parameter 'original_port' must be integer")
            translated_port = rule.get('translated_port')
            if translated_port and not isinstance(translated_port, int):
                raise cfy_exc.NonRecoverableError(
                    "Parameter 'translated_port' must be integer")
def creation_validation(vca_client, **kwargs):
    """
        validate nat rules in node properties
    """
    nat = get_mandatory(ctx.node.properties, 'nat')
    gateway = get_gateway(vca_client, get_mandatory(nat, 'edge_gateway'))
    service_type = get_vcloud_config().get('service_type')
    public_ip = nat.get(PUBLIC_IP)
    if public_ip:
        check_ip(public_ip)
    else:
        if is_subscription(service_type):
            getFreeIP(gateway)
    for rule in get_mandatory(ctx.node.properties, 'rules'):
        if rule['type'] == "DNAT":
            utils.check_protocol(rule.get('protocol'))
            original_port = rule.get('original_port')
            if original_port and not isinstance(original_port, int):
                raise cfy_exc.NonRecoverableError(
                    "Parameter 'original_port' must be integer")
            translated_port = rule.get('translated_port')
            if translated_port and not isinstance(translated_port, int):
                raise cfy_exc.NonRecoverableError(
                    "Parameter 'translated_port' must be integer")