def create(**kwargs): kwargs = common.get_properties_update( 'dynamic_member', "security_group_id", kwargs, target_relationship="cloudify.nsx.relationships.contained_in", target_property="resource_id") validation_rules = { "security_group_id": { "required": True }, # dynamic member definition "dynamic_set": { "required": True } } use_existing, dynamic_member = common.get_properties_and_validate( 'dynamic_member', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) resource_id = nsx_security_group.set_dynamic_member( client_session, dynamic_member['security_group_id'], dynamic_member['dynamic_set']) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % (resource_id))
def create(**kwargs): validation_rules = { "dlr_id": { "required": True }, "relayServer": { "default": {} }, "relayAgents": { "default": {} } } use_existing, relay_dict = common.get_properties_and_validate( 'relay', kwargs, validation_rules ) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) cfy_dlr.update_dhcp_relay( client_session, relay_dict['dlr_id'], relay_dict['relayServer'], relay_dict['relayAgents'] ) resource_id = relay_dict['dlr_id'] ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id)
def create(**kwargs): validation_rules = { "tag_id": { "required": True }, "vm_id": { "required": True } } use_existing, vm_tag = common.get_properties_and_validate( 'vm_tag', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) resource_id = nsx_security_tag.add_tag_vm( client_session, vm_tag['tag_id'], vm_tag['vm_id'], ) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id)
def _create(kwargs, validation_rules): use_existing, neighbour = common.get_properties_and_validate( 'neighbour', kwargs, validation_rules) if use_existing: ctx.logger.info("Used existed, no changes made") return resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) resource_id = cfy_dlr.add_bgp_neighbour( client_session, neighbour['dlr_id'], use_existing, neighbour['ipAddress'], neighbour['remoteAS'], neighbour['weight'], neighbour['holdDownTimer'], neighbour['keepAliveTimer'], neighbour['password'], neighbour.get('protocolAddress'), neighbour.get('forwardingAddress')) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id)
def create(**kwargs): validation_rules = { "dlr_id": { "required": True }, "name": { "required": True }, "ipAddress": { "required": True } } use_existing, prefix = common.get_properties_and_validate( 'prefix', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) if not use_existing: return # credentials client_session = common.nsx_login(kwargs) resource_id = cfy_dlr.add_routing_prefix(client_session, use_existing, prefix['dlr_id'], prefix['name'], prefix['ipAddress']) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id)
def create(**kwargs): validation_rules = { "dlr_id": { "required": True }, "address": { "required": True } } use_existing, gateway = common.get_properties_and_validate( 'gateway', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) result_raw = nsx_router.dlr_set_dgw(client_session, gateway['dlr_id'], gateway['address']) common.check_raw_result(result_raw) ctx.instance.runtime_properties['resource_id'] = gateway['dlr_id'] ctx.logger.info("created %s" % gateway['dlr_id'])
def create(**kwargs): validation_rules = { "security_policy_id": { "required": True }, "security_group_id": { "required": True } } use_existing, policy_group_bind = common.get_properties_and_validate( 'policy_group_bind', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) resource_id = nsx_security_policy.add_policy_group_bind( client_session, policy_group_bind['security_policy_id'], policy_group_bind['security_group_id'], ) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % (resource_id))
def create(**kwargs): validation_rules = { "name": { "required": True }, "description": { "set_none": True }, "precedence": { "type": "string", "required": True }, "parent": { "set_none": True }, "securityGroupBinding": { "set_none": True }, "actionsByCategory": { "set_none": True } } use_existing, policy = common.get_properties_and_validate( 'policy', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) if not resource_id: resource_id, exist_policy = nsx_security_policy.get_policy( client_session, policy['name']) if use_existing and resource_id: ctx.instance.runtime_properties['resource_id'] = resource_id _update_policy(exist_policy) ctx.logger.info("Used existed %s" % resource_id) elif resource_id: raise cfy_exc.NonRecoverableError( "Security policy '%s' already exists" % policy['name']) elif use_existing: raise cfy_exc.NonRecoverableError( "Security policy '%s' does not exist" % policy['name']) if not resource_id: resource_id = nsx_security_policy.add_policy( client_session, policy['name'], policy['description'], policy['precedence'], policy['parent'], policy['securityGroupBinding'], policy['actionsByCategory']) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id)
def create(**kwargs): validation_rules = { "dlr_id": { "required": True }, "areaId": { "required": True }, # must be vnic with uplink "vnic": { "required": True }, "helloInterval": { "default": 10, "type": "string" }, "deadInterval": { "default": 40, "type": "string", }, "priority": { "default": 128, "type": "string" }, "cost": { "set_none": True } } use_existing, interface = common.get_properties_and_validate( 'interface', kwargs, validation_rules ) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) if not use_existing: return # credentials client_session = common.nsx_login(kwargs) resource_id = cfy_dlr.add_esg_ospf_interface( client_session, interface['dlr_id'], interface['areaId'], interface['vnic'], use_existing, interface['helloInterval'], interface['deadInterval'], interface['priority'], interface['cost'] ) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id)
def create(**kwargs): validations_rules = { "esg_id": { "required": True }, "ip_range": { "required": True }, "default_gateway": { "set_none": True }, "subnet_mask": { "set_none": True }, "domain_name": { "set_none": True }, "dns_server_1": { "set_none": True }, "dns_server_2": { "set_none": True }, "lease_time": { "set_none": True }, "auto_dns": { "set_none": True } } use_existing, pool_dict = common.get_properties_and_validate( 'pool', kwargs, validations_rules) if use_existing: ctx.logger.info("Used pre existed!") return resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) resource_id = nsx_dhcp.add_dhcp_pool( client_session, pool_dict['esg_id'], pool_dict['ip_range'], pool_dict['default_gateway'], pool_dict['subnet_mask'], pool_dict['domain_name'], pool_dict['dns_server_1'], pool_dict['dns_server_2'], pool_dict['lease_time'], pool_dict['auto_dns']) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s | %s" % (resource_id, pool_dict['esg_id']))
def create(**kwargs): validation_rules = { "name": { "required": True }, "type": { "required": True, "values": [ 'group', 'policy', 'tag', 'lswitch', 'router' ] }, "scopeId": { "default": "globalroot-0", "required": True } } _, nsx_object = common.get_properties_and_validate( 'nsx_object', kwargs, validation_rules ) # credentials client_session = common.nsx_login(kwargs) if nsx_object['type'] == 'group': resource_id, _ = nsx_security_group.get_group( client_session, nsx_object['scopeId'], nsx_object['name'] ) elif nsx_object['type'] == 'policy': resource_id, _ = nsx_security_policy.get_policy( client_session, nsx_object['name'] ) elif nsx_object['type'] == 'tag': resource_id, _ = nsx_security_tag.get_tag( client_session, nsx_object['name'] ) elif nsx_object['type'] == 'lswitch': resource_id, switch_params = nsx_logical_switch.logical_switch_read( client_session, nsx_object['name'] ) elif nsx_object['type'] == 'router': resource_id, _ = nsx_router.dlr_read( client_session, nsx_object['name'] ) runtime_properties = ctx.instance.runtime_properties runtime_properties['resource_id'] = resource_id runtime_properties['use_external_resource'] = resource_id is not None
def test_get_properties_and_validate(self): """Check nsx_common.get_properties_and_validate func""" self._regen_ctx() self.assertEqual( common.get_properties_and_validate('some_name', {'some_name': { 'somevalue': True, 'not_showed': 'really' }}, {'somevalue': {'type': 'boolean'}}), (False, {'somevalue': True}) )
def create(**kwargs): validation_rules = { "esg_id": { "required": True }, "network": { "required": True }, "next_hop": { "required": True }, "vnic": { "set_none": True, "type": "string" }, "mtu": { "set_none": True, "type": "string" }, "admin_distance": { "set_none": True, "type": "string" }, "description": { "set_none": True } } use_existing, route = common.get_properties_and_validate( 'route', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) resource_id = nsx_esg.esg_route_add(client_session, route['esg_id'], route['network'], route['next_hop'], route['vnic'], route['mtu'], route['admin_distance'], route['description']) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id)
def create(**kwargs): validation_rules = { "name": { "required": True }, "description": { "set_none": True } } use_existing, tag = common.get_properties_and_validate( 'tag', kwargs, validation_rules ) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) if not resource_id: resource_id, _ = nsx_security_tag.get_tag(client_session, tag['name']) if use_existing and resource_id: ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("Used existed %s" % resource_id) elif resource_id: raise cfy_exc.NonRecoverableError( "Security tag '%s' already exists" % tag['name'] ) elif use_existing: raise cfy_exc.NonRecoverableError( "Security tag '%s' does not exist" % tag['name'] ) if not resource_id: resource_id = nsx_security_tag.add_tag( client_session, tag['name'], tag['description'], ) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id)
def create(**kwargs): validation_rules = { "dlr_id": { "required": True }, "areaId": { "required": True }, "type": { "required": True, "values": ["normal", "nssa"] }, "authentication": { "set_none": True, "sub": { "type": { "required": True, "values": ["none", "password", "md5"] }, "value": { "set_none": True, "required": False } } } } use_existing, area = common.get_properties_and_validate( 'area', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) if not use_existing: return # credentials client_session = common.nsx_login(kwargs) resource_id = cfy_dlr.add_esg_ospf_area(client_session, area['dlr_id'], area['areaId'], use_existing, area['type'], area['authentication']) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id)
def create(**kwargs): validation_rules = { "esg_id": { "required": True }, "dgw_ip": { "required": True }, "vnic": { "set_none": True, "type": "string" }, "mtu": { "set_none": True, "type": "string" }, "admin_distance": { "set_none": True, "type": "string" } } use_existing, gateway = common.get_properties_and_validate( 'gateway', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) resource_id = nsx_esg.esg_dgw_set(client_session, gateway['esg_id'], gateway['dgw_ip'], gateway['vnic'], gateway['mtu'], gateway['admin_distance']) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id)
def create(**kwargs): kwargs = common.get_properties_update( 'group_exclude_member', "security_group_id", kwargs, target_relationship="cloudify.nsx.relationships.contained_in", target_property="resource_id" ) validate_rules = { "security_group_id": { "required": True }, # member id "objectId": { "required": True } } use_existing, group_exclude_member = common.get_properties_and_validate( 'group_exclude_member', kwargs, validate_rules ) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) resource_id = nsx_security_group.add_group_exclude_member( client_session, group_exclude_member['security_group_id'], group_exclude_member['objectId'], ) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id)
def create(**kwargs): kwargs = common.get_properties_update( 'policy_section', "security_policy_id", kwargs, target_relationship="cloudify.nsx.relationships.contained_in", target_property="resource_id") validation_rules = { "security_policy_id": { "required": True }, "category": { "required": True }, "action": { "required": True } } use_existing, policy_section = common.get_properties_and_validate( 'policy_section', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) resource_id = nsx_security_policy.add_policy_section( client_session, policy_section['security_policy_id'], policy_section['category'], policy_section['action']) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % (resource_id))
def create(**kwargs): validation_rules = { "scopeId": { "default": "globalroot-0", "required": True }, "name": { "required": True }, "member": { "set_none": True }, "excludeMember": { "set_none": True }, "dynamicMemberDefinition": { "set_none": True } } use_existing, group = common.get_properties_and_validate( 'group', kwargs, validation_rules ) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) if not resource_id: resource_id, _ = nsx_security_group.get_group(client_session, group['scopeId'], group['name']) if use_existing and resource_id: ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("Used existed %s" % resource_id) elif resource_id: raise cfy_exc.NonRecoverableError( "Security group '%s' already exists" % group['name'] ) elif use_existing: raise cfy_exc.NonRecoverableError( "Security group '%s' does not exist" % group['name'] ) if not resource_id: resource_id = nsx_security_group.add_group( client_session, group['scopeId'], group['name'], group['member'], group['excludeMember'], group['dynamicMemberDefinition'] ) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id)
def create(**kwargs): validation_rules = { "neighbour_id": { "required": True }, "action": { "required": True, "values": [ "permit", "deny" ] }, "ipPrefixGe": { "type": "string", "set_none": True }, "ipPrefixLe": { "type": "string", "set_none": True }, "direction": { "required": True, "values": [ "in", "out" ] }, "network": { "required": True } } use_existing, neighbour_filter = common.get_properties_and_validate( 'filter', kwargs, validation_rules ) if use_existing: ctx.logger.info("Used existed, no changes made") return resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) resource_id = cfy_dlr.add_bgp_neighbour_filter( client_session, use_existing, neighbour_filter['neighbour_id'], neighbour_filter['action'], neighbour_filter['ipPrefixGe'], neighbour_filter['ipPrefixLe'], neighbour_filter['direction'], neighbour_filter['network'] ) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id)
def create(**kwargs): validation_rules = { # we need name in any case of usage except predefined 'id' "name": { "required": True, "external_use": True }, "transport_zone": { "required": True, "external_use": False }, "mode": { "required": False, "external_use": False, "set_none": True, "values": ["UNICAST_MODE", "MULTYCAST_MODE", "HYBRID_MODE"] } } use_existing, switch_dict = common.get_properties_and_validate( 'switch', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) # credentials client_session = common.nsx_login(kwargs) switch_params = {} if not resource_id: # no explicit id, validate params ctx.logger.info("checking switch: " + str(switch_dict)) resource_id, switch_params = nsx_logical_switch.logical_switch_read( client_session, switch_dict["name"]) if use_existing: ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("Used existed %s" % resource_id) elif resource_id: raise cfy_exc.NonRecoverableError("Switch '%s' already exists" % switch_dict["name"]) # create new logical switch if not use_existing: switch_mode = switch_dict.get("mode") # nsx does not understand unicode strings ctx.logger.info("creating %s" % switch_dict["name"]) resource_id, _ = nsx_logical_switch.logical_switch_create( client_session, switch_dict["transport_zone"], switch_dict["name"], switch_mode) ctx.logger.info("created %s" % resource_id) switch_params = None ctx.instance.runtime_properties['resource_id'] = resource_id if (not ctx.instance.runtime_properties.get('vsphere_network_id') or not ctx.instance.runtime_properties.get('name')): # read additional info about switch if not switch_params: switch_params = nsx_lswitch.get_logical_switch( client_session, resource_id) dpg_id = switch_params.get('vdsContextWithBacking', {}).get('backingValue') if not dpg_id: raise cfy_exc.RecoverableError( message="We dont have such network yet", retry_after=10) # If you change the following line you will probably break vsphere # integration ctx.instance.runtime_properties['vsphere_network_id'] = dpg_id ctx.logger.info("Distibuted port group id: %s" % dpg_id) # If you change the following line you will probably break vRops # integration ctx.instance.runtime_properties['name'] = switch_params['name'] ctx.logger.info("Lswitch name: %s" % ctx.instance.runtime_properties['name'])
def create(**kwargs): validation_rules = { "name": { "required": True }, "dlr_pwd": { "required": True }, "dlr_size": { "default": "compact", "values": [ "compact", "large", "quadlarge", "xlarge" ] }, "ha_ls_id": { "required": True }, "uplink_ls_id": { "required": True }, "uplink_ip": { "required": True }, "uplink_subnet": { "required": True }, "uplink_dgw": { "required": True } } use_existing, router_dict = common.get_properties_and_validate( 'router', kwargs, validation_rules ) ctx.logger.info("checking %s" % router_dict["name"]) # credentials client_session = common.nsx_login(kwargs) resource_id = ctx.instance.runtime_properties.get('resource_id') if not use_existing and not resource_id: resource_id, _ = nsx_router.dlr_read( client_session, router_dict["name"] ) if use_existing: ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("Used existed %s" % resource_id) elif resource_id: raise cfy_exc.NonRecoverableError( "Router '%s' already exists" % router_dict["name"] ) if not resource_id: # update properties with vcenter specific values, # required only on create router_dict = common.possibly_assign_vm_creation_props(router_dict) resource_id, _ = nsx_router.dlr_create( client_session, router_dict['name'], router_dict['dlr_pwd'], router_dict['dlr_size'], router_dict['datacentermoid'], router_dict['datastoremoid'], router_dict['resourcepoolid'], router_dict['ha_ls_id'], router_dict['uplink_ls_id'], router_dict['uplink_ip'], router_dict['uplink_subnet'], router_dict['uplink_dgw']) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id) uplink_vnic = nsx_dlr.get_uplink_vnic( client_session, resource_id, router_dict['uplink_ls_id']) ctx.instance.runtime_properties['router']['uplink_vnic'] = uplink_vnic nsx_dlr.update_common_edges(client_session, resource_id, kwargs, False)
def create(**kwargs): validation_rules = { "esg_id": { "required": True }, "action": { "required": True }, "originalAddress": { "required": True }, "translatedAddress": { "required": True }, "vnic": { "set_none": True }, "ruleTag": { "set_none": True }, "loggingEnabled": { "default": False, "type": "boolean", }, "enabled": { "default": True, "type": "boolean" }, "description": { "set_none": True }, "protocol": { "default": "any" }, "translatedPort": { "default": "any" }, "originalPort": { "default": "any" } } use_existing, nat_dict = common.get_properties_and_validate( 'rule', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) resource_id = nsx_nat.add_nat_rule( client_session, nat_dict['esg_id'], nat_dict['action'], nat_dict['originalAddress'], nat_dict['translatedAddress'], nat_dict['vnic'], nat_dict['ruleTag'], nat_dict['loggingEnabled'], nat_dict['enabled'], nat_dict['description'], nat_dict['protocol'], nat_dict['translatedPort'], nat_dict['originalPort']) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s " % resource_id)
def create(**kwargs): validation_rules = { "esg_id": { "required": True }, "ifindex": { "required": True, "type": "string" }, "ipaddr": { "set_none": True }, "netmask": { "set_none": True }, "prefixlen": { "set_none": True }, "name": { "set_none": True }, "mtu": { "set_none": True }, "is_connected": { "set_none": True }, "portgroup_id": { "set_none": True }, "vnic_type": { "set_none": True, "values": ["uplink", "internal"] }, "enable_send_redirects": { "set_none": True }, "enable_proxy_arp": { "set_none": True }, "secondary_ips": { "set_none": True } } use_existing, interface = common.get_properties_and_validate( 'interface', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) ifindex, resource_id = nsx_esg.esg_cfg_interface( client_session, interface['esg_id'], interface['ifindex'], interface['ipaddr'], interface['netmask'], interface['prefixlen'], interface['name'], interface['mtu'], interface['is_connected'], interface['portgroup_id'], interface['vnic_type'], interface['enable_send_redirects'], interface['enable_proxy_arp'], interface['secondary_ips']) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.instance.runtime_properties['ifindex'] = ifindex ctx.logger.info("created %s" % resource_id)
def create(**kwargs): validation_rules = { "esg_id": { "required": True }, "ruleTag": { "set_none": True }, "name": { "set_none": True }, "source": { "set_none": True }, "destination": { "set_none": True }, "application": { "set_none": True }, "matchTranslated": { "default": False, "type": "boolean" }, "direction": { "values": ["in", "out"], "set_none": True }, "action": { "required": True, "values": ["accept", "deny", "reject"] }, "enabled": { "default": True, "type": "boolean" }, "loggingEnabled": { "default": False, "type": "boolean" }, "description": { "set_none": True } } use_existing, firewall_dict = common.get_properties_and_validate( 'rule', kwargs, validation_rules) resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) rule_id, resource_id = nsx_firewall.add_firewall_rule( client_session, firewall_dict['esg_id'], firewall_dict['application'], firewall_dict["direction"], firewall_dict["name"], firewall_dict["loggingEnabled"], firewall_dict["matchTranslated"], firewall_dict["destination"], firewall_dict["enabled"], firewall_dict["source"], firewall_dict["action"], firewall_dict["ruleTag"], firewall_dict["description"]) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.instance.runtime_properties['rule_id'] = rule_id ctx.logger.info("created %s" % resource_id)
def create(**kwargs): validation_rules = { # we need name in any case of usage except predefined 'id' "name": { "required": True, "external_use": False }, "esg_pwd": { "required": True, "external_use": False }, "esg_size": { "default": "compact", "values": [ "compact", "large", "quadlarge", "xlarge" ] }, "datacentermoid": {}, "datastoremoid": {}, "resourcepoolid": {}, "default_pg": { "required": True, "external_use": False }, "esg_username": { "default": "admin" }, "esg_remote_access": { "default": False, "type": "boolean" } } use_existing, edge_dict = common.get_properties_and_validate( 'edge', kwargs, validation_rules ) resource_id = ctx.instance.runtime_properties.get('resource_id') # credentials client_session = common.nsx_login(kwargs) if use_existing and resource_id: name = nsx_dlr.get_edgegateway(client_session, resource_id)['name'] edge_dict['name'] = name ctx.instance.runtime_properties['edge']['name'] = name resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) if not resource_id: resource_id, _ = nsx_esg.esg_read(client_session, edge_dict["name"]) if use_existing: ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("Used existed %s" % resource_id) elif resource_id: raise cfy_exc.NonRecoverableError( "Edge '%s' already exists" % edge_dict["name"] ) if not resource_id: # update properties with vcenter specific values, # required only on create edge_dict = common.possibly_assign_vm_creation_props(edge_dict) resource_id, _ = nsx_esg.esg_create( client_session, edge_dict['name'], edge_dict['esg_pwd'], edge_dict['esg_size'], edge_dict['datacentermoid'], edge_dict['datastoremoid'], edge_dict['resourcepoolid'], edge_dict['default_pg'], edge_dict['esg_username'], edge_dict['esg_remote_access'] ) ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("created %s" % resource_id) nsx_dlr.update_common_edges(client_session, resource_id, kwargs, True)
def create(**kwargs): validation_rules = { "esg_id": { "required": True }, "vm_id": { "set_none": True }, "vnic_id": { "set_none": True, "type": "string" }, "mac": { "set_none": True }, "hostname": { "required": True }, "ip": { "required": True }, "default_gateway": { "set_none": True }, "subnet_mask": { "set_none": True }, "domain_name": { "set_none": True }, "dns_server_1": { "set_none": True }, "dns_server_2": { "set_none": True }, "lease_time": { "set_none": True }, "auto_dns": { "set_none": True } } use_existing, bind_dict = common.get_properties_and_validate( 'bind', kwargs, validation_rules) if use_existing: ctx.logger.info("Used pre existed!") return resource_id = ctx.instance.runtime_properties.get('resource_id') if resource_id: ctx.logger.info("Reused %s" % resource_id) return # credentials client_session = common.nsx_login(kwargs) if bind_dict.get('mac'): # if NONE skip this part resource_id = nsx_dhcp.add_mac_binding( client_session, bind_dict['esg_id'], bind_dict['mac'], bind_dict['hostname'], bind_dict['ip'], bind_dict['default_gateway'], bind_dict['subnet_mask'], bind_dict['domain_name'], bind_dict['dns_server_1'], bind_dict['dns_server_2'], bind_dict['lease_time'], bind_dict['auto_dns']) elif bind_dict.get('vnic_id') is not None and bind_dict.get('vm_id'): resource_id = nsx_dhcp.add_vm_binding( client_session, bind_dict['esg_id'], bind_dict['vm_id'], bind_dict['vnic_id'], bind_dict['hostname'], bind_dict['ip'], bind_dict['default_gateway'], bind_dict['subnet_mask'], bind_dict['domain_name'], bind_dict['dns_server_1'], bind_dict['dns_server_2'], bind_dict['lease_time'], bind_dict['auto_dns']) else: raise cfy_exc.NonRecoverableError("Please fill vm_id/vnic_id or mac") ctx.instance.runtime_properties['resource_id'] = resource_id ctx.logger.info("Binded %s | %s" % (resource_id, bind_dict))