Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…-client-python into develop
  • Loading branch information
edersonbrilhante committed Nov 26, 2015
2 parents e69a926 + 1d5245c commit 37a262f
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 15 deletions.
60 changes: 60 additions & 0 deletions networkapiclient/ApiRack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# -*- coding:utf-8 -*-
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from networkapiclient.ApiGenericClient import ApiGenericClient


class ApiRack(ApiGenericClient):

def __init__(self, networkapi_url, user, password, user_ldap=None):
"""Class constructor receives parameters to connect to the networkAPI.
:param networkapi_url: URL to access the network API.
:param user: User for authentication.
:param password: Password for authentication.
"""
super(ApiRack,self).__init__( networkapi_url, user, password, user_ldap)

def insert_rack(
self,
number,
name,
mac_address_sw1,
mac_address_sw2,
mac_address_ilo,
id_sw1,
id_sw2,
id_ilo):

data = dict()
data['number'] = number
data['name'] = name
data['mac_address_sw1'] = mac_address_sw1
data['mac_address_sw2'] = mac_address_sw2
data['mac_address_ilo'] = mac_address_ilo
data['id_sw1'] = id_sw1
data['id_sw2'] = id_sw2
data['id_ilo'] = id_ilo

uri = "api/rack/"

return self.post(uri, data=data)

def rack_deploy( self, rack_id):

data = dict()
uri = "api/rack/" + str(rack_id) + "/equipments/"

return self.post(uri, data=data)
31 changes: 22 additions & 9 deletions networkapiclient/ClientFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
from networkapiclient.ApiNetworkIPv6 import ApiNetworkIPv6
from networkapiclient.Rack import Rack
from networkapiclient.RackServers import RackServers

from networkapiclient.System import System
from networkapiclient.ApiRack import ApiRack


class ClientFactory(object):
Expand Down Expand Up @@ -375,8 +376,7 @@ def create_pool(self):
self.networkapi_url,
self.user,
self.password,
self.user_ldap
)
self.user_ldap)

def create_healthcheck(self):

Expand All @@ -386,8 +386,7 @@ def create_healthcheck(self):
self.networkapi_url,
self.user,
self.password,
self.user_ldap
)
self.user_ldap)

def create_api_vip_request(self):

Expand All @@ -397,8 +396,7 @@ def create_api_vip_request(self):
self.networkapi_url,
self.user,
self.password,
self.user_ldap
)
self.user_ldap)

def create_api_interface_request(self):

Expand Down Expand Up @@ -448,13 +446,28 @@ def create_rackservers(self):
self.user,
self.password,
self.user_ldap)
def create_api_vlan(self):

def create_api_vlan(self):
"""Get an instance of Api Vlan services facade."""

return ApiVlan(
self.networkapi_url,
self.user,
self.password,
self.user_ldap
)

def create_system(self):
"""Get an instance of Api System Variables services facade."""
return System(
self.networkapi_url,
self.user,
self.password,
self.user_ldap)

def create_apirack(self):
"""Get an instance of Api Rack Variables services facade."""
return ApiRack(
self.networkapi_url,
self.user,
self.password,
self.user_ldap)
4 changes: 2 additions & 2 deletions networkapiclient/Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,9 @@ def delete_channel(self, channel_name):

return self.response(code, xml)

def get_interface_by_channel(self, channel_name):
def get_interface_by_channel(self, channel_name, equip_name):

url = 'interface/get-by-channel/' + str(channel_name) + '/'
url = 'interface/get-by-channel/' + str(channel_name) + '/' + str(equip_name) + '/'

code, map = self.submit(None, 'GET', url)

Expand Down
4 changes: 2 additions & 2 deletions networkapiclient/Rack.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ def gerar_arq_config (self, id_rack):
return self.response(code, xml)


def aplicar_configuracao(self, id_rack):
def alocar_configuracao(self, id_rack):


if not is_valid_int_param(id_rack):
raise InvalidParameterError(
u'The identifier of Rack is invalid or was not informed.')

url = 'rack/aplicar-config/' + str(id_rack) + '/'
url = 'rack/alocar-config/' + str(id_rack) + '/'
code, xml = self.submit(None, 'POST', url)

return self.response(code, xml)
Expand Down
53 changes: 53 additions & 0 deletions networkapiclient/System.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding:utf-8 -*-
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from networkapiclient.ApiGenericClient import ApiGenericClient


class System(ApiGenericClient):

def __init__(self, networkapi_url, user, password, user_ldap=None):
"""Class constructor receives parameters to connect to the networkAPI.
:param networkapi_url: URL to access the network API.
:param user: User for authentication.
:param password: Password for authentication.
"""
super(System, self).__init__(networkapi_url, user, password, user_ldap)


def save(self, name, value, description):

uri = "api/system/variables/"

data = dict()
data['name'] = name
data['value'] = value
data['description'] = description

return self.post(uri, data=data)

def get_all(self):

uri = "api/system/variables/"

return self.get(uri)

def delete_all(self, variable_id):

uri = 'api/system/variables/' + str(variable_id) + '/'

return self.delete(uri)
11 changes: 9 additions & 2 deletions networkapiclient/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ def __init__(self, error):
NetworkAPIClientError.__init__(self, error)


class VariableError(NetworkAPIClientError):

def __init__(self, error):
NetworkAPIClientError.__init__(self, error)


class EquipamentoRoteiroError(NetworkAPIClientError):

def __init__(self, error):
Expand Down Expand Up @@ -1085,8 +1091,9 @@ class ErrorHandler(object):
380: RackAllreadyConfigError,
381: NomeRackDuplicadoError,
382: RackConfiguracaoError,
383: RackAplicarError
}
383: RackAplicarError,
407: VariableError
}

@classmethod
def handle(cls, code, description):
Expand Down

0 comments on commit 37a262f

Please sign in to comment.